From ecbf2e95f965bdeb543d78e6fbb1b16a6894605c Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 23 Apr 2014 14:04:26 -0400 Subject: [PATCH] Provide more specific details to client about reason for being unconnected --- bin/confetty | 19 +++++++------------ confluent/consoleserver.py | 15 +++++++++++++-- confluent/exceptions.py | 5 +++++ plugins/hardwaremanagement/ipmi.py | 6 +++++- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bin/confetty b/bin/confetty index 266b71b2..28fa6ab3 100755 --- a/bin/confetty +++ b/bin/confetty @@ -67,21 +67,16 @@ conserversequence = '\x05c' # ctrl-e, c oldtcattr = termios.tcgetattr(sys.stdin.fileno()) netserver = None -statedata = {} - - def updatestatus(stateinfo): status = consolename - if 'clientcount' in stateinfo: - statedata['clientcount'] = stateinfo['clientcount'] - if 'connectstate' in stateinfo: - statedata['connectstate'] = stateinfo['connectstate'] info = [] - if ('connectstate' in statedata and - statedata['connectstate'] != 'connected'): - info.append(statedata['connectstate']) - if 'clientcount' in statedata and statedata['clientcount'] != 1: - info.append('clients: %d' % statedata['clientcount']) + if ('connectstate' in stateinfo and + stateinfo['connectstate'] != 'connected'): + info.append(stateinfo['connectstate']) + if 'error' in stateinfo: + info.append(stateinfo['error']) + if 'clientcount' in stateinfo and stateinfo['clientcount'] != 1: + info.append('clients: %d' % stateinfo['clientcount']) if info: status += ' [' + ','.join(info) + ']' sys.stdout.write('\x1b]0;console: %s\x07' % status) diff --git a/confluent/consoleserver.py b/confluent/consoleserver.py index 3b270307..e988d7a6 100644 --- a/confluent/consoleserver.py +++ b/confluent/consoleserver.py @@ -146,8 +146,9 @@ class _ConsoleHandler(object): event=log.Events.stacktrace) if not isinstance(self._console, conapi.Console): self.connectstate = 'unconnected' - self._send_rcpts({'connectstate': self.connectstate}) self.error = 'misconfigured' + self._send_rcpts({'connectstate': self.connectstate, + 'error': self.error}) return self.send_break = self._console.send_break if self._attribwatcher: @@ -161,10 +162,20 @@ class _ConsoleHandler(object): (self.node,), attribstowatch, self._attribschanged) try: self._console.connect(self.get_console_output) + except exc.TargetEndpointBadCredentials: + self.error = 'badcredentials' + self.connectstate = 'unconnected' + self._send_rcpts({'connectstate': self.connectstate, + 'error': self.error}) + retrytime = 30 + (30 * random.random()) + if not self.reconnect: + self.reconnect = eventlet.spawn_after(retrytime, self._connect) + return except exc.TargetEndpointUnreachable: self.error = 'unreachable' self.connectstate = 'unconnected' - self._send_rcpts({'connectstate': self.connectstate}) + self._send_rcpts({'connectstate': self.connectstate, + 'error': self.error}) retrytime = 30 + (30 * random.random()) if not self.reconnect: self.reconnect = eventlet.spawn_after(retrytime, self._connect) diff --git a/confluent/exceptions.py b/confluent/exceptions.py index e8a8108d..7ed2235b 100644 --- a/confluent/exceptions.py +++ b/confluent/exceptions.py @@ -36,6 +36,11 @@ class TargetEndpointUnreachable(ConfluentException): # was unreachable. http code 504 pass +class TargetEndpointBadCredentials(ConfluentException): + # target was reachable, but authentication/authorization + # failed + pass + class ForbiddenRequest(ConfluentException): # The client request is not allowed by authorization engine diff --git a/plugins/hardwaremanagement/ipmi.py b/plugins/hardwaremanagement/ipmi.py index 25e59330..c1bbdb21 100644 --- a/plugins/hardwaremanagement/ipmi.py +++ b/plugins/hardwaremanagement/ipmi.py @@ -138,7 +138,11 @@ class IpmiConsole(conapi.Console): if self.broken: break if self.broken: - raise exc.TargetEndpointUnreachable(self.error) + if (self.error.startswith('Incorrect password') or + self.error.startswith('Unauthorized name')): + raise exc.TargetEndpointBadCredentials + else: + raise exc.TargetEndpointUnreachable(self.error) self.connected = True except socket.gaierror as err: raise exc.TargetEndpointUnreachable(str(err))