def bringUpNetworks(self): count = 1 command = "ip link show|egrep -i \".*<BROADCAST,MULTICAST>.*DOWN.*\"|awk '{sub(/:$/, \"\", $2);print $2}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() nicList = out.splitlines() for nic in nicList: command = "ifconfig " + nic + " 10.1.1." + str(count) + "/32 up" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '' or result.returncode != 0: csurUtils.log("stdout = " + out, "error") csurUtils.log(err, "error") count += 1
def getNicBusList(self): nicBusList = [] commands = [] count = 0 if self.systemModel == 'DL580G7' or self.systemModel =='DL980G7' or self.systemModel =='BL680cG7': commands.append("lspci -v|grep -B1 NC --no-group-separator|sed -e '$!N;s/\\n/ /'|uniq -w 2|egrep -io \".{2}:.{2}\.[0-9]{1}|NC[0-9]+[a-z]{1,3}\"|sed -e '$!N;s/\\n/ /'| sort -k2") elif self.systemModel == 'DL580Gen8': commands.append("lspci -v|grep 'NetXtreme BCM5719'|uniq -w 2|egrep -io \".{2}:.{2}\.[0-9]{1}\"") #HP 331FLR commands.append("HP331FLR") commands.append("lspci -v|grep 'Intel Corporation 82599'|uniq -w 2|egrep -io \".{2}:.{2}\.[0-9]{1}\"") #HP 560SFP+ commands.append("HP560SFP") while count < len(commands): command = commands[count] result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") if len(commands) == 1: nicBusList = out.splitlines() else: tmpList = out.splitlines() nicBusList.extend(x + ' ' + commands[count + 1] for x in tmpList) count += 2 return nicBusList
def getFusionIOSoftwareInventory(self, csurData): started = False updateSoftwareList = [] regex = r"^FusionIOSoftware.*" csurUtils.log("Begin Getting FusionIO Software Inventory", "info") csurUtils.log("csurData = " + ":".join(csurData), "debug") fh = open(self.gapAnalysisFile, 'a') for data in csurData: if not re.match(regex, data) and not started: continue elif re.match(regex, data): started = True continue else: csurSoftwareList = data.split('|') csurSoftware = csurSoftwareList[0].strip() csurSoftwareEpoch = csurSoftwareList[1].strip() csurSoftwareVersion = csurSoftwareList[2].strip() command = "rpm -q --queryformat=\"%{buildtime} %{version}-%{release}\" " + csurSoftware + " 2> /dev/null" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.softwareError = True csurUtils.log("out = " + out, "debug") if result.returncode != 0: fh.write( csurUtils.conversion("| " + csurSoftware.ljust(25) + "| " + csurSoftwareVersion.ljust(25) + "| Missing".ljust(25, ' ') + "|" + "\n")) updateSoftwareList.append(csurSoftware + "-") continue installedSoftware = out.strip() installedSoftwareList = installedSoftware.split() installedSoftwareEpoch = installedSoftwareList[0] installedSoftwareVersion = installedSoftwareList[1] fh.write( csurUtils.conversion("| " + csurSoftware.ljust(25) + "| " + csurSoftwareVersion.ljust(25) + "| " + installedSoftwareVersion.ljust(23) + "|" + "\n")) fh.close() csurUtils.log("End Getting Software Inventory", "info")
def getSoftwareInventory(self, csurData): started = False softwareFound = False updateSoftwareList = [] logger.info("Begin Getting Software Inventory") logger.debug("csurData = " + ":".join(csurData)) regex = ".*" + self.OSDistLevel + ".*" + self.systemModel + ".*" for data in csurData: if not re.match('Software.*', data) and not softwareFound: continue elif re.match('Software.*', data): softwareFound = True continue elif not re.match(regex, data) and not started: continue elif re.match(regex, data): started = True continue elif re.match(r'\s*$', data): break else: csurSoftwareList = data.split('|') csurSoftware = csurSoftwareList[0].strip() csurSoftwareEpoch = csurSoftwareList[1].strip() csurSoftwareVersion = csurSoftwareList[2].strip() command = "rpm -q --queryformat=\"%{buildtime} %{version}-%{release}\" " + csurSoftware + " 2> /dev/null" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.softwareError = True logger.debug("software = " + csurSoftware) logger.debug("out = " + out) if result.returncode != 0: updateSoftwareList.append(csurSoftware) continue installedSoftware = out.strip() installedSoftwareList = installedSoftware.split() installedSoftwareEpoch = installedSoftwareList[0] installedSoftwareVersion = installedSoftwareList[1] if re.match(regex, csurSoftware): continue if installedSoftwareEpoch < csurSoftwareEpoch: updateSoftwareList.append(csurSoftware) logger.debug("updateSoftwareList = " + ":".join(updateSoftwareList)) logger.info("End Getting Software Inventory") return updateSoftwareList
def getFusionIODriverInventory(self, csurData): started = False updateDriverList = [] csurUtils.log("Begin Getting FusionIO Driver Inventory", "info") csurUtils.log("csurData = " + ":".join(csurData), "debug") fh = open(self.gapAnalysisFile, 'a') regex = r"^FusionIODriver.*" for data in csurData: if not re.match(regex, data) and not started: continue elif re.match(regex, data): started = True continue else: csurDriverList = data.split('|') csurDriver = csurDriverList[0].strip() csurDriverVersion = csurDriverList[1].strip() command = "fio-status -v|awk '{print $1}'|egrep -o \"^[0-9]{1}\.[0-9]{1}\.[0-9]{1}\"" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.driverError = True csurUtils.log("out = " + out, "debug") installedDriverVersion = out.strip() fh.write( csurUtils.conversion("| " + csurDriver.ljust(25) + "| " + csurDriverVersion.ljust(25) + "| " + installedDriverVersion.ljust(23) + "|" + "\n")) break fh.close() csurUtils.log("End Getting FusionIO Driver Inventory", "info")
def getFirmwareDict(self, csurData): started = False firmwareDict = {} csurUtils.log("Begin Getting Firmware Dictionary", "info") for data in csurData: if not re.match(r'Firmware.*', data) and not started: continue elif re.match(r'Firmware.*', data): started = True continue elif re.match(r'\s*$', data): break else: firmwareList = data.split('|') firmwareDict[firmwareList[0].strip()] = firmwareList[1].strip() csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("End Getting Firmware Dictionary", "info") return firmwareDict
def getComputeNodeSpecificFirmwareInventory(self, firmwareDict, updateList): fh = open(self.gapAnalysisFile, 'a') csurUtils.log("Begin Getting Compute Node Specific Firmware Inventory", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("updateList = " + ":".join(updateList), "debug") #Power Management Controller fh2 = open("dmidecode.log", 'w') subprocess.call(["dmidecode"], stdout=fh2) fh2.close() command = "egrep -A 1 \"^\s*Power Management Controller Firmware\s*$\" dmidecode.log |grep -v Power |sed -e 's/^[ \t]*//'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() fh.write( csurUtils.conversion("| " + 'PMCDL580Gen8'.ljust(25) + "| " + (firmwareDict.get('PMCDL580Gen8')).ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) fh.close() os.remove("dmidecode.log") csurUtils.log("End Getting Compute Node Specific Firmware Inventory", "info")
def getComputeNodeSpecificFirmwareInventory(self, firmwareDict, updateList): fh = open(self.gapAnalysisFile, 'a') csurUtils.log("Begin Getting Compute Node Specific Firmware Inventory", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("updateList = " + ":".join(updateList), "debug") #Fusion-IO command = "fio-status|grep -i -m 1 firmware|awk '{sub(/,/,\"\"); sub(/v/, \"\");print $2\".\"$4}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() fh.write( csurUtils.conversion("| " + 'FusionIO'.ljust(25) + "| " + firmwareDict.get('FusionIO').ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) fh.close() csurUtils.log("End Getting Compute Node Specific Firmware Inventory", "info")
def getStorageFirmwareInventory(self, firmwareDict, updateList): fh = open(self.gapAnalysisFile, 'a') csurUtils.log("Begin Getting Storage Firmware Inventory", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("updateList = " + ":".join(updateList), "debug") #hpacucli has been replaced by hpssacli so we need to check in case we are on an older system. if os.path.isfile('/usr/sbin/hpssacli'): arrayCfgUtilFile = '/usr/sbin/hpssacli' else: arrayCfgUtilFile = '/usr/sbin/hpacucli' csurUtils.log("arrayCfgUtilFile = " + arrayCfgUtilFile, "debug") #Get list of storage controllers. command = arrayCfgUtilFile + " ctrl all show status|egrep -o \"P.*Slot\s*[0-9]{1,2}\"|awk '{print $1\":\"$NF}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") controllerList = out.splitlines() hardDriveList = [ ] #This is a complete list of hard drives from all controllers combined. for controller in controllerList: controllerModel = controller[0:controller.index(':')] controllerSlot = controller[controller.index(':') + 1:len(controller)] csurFirmwareVersion = firmwareDict.get(controllerModel) command = arrayCfgUtilFile + " ctrl slot=" + controllerSlot + " show |grep \"Firmware Version\"|awk '{print $3}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() if installedFirmwareVersion != csurFirmwareVersion: updateList.append(controllerModel) fh.write( csurUtils.conversion("| " + controllerModel.ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) if (controllerModel == 'P812') or (controllerModel == 'P431'): csurFirmwareVersion = firmwareDict.get('D2700') command = arrayCfgUtilFile + " ctrl slot=" + controllerSlot + " enclosure all show detail|grep -m 1 \"Firmware Version\"|awk '{print $3}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() if installedFirmwareVersion != csurFirmwareVersion: updateList.append('D2700') fh.write( csurUtils.conversion("| " + "D2700".ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) #Get a list of all hard drives and thier firmware version. command = arrayCfgUtilFile + " ctrl slot=" + controllerSlot + " pd all show detail|grep -A 2 --no-group-separator \"Firmware Revision\"|grep -v Serial|sed -e '$!N;s/\\n/ /'|awk '{print $6, $3}'|sort -k1" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") hardDriveList.extend( out.splitlines() ) #out is an array of hard drives and their firmware version, e.g. 'EG0600FBVFP HPDC' #Sort the hard drive list since it may not be sorted due to multiple controllers. hardDriveList.sort() #Get a unique list of hard drives managed by the controllers. hardDriveModels = [] count = 0 for hd in hardDriveList: hardDriveData = hd.split() if count == 0: hardDriveModels.append(hardDriveData[0].strip()) tmpHardDriveModel = hardDriveData[0] count += 1 elif hardDriveData[0] != tmpHardDriveModel: hardDriveModels.append(hardDriveData[0].strip()) tmpHardDriveModel = hardDriveData[0] #Now check each hard drive's firmware version. for hardDriveModel in hardDriveModels: count = 0 csurFirmwareVersion = firmwareDict.get(hardDriveModel) #This accounts for the cases where the CSUR did not include a hard drive's firmware. if csurFirmwareVersion is None: csurFirmwareVersion = 'Missing' fh.write( csurUtils.conversion("| " + hardDriveModel.ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| ".ljust(25, ' ') + "|" + "\n")) continue #Now check every hard drive's firmware version that matches the current hardDriveModel. for hd in hardDriveList: hardDriveData = hd.split() if hardDriveData[0].strip() == hardDriveModel: hardDriveFirmwareVersion = hardDriveData[1].strip() ''' If the hard drive version does not match the CSUR version then add it to the updateList. We only care about a one time occurance of a firmware mis-match. ''' if hardDriveFirmwareVersion != csurFirmwareVersion: updateList.append(hardDriveModel) fh.write( csurUtils.conversion( "| " + hardDriveModel.ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| " + hardDriveFirmwareVersion.ljust(23) + "|" + "\n")) count += 1 break #If all the hard drives for the given model have firmware matching the CSUR then count will be 0. if count == 0: fh.write( csurUtils.conversion("| " + hardDriveModel.ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| " + hardDriveFirmwareVersion.ljust(23) + "|" + "\n")) fh.close() csurUtils.log("End Getting Storage Firmware Inventory", "info")
def getDriverInventory(self, csurData): started = False updateDriverList = [] csurUtils.log("Begin Getting Driver Inventory", "info") csurUtils.log("csurData = " + ":".join(csurData), "debug") fh = open(self.gapAnalysisFile, 'a') regex = self.OSDistLevel + ".*" + self.systemModel + ".*" for data in csurData: if not re.match(regex, data) and not started: continue elif re.match(regex, data): started = True continue elif re.match(r'\s*$', data): break else: csurDriverList = data.split('|') csurDriver = csurDriverList[0].strip() csurDriverVersion = csurDriverList[1].strip() command = "modinfo " + csurDriver + "|grep -i ^version|awk '{print $2}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.driverError = True csurUtils.log("out = " + out, "debug") installedDriverVersion = out.strip() fh.write( csurUtils.conversion("| " + csurDriver.ljust(25) + "| " + csurDriverVersion.ljust(25) + "| " + installedDriverVersion.ljust(23) + "|" + "\n")) if installedDriverVersion != csurDriverVersion: updateDriverList.append(csurDriver) fh.close() csurUtils.log("updateDriverList = " + ":".join(updateDriverList), "debug") csurUtils.log("End Getting Driver Inventory", "info") return updateDriverList
def getCommonFirmwareInventory(self, firmwareDict, updateList): biosFirmwareType = "BIOS" + self.systemModel fh = open(self.gapAnalysisFile, 'a') csurUtils.log("Begin Getting Compute Node Common Firmware Inventory", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("updateList = " + ":".join(updateList), "debug") #BIOS command = "dmidecode -s bios-release-date" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") biosFirmwareDate = out.strip() biosFirmwareDateList = biosFirmwareDate.split('/') installedFirmwareVersion = biosFirmwareDateList[ 2] + '.' + biosFirmwareDateList[0] + '.' + biosFirmwareDateList[1] csurFirmwareVersion = firmwareDict.get(biosFirmwareType) if installedFirmwareVersion != csurFirmwareVersion: updateList.append(biosFirmwareType) fh.write( csurUtils.conversion("| " + biosFirmwareType.ljust(25) + "| " + csurFirmwareVersion.ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) #iLO command = "hponcfg -g|grep \"Firmware Revision\"|awk '{print $4}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() if installedFirmwareVersion != firmwareDict.get('iLO'): updateList.append('iLO') fh.write( csurUtils.conversion("| " + 'iLO'.ljust(25) + "| " + firmwareDict.get('iLO').ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) fh.close() csurUtils.log("End Getting Compute Node Common Firmware Inventory", "info")
def getNICFirmwareInventory(self, firmwareDict, updateList): nicCardModels = [] count = 0 csurUtils.log("Begin Getting NIC Firmware Inventory", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") csurUtils.log("updateList = " + ":".join(updateList), "debug") nicBusList = self.getNicBusList() #Get a unique list of nic card models. for nd in nicBusList: #['03:00.0 HP331FLR', '44:00.0 HP560SFP', '47:00.0 HP560SFP'] nicCardData = nd.split() if count == 0: nicCardModels.append(nicCardData[1].strip()) tmpNicCardModel = nicCardData[1] count += 1 elif nicCardData[1] != tmpNicCardModel: nicCardModels.append(nicCardData[1].strip()) tmpNicCardModel = nicCardData[1] #Get nic card list which will be used to map nic card bus to nic device. command = "ifconfig -a|egrep -v \"^\s+|^bond|^lo|^\s*$\"|awk '{print $1}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") nicCardList = out.splitlines( ) #['em0', 'em1', 'em2', 'em3', 'p4p1', 'p4p2', 'p5p1', 'p5p2', 'p7p1', 'p7p2', 'p8p1', 'p8p2'] fh = open(self.gapAnalysisFile, 'a') #Loop through all nic cards to check thier firmware. Only record one occcurance of a mismatch. for nicCardModel in nicCardModels: #['HP331FLR', 'HP560SFP'] count = 0 csurNicCardFirmwareVersion = firmwareDict.get(nicCardModel) for data in nicBusList: nicCardData = data.split() nicBus = nicCardData[0].strip() installedNicCardModel = nicCardData[1].strip() if installedNicCardModel == nicCardModel: for nic in nicCardList: command = "ethtool -i " + nic + "|grep " + nicBus result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") if result.returncode != 0: continue else: nicDevice = nic command = "ethtool -i " + nicDevice + "|grep firmware-version|awk '{print $NF}'" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.firmwareError = True csurUtils.log("out = " + out, "debug") installedFirmwareVersion = out.strip() if installedFirmwareVersion != csurNicCardFirmwareVersion and count == 0: updateList.append(nicCardModel) fh.write( csurUtils.conversion( "| " + nicCardModel.ljust(25) + "| " + csurNicCardFirmwareVersion.ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) count += 1 break #We only get here if a nic card matched the nicBus we are looking at. else: continue if count == 1: break if count == 0: fh.write( csurUtils.conversion("| " + nicCardModel.ljust(25) + "| " + csurNicCardFirmwareVersion.ljust(25) + "| " + installedFirmwareVersion.ljust(23) + "|" + "\n")) fh.close() csurUtils.log("End Getting NIC Firmware Inventory", "info")
def finalizeUpdate(self, hostname, systemModel): date = (datetime.date.today()).strftime('%d, %b %Y') dateCaption = "System Update Date: " + date title = "System update for " + hostname + " (" + systemModel + ")" successfulSoftware = [] successfulDrivers = [] successfulFirmware = [] unSuccessfulSoftware = [] unSuccessfulDrivers = [] unSuccessfulFirmware = [] self.getSuccessfulComponentInstalls(successfulSoftware, successfulDrivers, successfulFirmware) self.getUnsuccessfulComponentInstalls(unSuccessfulSoftware, unSuccessfulDrivers, unSuccessfulFirmware) csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS csurUtils.log("| " + dateCaption.ljust(77) + "|", "info") print csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + dateCaption.ljust( 77) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS csurUtils.log("|" + title.center(78) + "|", "info") print csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS + title.center( 78) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS #Print successful updates. count = max(len(successfulSoftware), len(successfulDrivers), len(successfulFirmware)) if count != 0: csurUtils.log( "|" + "The following components were successfully updated".center(78) + "|", "info") print csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS + csurUtils.GREEN + "The following components were successfully updated".center( 78 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS csurUtils.log( "| Software".ljust(27) + "| Drivers".ljust(27) + "| Firmware".ljust(25) + "|", "info") print csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Software".ljust( 25 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Drivers".ljust( 25 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Firmware".ljust( 23 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS for i in range(0, count): if len(successfulSoftware) > i: row = "| " + successfulSoftware[i].ljust(25) + "| " printRow = csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + successfulSoftware[ i].ljust( 25 ) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS else: row = "| " + ' '.ljust(25) + "| " printRow = csurUtils.YELLOW + "| " + ' '.ljust( 25) + "| " + csurUtils.RESETCOLORS if len(successfulDrivers) > i: row = row + successfulDrivers[i].ljust(25) + "| " printRow = printRow + successfulDrivers[i].ljust( 25) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS else: row = row + ' '.ljust(25) + "| " printRow = printRow + ' '.ljust( 25) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS if len(successfulFirmware) > i: row = row + successfulFirmware[i].ljust(23) + "|" printRow = printRow + successfulFirmware[i].ljust( 23) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS else: row = row + ' '.ljust(23) + "|" printRow = printRow + ' '.ljust( 23) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log(row, "info") print printRow csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS #Print unsuccessful updates. count = max(len(unSuccessfulSoftware), len(unSuccessfulDrivers), len(unSuccessfulFirmware)) rows = '' if count != 0: csurUtils.log( "|" + "The following components were unsuccessfully updated".center( 78) + "|", "info") print csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS + csurUtils.RED + "The following components were unsuccessfully updated".center( 78 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS csurUtils.log( "| Software".ljust(27) + "| Drivers".ljust(27) + "| Firmware".ljust(25) + "|", "info") print csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Software".ljust( 25 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Drivers".ljust( 25 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + csurUtils.BLUE + "Firmware".ljust( 23 ) + csurUtils.RESETCOLORS + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS for i in range(0, count): if len(unSuccessfulSoftware) > i: row = "| " + unSuccessfulSoftware[i].ljust(25) + "| " printRow = csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS + unSuccessfulSoftware[ i].ljust( 25 ) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS else: row = "| " + ' '.ljust(25) + "| " printRow = csurUtils.YELLOW + "| " + ' '.ljust( 25) + "| " + csurUtils.RESETCOLORS if len(unSuccessfulDrivers) > i: row = row + unSuccessfulDrivers[i].ljust(25) + "| " printRow = printRow + unSuccessfulDrivers[i].ljust( 25) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS else: row = row + ' '.ljust(25) + "| " printRow = printRow + ' '.ljust( 25) + csurUtils.YELLOW + "| " + csurUtils.RESETCOLORS if len(unSuccessfulFirmware) > i: row = row + unSuccessfulFirmware[i].ljust(23) + "|" printRow = printRow + unSuccessfulFirmware[i].ljust( 23) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS else: row = row + ' '.ljust(23) + "|" printRow = printRow + ' '.ljust( 23) + csurUtils.YELLOW + "|" + csurUtils.RESETCOLORS csurUtils.log(row, "info") print printRow csurUtils.log("+" + "-" * 78 + "+", "info") print csurUtils.YELLOW + "+" + "-" * 78 + "+" + csurUtils.RESETCOLORS if count != 0: print csurUtils.RED + "\nThe update completed with errors. Check log file for additional information." + csurUtils.RESETCOLORS exit(1) else: print csurUtils.GREEN + "\nThe update completed successfully. Reboot the system for changes to take affect." + csurUtils.RESETCOLORS exit(0)
def updateFirmware(self, firmwareDict, OSDistLevel): self.updateFirmwareDict = firmwareDict firmwareDir = self.baseDir + 'firmware/' #This is for firmware that is installed using a smart component. regex = ".*\.scexe" #This would be part of the error message if already installed. message = "is already installed" csurUtils.log("Begin Updating firmware.", "info") csurUtils.log("firmwareDict = " + str(firmwareDict), "debug") #This may not be necessary if not updating NIC cards, but it won't hurt either. self.bringUpNetworks() for firmwareKey in firmwareDict: time.sleep(2) timeFeedbackThread = csurUtils.TimeFeedbackThread( "firmware", firmwareKey) timeFeedbackThread.start() ''' If updating DL580Gen8 (CS500)BIOS to 1.6 make required network configuration changes. This applies to CSUR1506. ''' if firmwareKey == "BIOSDL580Gen8" and re.match( "SLES.*", OSDistLevel) and re.match( ".*p79-1.60", firmwareDict[firmwareKey]): command = "updateNetworkCFGFiles.pl" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") if re.match(regex, firmwareDict[firmwareKey]): os.chdir(firmwareDir) command = "./" + firmwareDict[firmwareKey] + " -f -s" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") csurUtils.log("out = " + out, "debug") if result.returncode == 3: csurUtils.log("stdout = " + out, "error") self.installFirmwareProblemDict[firmwareKey] = '' timeFeedbackThread.stopTimer() timeFeedbackThread.join() else: rpm = firmwareDict[firmwareKey] command = "rpm -U --oldpackage --nosignature " + firmwareDir + rpm result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '' or result.returncode == 1: if err == '': csurUtils.log("stdout = " + out, "error") self.installFirmwareProblemDict[firmwareKey] = '' timeFeedbackThread.stopTimer() timeFeedbackThread.join() continue else: if not err.find(message): csurUtils.log(err, "error") self.installFirmwareProblemDict[firmwareKey] = '' timeFeedbackThread.stopTimer() timeFeedbackThread.join() continue ''' Currently firmware RPMs end with x86_64.rpm or i386.rpm. ''' if rpm.endswith("x86_64.rpm"): firmwareRPMDir = '/usr/lib/x86_64-linux-gnu/' setupDir = firmwareRPMDir + rpm[0:rpm.index('.x86_64.rpm')] else: firmwareRPMDir = '/usr/lib/i386-linux-gnu/' setupDir = firmwareRPMDir + rpm[0:rpm.index('.i386.rpm')] os.chdir(setupDir) setupFile = setupDir + "/hpsetup" ''' Need to check setup file, since there is no consistency between RPM images. ''' if os.path.isfile(setupFile): command = "./hpsetup -f -s" else: command = "./.hpsetup -f -s" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if result.returncode == 3: csurUtils.log("stdout = " + out, "error") self.installFirmwareProblemDict[firmwareKey] = '' timeFeedbackThread.stopTimer() timeFeedbackThread.join() if len(self.installFirmwareProblemDict) != 0: print csurUtils.RED + "\tThere were problems updating the firmware.\n\tCheck the log file for additional information.\n" + csurUtils.RESETCOLORS else: print csurUtils.GREEN + "\tFirmware update completed successfully.\n" + csurUtils.RESETCOLORS csurUtils.log("End Updating firmware.", "info")
def updateSoftware(self, softwareToUpdate, softwareDict, OSDistLevel): self.updateSoftwareDict = softwareDict softwareDir = self.baseDir + 'software/' + OSDistLevel + '/' csurUtils.log("Begin Updating software.", "info") csurUtils.log("softwareDict = " + str(softwareDict), "debug") for software in softwareToUpdate: time.sleep(2) print "\tUpdating package " + software #Need to removed hponcfg first on RHEL systems due to package version mis-match causing installtion file conflicts. if software == "hponcfg" and re.match("RHEL6.*", OSDistLevel): #First make sure it is already installed command = "rpm -q hponcfg" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if result.returncode == 0: command = "rpm -e hponcfg" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") self.installSoftwareProblemDict[software] = '' continue #hp-health needs to be stopped first since it has been known to cause installtion problems. if software == "hp-health": #First make sure it is already installed command = "rpm -q hp-health" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() #This means hp-health is installed. if result.returncode == 0: command = "/etc/init.d/hp-health stop" #Spend up to two minutes trying to stop hp-health timedProcessThread = csurUtils.TimedProcessThread( command, 120) timedProcessThread.start() returncode = timedProcessThread.join() if returncode != 0: csurUtils.log( "hp-health could not be stopped; will try to kill it now.", "error") command = "pgrep -x hpasmlited" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() #The result should be 0 unless it just stopped suddenly. if result.returncode == 0: hpHealthPID = out.strip() command = "kill -9 " + hpHealthPID #Spend up to two more minutes trying to stop hp-health timedProcessThread = csurUtils.TimedProcessThread( command, 120) timedProcessThread.start() returncode = timedProcessThread.join() if returncode != 0: csurUtils.log( "hp-health could not be stopped; skipping update of hp-health.", "error") self.installSoftwareProblemDict[software] = '' continue command = "rpm -U --oldpackage --nosignature " + softwareDir + softwareDict[ software] csurUtils.log("command = " + command, "debug") result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() csurUtils.log("out = " + out, "debug") if result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") self.installSoftwareProblemDict[software] = '' if len(self.installSoftwareProblemDict) != 0: print csurUtils.RED + "\tThere were problems updating the software.\n\tCheck the log file for additional information.\n" + csurUtils.RESETCOLORS else: print csurUtils.GREEN + "\tSoftware update completed successfully.\n" + csurUtils.RESETCOLORS csurUtils.log("End Updating software.", "info")
def updateDrivers(self, driverDict, OSDistLevel, systemModel): self.updateDriverDict = driverDict driverDir = self.baseDir + 'drivers/' + OSDistLevel + '/' csurUtils.log("Begin Updating drivers.", "info") csurUtils.log("driverDict = " + str(driverDict), "debug") for driverKey in driverDict: time.sleep(2) print "\tUpdating driver " + driverKey ''' nx_nic driver has to be removed first if it is an old driver, since the packages have been renamed. We also save a copy of the original RPMs just in case. ''' if driverKey == "nx_nic" and ((systemModel == 'DL580G7') or (systemModel == 'DL980G7')): command = "rpm -qa|grep ^hpqlgc-nx" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if result.returncode != 0: command = "rpm -e hp-nx_nic-kmp-default hp-nx_nic-tools" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '' or result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") self.installDriverProblemDict[driverKey] = '' continue #Need to remove the hp-be2net-kmp-default driver first as it will cause a conflict. if driverKey == "be2net": command = "rpm -q hp-be2net-kmp-default" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if result.returncode == 0: command = "rpm -e hp-be2net-kmp-default" result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() if err != '': csurUtils.log(err, "error") self.installDriverProblemDict[driverKey] = '' continue if ':' not in driverDict[driverKey]: driverRPMList = driverDir + driverDict[driverKey] else: if driverKey != "be2net": driverRPMsString = driverDict[driverKey] tmpDriverRPMList = driverRPMsString.replace( ':', ' ' + driverDir) driverRPMList = driverDir + tmpDriverRPMList else: ''' We have to install the driver before the Fibre Channel Enablement Kit. Thus we will install the be2net driver and Fibre Channel Enablement Kit as a separate step. ''' driverRPMsString = driverDict[driverKey] location = driverRPMsString.find(':') driver = driverDir + (driverRPMsString[:location]) newRPMList = (driverRPMsString[(location + 1):]) tmpNewRPMList = newRPMList.replace(':', ' ' + driverDir) cnaRPMList = driverDir + tmpNewRPMList #Install the be2net driver. command = "rpm -U --oldpackage --nosignature " + driver result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() csurUtils.log("out = " + out, "debug") if result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") self.installDriverProblemDict[driverKey] = '' continue #Install the Fibre Channel Enablement Kit. command = "rpm -U --replacepkgs --nosignature " + cnaRPMList result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() csurUtils.log("out = " + out, "debug") if result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") continue command = "rpm -U --oldpackage --nosignature " + driverRPMList result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = result.communicate() csurUtils.log("out = " + out, "debug") if result.returncode != 0: csurUtils.log(err, "error") csurUtils.log("stdout = " + out, "error") self.installDriverProblemDict[driverKey] = '' if len(self.installDriverProblemDict) != 0: print csurUtils.RED + "\tThere were problems updating the drivers.\n\tCheck the log file for additional information.\n" + csurUtils.RESETCOLORS else: print csurUtils.GREEN + "\tDriver update completed successfully.\n" + csurUtils.RESETCOLORS csurUtils.log("End Updating drivers.", "info")