diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 5c7617b1..c7e21654 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -54,7 +54,7 @@ class ConfluentMessage(object): def json(self): # This will create the canonical json representation of this message - if self.stripped: + if hasattr(self, 'stripped') and self.stripped: datasource = self.kvpairs else: datasource = {'databynode': self.kvpairs} @@ -65,7 +65,7 @@ class ConfluentMessage(object): """Return pythonic representation of the response. Used by httpapi while assembling data prior to json serialization""" - if self.stripped: + if hasattr(self, 'stripped') and self.stripped: return self.kvpairs return {'databynode': self.kvpairs} @@ -155,7 +155,7 @@ class ConfluentNodeError(object): self.error = errorstr def raw(self): - return {self.node: {'error': self.error}} + return {'databynode': {self.node: {'error': self.error}}} def html(self): return self.node + ":" + self.error @@ -175,6 +175,14 @@ class ConfluentTargetTimeout(ConfluentNodeError): raise exc.TargetEndpointUnreachable +class ConfluentTargetNotFound(ConfluentNodeError): + def __init__(self, node, errorstr='not found'): + self.node = node + self.error = errorstr + + def strip_node(self, node): + raise exc.NotFoundException(self.error) + class ConfluentTargetInvalidCredentials(ConfluentNodeError): def __init__(self, node): self.node = node diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index e09274ac..11cff648 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -329,7 +329,10 @@ class IpmiHandler(object): else: self.make_sensor_map() if sensorname not in self.sensormap: - raise exc.NotFoundException('No such sensor') + self.output.put( + msg.ConfluentTargetNotFound(self.node, + 'Sensor not found')) + return reading = self.ipmicmd.get_sensor_reading( self.sensormap[sensorname]) self.output.put( diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index b8eb2e2b..ae9a9713 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -123,6 +123,14 @@ def sessionhdl(connection, authname, skipauth=False): tlvdata.send(connection, {'errorcode': 501, 'error': 'Not Implemented'}) tlvdata.send(connection, {'_requestdone': 1}) + except exc.NotFoundException as nfe: + tlvdata.send(connection, {'errorcode': 404, + 'error': str(nfe)}) + tlvdata.send(connection, {'_requestdone': 1}) + except exc.InvalidArgumentException as iae: + tlvdata.send(connection, {'errorcode': 400, + 'error': 'Bad Request - ' + str(iae)}) + tlvdata.send(connection, {'_requestdone': 1}) except SystemExit: sys.exit(0) except: