Commit 81ac4947 authored by Valentin Reis's avatar Valentin Reis

Logging an error in case of malformed machine_info.

Related to #22
parent e626053c
Pipeline #4599 passed with stages
in 55 seconds
...@@ -91,7 +91,13 @@ class Controller(object): ...@@ -91,7 +91,13 @@ class Controller(object):
def planify(self, target, machineinfo): def planify(self, target, machineinfo):
"""Plan the next action for the control loop.""" """Plan the next action for the control loop."""
total_power = machineinfo['energy']['power']['total'] try:
total_power = machineinfo['energy']['power']['total']
except TypeError:
logging.error("\"machineinfo\" malformed. Can not run "
"control loop.")
return (None, None)
direction = None direction = None
if total_power < target: if total_power < target:
direction = 'i' direction = 'i'
...@@ -154,14 +154,19 @@ class Daemon(object): ...@@ -154,14 +154,19 @@ class Daemon(object):
def do_sensor(self): def do_sensor(self):
self.machine_info = self.sensor_manager.do_update() self.machine_info = self.sensor_manager.do_update()"current state: %r", self.machine_info)"current state: %r", self.machine_info)
total_power = self.machine_info['energy']['power']['total'] try:
msg = {'api': 'up_pub', total_power = self.machine_info['energy']['power']['total']
'type': 'power', except TypeError:
'total': total_power, logger.error("power sensor format malformed, "
'limit': "can not report power upstream.")
} else:
self.upstream_pub_server.sendmsg(PUB_MSG['power'](**msg)) msg = {'api': 'up_pub',"sending sensor message: %r", msg) 'type': 'power',
'total': total_power,
self.upstream_pub_server.sendmsg(PUB_MSG['power'](**msg))"sending sensor message: %r", msg)
def do_control(self): def do_control(self):
plan = self.controller.planify(, self.machine_info) plan = self.controller.planify(, self.machine_info)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment