From 170e7934ca278b1e1efe4639a12db94e70d22374 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 1 Feb 2014 19:28:31 -0500 Subject: [PATCH] Restructure ipmi plugin logon errors Make it so that logon errors are raised in the context of the request(s) that actually care. --- confluent/exceptions.py | 9 +++++++++ plugins/hardwaremanagement/ipmi.py | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/confluent/exceptions.py b/confluent/exceptions.py index c285b887..0dbbb677 100644 --- a/confluent/exceptions.py +++ b/confluent/exceptions.py @@ -2,7 +2,16 @@ class ConfluentException(Exception): pass class NotFoundException(ConfluentException): + # Something that could be construed as a name was not found + # basically, picture an http error code 404 pass class InvalidArgumentException(ConfluentException): + # Something from the remote client wasn't correct + # like http code 400 + pass + +class TargetEndpointTimeout(ConfluentException): + # A target system was unavailable. For example, a BMC + # was unreachable. http code 504 pass diff --git a/plugins/hardwaremanagement/ipmi.py b/plugins/hardwaremanagement/ipmi.py index 3d416d6f..ba98074d 100644 --- a/plugins/hardwaremanagement/ipmi.py +++ b/plugins/hardwaremanagement/ipmi.py @@ -1,4 +1,5 @@ import collections +import confluent.exceptions as exc import confluent.interface.console as conapi import confluent.messages as msg import eventlet @@ -231,6 +232,7 @@ class IpmiHandler(object): global chainpulled global _ipmithread global pullchain + self.broken = False if _ipmithread is None: pullchain = os.pipe() _ipmithread = eventlet.spawn(_ipmi_evtloop) @@ -261,8 +263,10 @@ class IpmiHandler(object): def logged(self, response, ipmicmd): if 'error' in response: - raise Exception(response['error']) - self.loggedin = True + self.broken = True + self.error = response['error'] + else: + self.loggedin = True def call_ipmicmd(self, function, *args): global chainpulled @@ -279,11 +283,16 @@ class IpmiHandler(object): self.lastrsp = response def handle_request(self): - while not self.loggedin: - wait_on_ipmi() bootdevices = { 'optical': 'cd' } + while not (self.loggedin or self.broken): + wait_on_ipmi() + if self.broken: + if self.error == 'timeout': + raise exc.TargetEndpointTimeout() + else: + raise Exception(self.error) if self.element == [ 'power', 'state' ]: if 'read' == self.op: power = self.call_ipmicmd(self.ipmicmd.get_power)