X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=source%2Fsteps%2FAuthenticateWithPLC.py;h=2e71a1cd7c5a0c0a49839ef22a3b922deef5e7c3;hb=f52080486db907ba6557d1047730c638c4562790;hp=bad3c16d197696de6aaf24f9f2da8fc2a02512db;hpb=7ab7e9dd797333a9fdc8604554e16e192a32144d;p=bootmanager.git diff --git a/source/steps/AuthenticateWithPLC.py b/source/steps/AuthenticateWithPLC.py index bad3c16..2e71a1c 100644 --- a/source/steps/AuthenticateWithPLC.py +++ b/source/steps/AuthenticateWithPLC.py @@ -1,14 +1,22 @@ +#!/usr/bin/python +# +# Copyright (c) 2003 Intel Corporation +# All rights reserved. +# +# Copyright (c) 2004-2006 The Trustees of Princeton University +# All rights reserved. + + import os from Exceptions import * import BootAPI -import StartDebug -AUTH_FAILURE_COUNT_FILE= "/tmp/authfailurecount" +AUTH_FAILURE_COUNT_FILE = "/tmp/authfailurecount" -def Run( vars, log ): +def Run(vars, log): """ Authenticate this node with PLC. This ensures that the node can operate as normal, and that our management authority has authorized it. @@ -25,34 +33,41 @@ def Run( vars, log ): NUM_AUTH_FAILURES_BEFORE_DEBUG How many failures before debug """ - log.write( "\n\nStep: Authenticating node with PLC.\n" ) + log.write("\n\nStep: Authenticating node with PLC.\n") # make sure we have the variables we need try: - NUM_AUTH_FAILURES_BEFORE_DEBUG= int(vars["NUM_AUTH_FAILURES_BEFORE_DEBUG"]) - except KeyError, var: - raise BootManagerException, "Missing variable in vars: %s\n" % var - except ValueError, var: - raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var + NUM_AUTH_FAILURES_BEFORE_DEBUG = int(vars["NUM_AUTH_FAILURES_BEFORE_DEBUG"]) + except KeyError as var: + raise BootManagerException("Missing variable in vars: {}\n".format(var)) + except ValueError as var: + raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var)) try: - authorized= BootAPI.call_api_function( vars, "BootCheckAuthentication", () ) + authorized = BootAPI.call_api_function(vars, "BootCheckAuthentication", ()) if authorized == 1: - log.write( "Authentication successful.\n" ) + log.write("Authentication successful.\n") try: - os.unlink( AUTH_FAILURE_COUNT_FILE ) - except OSError, e: + os.unlink(AUTH_FAILURE_COUNT_FILE) + except OSError as e: pass return 1 - except BootManagerException, e: - log.write( "Authentication failed: %s.\n" % e ) + except BootManagerException as e: + log.write("Authentication failed: {}.\n".format(e)) + except: + # This is ugly. + if vars['DISCONNECTED_OPERATION']: + vars['API_SERVER_INST'] = None + return 1 + else: + raise # increment auth failure - auth_failure_count= 0 + auth_failure_count = 0 try: - auth_failure_count= int(file(AUTH_FAILURE_COUNT_FILE,"r").read().strip()) + auth_failure_count = int(file(AUTH_FAILURE_COUNT_FILE, "r").read().strip()) except IOError: pass except ValueError: @@ -61,18 +76,16 @@ def Run( vars, log ): auth_failure_count += 1 try: - fail_file= file(AUTH_FAILURE_COUNT_FILE,"w") - fail_file.write( str(auth_failure_count) ) + fail_file = file(AUTH_FAILURE_COUNT_FILE, "w") + fail_file.write(str(auth_failure_count)) fail_file.close() except IOError: pass if auth_failure_count >= NUM_AUTH_FAILURES_BEFORE_DEBUG: - log.write( "Maximum number of authentication failures reached.\n" ) - log.write( "Canceling boot process and going into debug mode.\n" ) - - StartDebug.Run( vars, log ) + log.write("Maximum number of authentication failures reached.\n") + log.write("Canceling boot process and going into debug mode.\n") - raise BootManagerException, "Unable to authenticate node." + raise BootManagerException("Unable to authenticate node.")