def main(): applicationResourceFile = '/hp/support/patches/resourceFiles/patchResourceFile' loggerName = 'patchLogger' patchResourceDict = init(applicationResourceFile, loggerName) logger = logging.getLogger(loggerName) options = patchResourceDict['options'] if not options.p: print GREEN + 'Phase 2: Updating system with patches.' + RESETCOLORS osDistLevel = patchResourceDict['osDistLevel'] if not options.k: if patchResourceDict['removeRPMs'] or patchResourceDict['addRPMs']: #from modules.oneOffs import OneOffs oneOffs = OneOffs(loggerName) # oneOffs if patchResourceDict['removeRPMs']: if not oneOffs.removeRPMs(patchResourceDict.copy()): print RED + BOLD + '\nProblems were encountered while removing the RPMs which were identified by the patch resource file for removal; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) if patchResourceDict['addRPMs']: if not oneOffs.addRPMs(patchResourceDict.copy()): print RED + BOLD + '\nProblems were encountered while adding the RPMs which were identified by the patch resource file for addition; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) #from modules.applyPatches import ApplyPatches applyPatches = ApplyPatches() # applyPatches s = SignalHandler(applyPatches) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) workerThread = Thread(target=applyPatches.applyPatches, args=(patchResourceDict['repositoryList'], loggerName)) workerThread.start() while 1: time.sleep(0.1) if not workerThread.is_alive(): if applyPatches.getExitStatus() != 0: exit(1) else: break response = s.getResponse() if response != '': if response == 'y': applyPatches.endTask() exit(1) signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) print '' updateTaskStatusDict = {} if (options.a or options.k) and osDistLevel == 'SLES_SP4': print GREEN + "Phase 3: Updating the system's bootloader." + RESETCOLORS #from modules.createBootloaderConfigFile import configureBootLoader updateTaskStatusDict['configureBootLoader'] = configureBootLoader(loggerName) if (options.a or options.k) and osDistLevel == 'SLES_SP4': print GREEN + 'Phase 4: Updating the patch bundle information file.' + RESETCOLORS else: print GREEN + 'Phase 3: Updating the patch bundle information file.' + RESETCOLORS #from modules.updateReleaseInformation import updateVersionInformationFile if options.a: updateTaskStatusDict['updateVersionInformationFile'] = updateVersionInformationFile(patchResourceDict.copy(), 'all', loggerName)
def main(): applicationResourceFile = '/hp/support/patches/resourceFiles/patchResourceFile' patchResourceDict = init(applicationResourceFile) logger = logging.getLogger("patchLogger") options = patchResourceDict['options'] if not options.p: print GREEN + "Phase 2: Updating system with patches." + RESETCOLORS #Set traps so that the software update is not interrupted by the user. original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGQUIT, signal_handler) #Apply patches to the system based on option(s) selected. applyPatches(patchResourceDict['repositoryList']) #Restore the signals back to their defaults. signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) updateTaskStatusDict = {} #Configure the boot loader for the new kernel if option 'a' or 'k' were selected. if options.a or options.k: print GREEN + "Phase 3: Updating the system's bootloader." + RESETCOLORS updateTaskStatusDict['configureBootLoader'] = configureBootLoader() #Install the patch bundle release RPM. print GREEN + "Phase 4: Installing the patch bundle release RPM." + RESETCOLORS if options.a: updateTaskStatusDict['installReleaseRPM'] = installReleaseRPM( patchResourceDict.copy()) elif options.k: updateTaskStatusDict['installReleaseRPM'] = installReleaseRPM( patchResourceDict.copy(), 'kernel') elif options.o: updateTaskStatusDict['installReleaseRPM'] = installReleaseRPM( patchResourceDict.copy(), 'os') taskFailureList = '' #Now check if any of the update tasks failed and print hte appropriate message. for key, value in updateTaskStatusDict.iteritems(): if value == 'Failure': if taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': if patchResourceDict['postUpdateRequired'] == 'yes': print GREEN + "\nThe system update has completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print GREEN + "\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS else: if patchResourceDict['postUpdateRequired'] == 'yes': print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed update tasks(" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed update tasks(" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS else: ''' Get the post update resume log, which contains information for the post update tasks. The following is a list of variables currently found in the post update resume log: isServiceguardSystem = 'yes or no' isFusionIOSystem = 'yes or no' firmwareUpdateRequired = 'yes or no' busList = '8c:00.0 8d:00.0 87:00.0 88:00.0' ''' try: logBaseDir = (re.sub('\s+', '', patchResourceDict['logBaseDir'])).rstrip('/') postUpdateResumeLog = re.sub( '\s+', '', patchResourceDict['postUpdateResumeLog']) postUpdateResumeLog = logBaseDir + '/' + postUpdateResumeLog except KeyError as err: logger.error("The resource key (" + str(err) + ") was not present in the resource file.") print RED + "The resource key for the post update resume log was not present in the resource file; check the log file for errors; exiting program execution." + RESETCOLORS exit(1) resumeDict = {} try: with open(postUpdateResumeLog) as f: for line in f: line = line.strip() #Remove quotes. line = re.sub('[\'"]', '', line) #Ignore commented and blank lines. if len(line) == 0 or re.match("^#", line): continue else: (key, val) = line.split('=') key = re.sub('\s+', '', key) resumeDict[key] = val.lstrip() except IOError as err: logger.error( "Unable to get the post update information from resume log.\n" + str(err)) print RED + "Unable to get the post update information from resume log; check the log file for errors; exiting program execution." + RESETCOLORS exit(1) #This is used for the phase numbering. The count starts at two, since one was already used for the initialization message. count = 2 #This is used to keep track of post update task completion status. postUpdateTaskStatusDict = {} if 'isServiceguardSystem' in resumeDict: if resumeDict['isServiceguardSystem'] == 'yes': print GREEN + "Phase " + str( count ) + ": Building and installing the deadman driver." + RESETCOLORS postUpdateTaskStatusDict[ 'buildDeadmanDriver'] = buildDeadmanDriver() count += 1 if 'isFusionIOSystem' in resumeDict: if resumeDict['isFusionIOSystem'] == 'yes': if resumeDict['firmwareUpdateRequired'] == 'yes': print GREEN + "Phase " + str( count ) + ": Updating FusionIO firmware, driver, and software." + RESETCOLORS postUpdateTaskStatusDict[ 'updateFusionIO'] = updateFusionIO( patchResourceDict.copy(), firmwareUpdateRequired=resumeDict[ 'firmwareUpdateRequired'], busList=resumeDict['busList']) else: print GREEN + "Phase " + str( count ) + ": Updating FusionIO driver and software." + RESETCOLORS postUpdateTaskStatusDict[ 'updateFusionIO'] = updateFusionIO( patchResourceDict.copy(), firmwareUpdateRequired=resumeDict[ 'firmwareUpdateRequired']) taskFailureList = '' for key, value in postUpdateTaskStatusDict.iteritems(): if value == 'Failure': if taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': print GREEN + "\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS else: print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed post update tasks(" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS
def main(): applicationResourceFile = '/hp/support/patches/resourceFiles/patchResourceFile' loggerName = 'patchLogger' patchResourceDict = init(applicationResourceFile, loggerName) logger = logging.getLogger(loggerName) options = patchResourceDict['options'] if not options.p: print GREEN + 'Phase 2: Updating system with patches.' + RESETCOLORS osDistLevel = patchResourceDict['osDistLevel'] if not options.k: if patchResourceDict['removeRPMs'] or patchResourceDict['addRPMs']: oneOffs = OneOffs(loggerName) if not patchResourceDict['removeRPMs'] and oneOffs.removeRPMs( patchResourceDict.copy()): print RED + BOLD + '\nProblems were encountered while removing the RPMs which were identified by the patch resource file for removal; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) if patchResourceDict['addRPMs']: if not oneOffs.addRPMs(patchResourceDict.copy()): print RED + BOLD + '\nProblems were encountered while adding the RPMs which were identified by the patch resource file for addition; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) applyPatches = ApplyPatches() s = SignalHandler(applyPatches) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) workerThread = Thread(target=applyPatches.applyPatches, args=(patchResourceDict['repositoryList'], loggerName)) workerThread.start() while None: if not workerThread.is_alive(): if applyPatches.getExitStatus() != 0: exit(1) else: break response = s.getResponse() if response != '' or response == 'y': applyPatches.endTask() exit(1) signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) print '' updateTaskStatusDict = {} if (options.a or options.k) and osDistLevel == 'SLES_SP4': print GREEN + "Phase 3: Updating the system's bootloader." + RESETCOLORS updateTaskStatusDict['configureBootLoader'] = configureBootLoader( loggerName) if (options.a or options.k) and osDistLevel == 'SLES_SP4': print GREEN + 'Phase 4: Updating the patch bundle information file.' + RESETCOLORS else: print GREEN + 'Phase 3: Updating the patch bundle information file.' + RESETCOLORS if options.a: updateTaskStatusDict[ 'updateVersionInformationFile'] = updateVersionInformationFile( patchResourceDict.copy(), 'all', loggerName) elif options.k: updateTaskStatusDict[ 'updateVersionInformationFile'] = updateVersionInformationFile( patchResourceDict.copy(), 'kernel', loggerName) elif options.o: updateTaskStatusDict[ 'updateVersionInformationFile'] = updateVersionInformationFile( patchResourceDict.copy(), 'os', loggerName) taskFailureList = '' for (key, value) in updateTaskStatusDict.iteritems(): if value == 'Failure' or taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': if patchResourceDict['postUpdateRequired'] == 'yes': print GREEN + '\nThe system update has completed. Reboot the system for the changes to take affect.\n' + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print GREEN + '\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n' + RESETCOLORS elif patchResourceDict['postUpdateRequired'] == 'yes': print RED + BOLD + '\nThe system update failed to complete successfully. Address the failed update tasks (' + taskFailureList + ') and then reboot the system for the changes to take affect.\n' + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print RED + BOLD + '\nThe system update failed to complete successfully. Address the failed update tasks (' + taskFailureList + ') and then reboot the system for the changes to take affect.\n' + RESETCOLORS try: logBaseDir = re.sub('\\s+', '', patchResourceDict['logBaseDir']).rstrip('/') postUpdateResumeLog = re.sub('\\s+', '', patchResourceDict['postUpdateResumeLog']) postUpdateResumeLog = logBaseDir + '/' + postUpdateResumeLog except KeyError: err = None logger.error('The resource key (' + str(err) + ') was not present in the resource file.') print RED + 'The resource key for the post update resume log was not present in the resource file; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) resumeDict = {} try: with open(postUpdateResumeLog) as f: for line in f: line = line.strip() if len(line) == 0 and re.match('^\\s*#', line) or re.match( '^\\s+$', line): continue continue line = re.sub('[\'"]', '', line) (key, val) = line.split('=') key = key.strip() resumeDict[key] = val.strip() except IOError: err = None logger.error( 'Unable to get the post update information from resume log.\n' + str(err)) print RED + 'Unable to get the post update information from resume log; check the log file for errors; exiting program execution.' + RESETCOLORS exit(1) count = 2 postUpdateTaskStatusDict = {} if 'isServiceguardSystem' in resumeDict and resumeDict[ 'isServiceguardSystem'] == 'yes': original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) buildDeadmanDriver = BuildDeadmanDriver() s = SignalHandler(buildDeadmanDriver) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) print GREEN + 'Phase ' + str( count ) + ': Building and installing the deadman driver.' + RESETCOLORS workerThread = Thread(target=buildDeadmanDriver.buildDeadmanDriver, args=(loggerName, )) workerThread.start() while None: if not workerThread.is_alive(): postUpdateTaskStatusDict[ 'buildDeadmanDriver'] = buildDeadmanDriver.getCompletionStatus( ) break response = s.getResponse() if response != '' or response == 'y': buildDeadmanDriver.endTask() signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) count += 1 if 'isFusionIOSystem' in resumeDict and resumeDict[ 'isFusionIOSystem'] == 'yes': original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) updateFusionIO = UpdateFusionIO() s = SignalHandler(updateFusionIO) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) if resumeDict['firmwareUpdateRequired'] == 'yes': print GREEN + 'Phase ' + str( count ) + ': Updating FusionIO firmware, driver, and software.' + RESETCOLORS workerThread = Thread(target=updateFusionIO.updateFusionIO, args=(patchResourceDict.copy(), loggerName), kwargs={ 'firmwareUpdateRequired': resumeDict['firmwareUpdateRequired'], 'busList': resumeDict['busList'], 'iomemory-vslBackup': resumeDict['iomemory-vslBackup'] }) workerThread.start() else: print GREEN + 'Phase ' + str( count ) + ': Updating FusionIO driver and software.' + RESETCOLORS workerThread = Thread(target=updateFusionIO.updateFusionIO, args=(patchResourceDict.copy(), loggerName), kwargs={ 'firmwareUpdateRequired': resumeDict['firmwareUpdateRequired'], 'iomemory-vslBackup': resumeDict['iomemory-vslBackup'] }) workerThread.start() while None: if not workerThread.is_alive(): postUpdateTaskStatusDict[ 'updateFusionIO'] = updateFusionIO.getCompletionStatus() break response = s.getResponse() if response != '' or response == 'y': updateFusionIO.endTask() signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) taskFailureList = '' for (key, value) in postUpdateTaskStatusDict.iteritems(): if value == 'Failure' or taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': print GREEN + '\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n' + RESETCOLORS else: print RED + BOLD + '\nThe system update failed to complete successfully. Address the failed post update tasks (' + taskFailureList + ') and then reboot the system for the changes to take affect.\n' + RESETCOLORS
def main(): applicationResourceFile = '/hp/support/patches/resourceFiles/patchResourceFile' loggerName = 'patchLogger' patchResourceDict = init(applicationResourceFile, loggerName) logger = logging.getLogger(loggerName) options = patchResourceDict['options'] if not options.p: print GREEN + "Phase 2: Updating system with patches." + RESETCOLORS #Get the current signal handlers so that they can be restored after the patches are installed. original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) #Instantiate the ApplyPatches class. We will be passing its main function (applyPatches) to a worker thread. applyPatches = ApplyPatches() ''' Setup signal handler to intercept SIGINT and SIGQUIT. Need to pass in a reference to the class object that will be peforming the update. That way we gain access to the TimerThread so that it can be stopped/started. ''' s = SignalHandler(applyPatches) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) #Create and start the worker thread. workerThread = Thread(target=applyPatches.applyPatches, args=(patchResourceDict['repositoryList'], loggerName,)) workerThread.start() #Wait for the thread to either stop or get interrupted. while 1: time.sleep(0.1) if not workerThread.is_alive(): if applyPatches.getExitStatus() != 0: exit(1) else: break ''' The response will be an empty string unless a signal was received. If a signal is received then response is either 'n' (Don't cancel patch update) or 'y' (Cancel patch update.). ''' response = s.getResponse() if response != '': if response == 'y': applyPatches.endTask() exit(1) signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) ''' Move the cursor down one line for output formatting purposes, so next line does not appear on the same line as the previous line. ''' print '' updateTaskStatusDict = {} #Configure the boot loader for the new kernel if option 'a' or 'k' were selected. if options.a or options.k: print GREEN + "Phase 3: Updating the system's bootloader." + RESETCOLORS updateTaskStatusDict['configureBootLoader'] = configureBootLoader(loggerName) #Update the patch bundler version information file. if options.a or options.k: print GREEN + "Phase 4: Updating the patch bundle information file." + RESETCOLORS else: print GREEN + "Phase 3: Updating the patch bundle information file." + RESETCOLORS if options.a: updateTaskStatusDict['updateVersionInformationFile'] = updateVersionInformationFile(patchResourceDict.copy(), 'all', loggerName) elif options.k: updateTaskStatusDict['updateVersionInformationFile'] = updateVersionInformationFile(patchResourceDict.copy(), 'kernel', loggerName) elif options.o: updateTaskStatusDict['updateVersionInformationFile'] = updateVersionInformationFile(patchResourceDict.copy(), 'os', loggerName) taskFailureList = '' #Now check if any of the update tasks failed and print the appropriate message. for key, value in updateTaskStatusDict.iteritems(): if value == 'Failure': if taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': if patchResourceDict['postUpdateRequired'] == 'yes': print GREEN + "\nThe system update has completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print GREEN + "\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS else: if patchResourceDict['postUpdateRequired'] == 'yes': print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed update tasks (" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS print PURPLE + BOLD + UNDERLINE + "Make sure to run the program again with the '-p' option after the system reboots to complete the update procedure!\n" + RESETCOLORS else: print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed update tasks (" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS else: ''' Get the post update resume log, which contains information for the post update tasks. The following is a list of variables currently found in the post update resume log: isServiceguardSystem = 'yes or no' isFusionIOSystem = 'yes or no' firmwareUpdateRequired = 'yes or no' busList = '8c:00.0 8d:00.0 87:00.0 88:00.0' ''' try: logBaseDir = (re.sub('\s+', '', patchResourceDict['logBaseDir'])).rstrip('/') postUpdateResumeLog = re.sub('\s+', '', patchResourceDict['postUpdateResumeLog']) postUpdateResumeLog = logBaseDir + '/' + postUpdateResumeLog except KeyError as err: logger.error("The resource key (" + str(err) + ") was not present in the resource file.") print RED + "The resource key for the post update resume log was not present in the resource file; check the log file for errors; exiting program execution." + RESETCOLORS exit(1) resumeDict = {} try: with open(postUpdateResumeLog) as f: for line in f: line = line.strip() #Ignore commented and blank lines. if len(line) == 0 or re.match("^#", line): continue else: #Remove quotes. line = re.sub('[\'"]', '', line) (key, val) = line.split('=') key = re.sub('\s+', '', key) #Remove space on left before assigning. resumeDict[key] = val.lstrip() except IOError as err: logger.error("Unable to get the post update information from resume log.\n" + str(err)) print RED + "Unable to get the post update information from resume log; check the log file for errors; exiting program execution." + RESETCOLORS exit(1) #This is used for the phase numbering. The count starts at two, since one was already used for the initialization message. count = 2 #This is used to keep track of post update task completion status. postUpdateTaskStatusDict = {} if 'isServiceguardSystem' in resumeDict: if resumeDict['isServiceguardSystem'] == 'yes': #Get the current signal handlers so that they can be restored after the deadman driver is built/installed. original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) #Instantiate the BuildDeadmanDriver class. We will be passing its main function (buildDeadmanDriver) to a worker thread. buildDeadmanDriver = BuildDeadmanDriver() ''' Setup signal handler to intercept SIGINT and SIGQUIT. Need to pass in a reference to the class object that will be peforming the update. That way we gain access to the TimerThread so that it can be stopped/started. ''' s = SignalHandler(buildDeadmanDriver) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) #Create and start the worker thread. print GREEN + "Phase " + str(count) + ": Building and installing the deadman driver." + RESETCOLORS workerThread = Thread(target=buildDeadmanDriver.buildDeadmanDriver, args=(loggerName,)) workerThread.start() #Wait for the thread to either stop or get interrupted. while 1: time.sleep(0.1) if not workerThread.is_alive(): postUpdateTaskStatusDict['buildDeadmanDriver'] = buildDeadmanDriver.getCompletionStatus() break ''' The response will be an empty string unless a signal was received. If a signal is received then response is either 'n' (Don't cancel the build/install) or 'y' (Cancel the build/install.). ''' response = s.getResponse() if response != '': if response == 'y': buildDeadmanDriver.endTask() signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) count += 1 if 'isFusionIOSystem' in resumeDict: if resumeDict['isFusionIOSystem'] == 'yes': #Get the current signal handlers so that they can be restored after the FusionIO software and driver are installed. original_sigint_handler = signal.getsignal(signal.SIGINT) original_sigquit_handler = signal.getsignal(signal.SIGQUIT) #Instantiate the UpdateFusionIO class. We will be passing its main function (updateFusionIO) to a worker thread. updateFusionIO = UpdateFusionIO() ''' Setup signal handler to intercept SIGINT and SIGQUIT. Need to pass in a reference to the class object that will be peforming the update. That way we gain access to the TimerThread so that it can be stopped/started. ''' s = SignalHandler(updateFusionIO) signal.signal(signal.SIGINT, s.signal_handler) signal.signal(signal.SIGQUIT, s.signal_handler) #Create and start the worker thread. if resumeDict['firmwareUpdateRequired'] == 'yes': print GREEN + "Phase " + str(count) + ": Updating FusionIO firmware, driver, and software." + RESETCOLORS workerThread = Thread(target=updateFusionIO.updateFusionIO, args=(patchResourceDict.copy(), loggerName,), kwargs={'firmwareUpdateRequired' : resumeDict['firmwareUpdateRequired'], 'busList' : resumeDict['busList']}) workerThread.start() else: print GREEN + "Phase " + str(count) + ": Updating FusionIO driver and software." + RESETCOLORS postUpdateTaskStatusDict['updateFusionIO'] = updateFusionIO(patchResourceDict.copy(), loggerName, firmwareUpdateRequired = resumeDict['firmwareUpdateRequired']) workerThread = Thread(target=updateFusionIO.updateFusionIO, args=(patchResourceDict.copy(), loggerName,), kwargs={'firmwareUpdateRequired' : resumeDict['firmwareUpdateRequired']}) workerThread.start() #Wait for the thread to either stop or get interrupted. while 1: time.sleep(0.1) if not workerThread.is_alive(): postUpdateTaskStatusDict['updateFusionIO'] = updateFusionIO.getCompletionStatus() break ''' The response will be an empty string unless a signal was received. If a signal is received then response is either 'n' (Don't cancel the update) or 'y' (Cancel the update.). ''' response = s.getResponse() if response != '': if response == 'y': updateFusionIO.endTask() signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGQUIT, original_sigquit_handler) taskFailureList = '' for key, value in postUpdateTaskStatusDict.iteritems(): if value == 'Failure': if taskFailureList == '': taskFailureList += key else: taskFailureList += ', ' + key if taskFailureList == '': print GREEN + "\nThe system update has successfully completed. Reboot the system for the changes to take affect.\n" + RESETCOLORS else: print RED + BOLD + "\nThe system update failed to complete successfully. Address the failed post update tasks (" + taskFailureList + ") and then reboot the system for the changes to take affect.\n" + RESETCOLORS