GitLab maintenance scheduled for Tomorrow, 2019-04-24, from 12:00 to 13:00 CDT - Services will be unavailable during this time.

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):
def planify(self, target, machineinfo):
"""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
if total_power < target:
direction = 'i'
......
......@@ -154,14 +154,19 @@ class Daemon(object):
def do_sensor(self):
self.machine_info = self.sensor_manager.do_update()
logger.info("current state: %r", self.machine_info)
total_power = self.machine_info['energy']['power']['total']
msg = {'api': 'up_pub',
'type': 'power',
'total': total_power,
'limit': self.target
}
self.upstream_pub_server.sendmsg(PUB_MSG['power'](**msg))
logger.info("sending sensor message: %r", msg)
try:
total_power = self.machine_info['energy']['power']['total']
except TypeError:
logger.error("power sensor format malformed, "
"can not report power upstream.")
else:
msg = {'api': 'up_pub',
'type': 'power',
'total': total_power,
'limit': self.target
}
self.upstream_pub_server.sendmsg(PUB_MSG['power'](**msg))
logger.info("sending sensor message: %r", msg)
def do_control(self):
plan = self.controller.planify(self.target, self.machine_info)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment