def handle_reload_cmd(self, fsm_ctx): self.ctx.send("yes", timeout=30) self.op_id = self.get_op_id(fsm_ctx.ctrl.before) if self.op_id == -1: self.fsm_result = False return False sleep(60) try: watch_operation(self.ctx, self.op_id) except self.ctx.CommandTimeoutError: # The device already started the reload pass success = wait_for_reload(self.ctx) if not success: self.ctx.error("Reload or boot failure") self.fsm_result = False return self.ctx.info("Operation {} finished successfully".format(self.op_id)) self.fsm_result = True return True
def run(self): need_reload = False # XR ddts CSCvb67386 workaround # if cbc only or power module only, then do not reload avoid_reload = False self.ctx.info("FPD-Upgrade Pending") self.ctx.post_status("FPD-Upgrade Pending") if not fpd_package_installed(self.ctx): self.ctx.error("No FPD package is active on device. " "Please install and activate the FPD package on device first.") return False fpd_location = self.ctx.load_job_data('fpd_location')[0] fpd_type = self.ctx.load_job_data('fpd_type')[0] self.ctx.info("fpd_location = {}".format(fpd_location)) self.ctx.info("fpd_type = {}".format(fpd_type)) if not fpd_location: fpd_location = 'all' if not fpd_type: fpd_type = 'all' # case 1: both fpd_location and fpd_type are none. # case 2: only fpd_location is specified # case 3: only fpd_type is specified # case 4: both fpd_location and fpd_type are specified locations = fpd_locations(self.ctx) self.ctx.info("FPD Location to be upgraded = {}".format(locations)) upgd_result = True begin = time.time() for location in locations: if location == fpd_location or fpd_location == 'all': if fpd_needs_upgd(self.ctx, location, fpd_type): need_reload = True if not hw_fpd_upgd(self.ctx, location, fpd_type): upgd_result = False else: continue if not need_reload: self.ctx.info("All FPD devices are current. Nothing to be upgraded.") return True if 'cbc' in fpd_type or '/PS' in 'fpd_location': avoid_reload = True if fpd_location == 'all' and fpd_type == 'all': avoid_reload = cbc_pwr_only(self.ctx) if not avoid_reload: elapsed = time.time() - begin self.ctx.info("Overall fpd upgrade time: {} minute(s) {:.0f} second(s)".format(elapsed // 60, elapsed % 60)) self.ctx.info("Reloading the host") if not hw_fpd_reload(self.ctx, fpd_location): self.ctx.warning("Encountered error when attempting to reload device.") self.ctx.info("Wait for the host reload to complete") success = wait_for_reload(self.ctx) if not success: self.ctx.error("Reload or boot failure") return False self.ctx.info("Refreshing package and inventory information") self.ctx.post_status("Refreshing package and inventory information") # Refresh package and inventory information get_package(self.ctx) get_inventory(self.ctx) update_device_info_udi(self.ctx) if upgd_result: for location in locations: if location == fpd_location or fpd_location == 'all': if not fpd_check_status(self.ctx, location, fpd_type): upgd_result = False else: continue if upgd_result: self.ctx.info("FPD-Upgrade Successfully") return True else: self.ctx.error("FPD-Upgrade completed but the status of one or more nodes is not current") return False
def run(self): self.ctx.info("FPD-Upgrade Pending") self.ctx.post_status("FPD-Upgrade Pending") fpd_location = self.ctx.load_job_data('fpd_location')[0] fpd_type = self.ctx.load_job_data('fpd_type')[0] self.ctx.info("fpd_location = {}".format(fpd_location)) self.ctx.info("fpd_type = {}".format(fpd_type)) # case 1: both fpd_location and fpd_type are none. if not fpd_location and not fpd_type: fpd_location = 'all' fpd_type = 'all' # case 2: only fpd_location is specified # case 3: only fpd_type is specified # case 4: both fpd_location and fpd_type are specified if fpd_is_current(self.ctx, fpd_location, fpd_type): self.ctx.info("All FPD devices are CURRENT. Nothing to be upgraded.") return True upgd_locations = fpd_needs_upgd(self.ctx, fpd_location, fpd_type) self.ctx.info("locations to be upgraded = {}".format(upgd_locations)) if upgd_locations: if fpd_location == 'all' and fpd_type == 'all': if not hw_fpd_upgd(self.ctx, fpd_location, fpd_type): self.ctx.error("Fail to issue {}".format('upgrade hw-module location all fpd all')) return wait_for_fpd_upgd(self.ctx, fpd_location, fpd_type) elif fpd_location and not fpd_type: type = 'all' if not hw_fpd_upgd(self.ctx, fpd_location, type): cmd = 'upgrade hw-module location ' + fpd_location + ' fpd ' + type self.ctx.error("Fail to issue {}".format(cmd)) return wait_for_fpd_upgd(self.ctx, fpd_location, type) elif not fpd_location and fpd_type: for location in upgd_locations: if not hw_fpd_upgd(self.ctx, location, fpd_type): cmd = 'upgrade hw-module location ' + location + ' fpd ' + fpd_type self.ctx.error("Fail to issue {}".format(cmd)) return wait_for_fpd_upgd(self.ctx, location, fpd_type) time.sleep(30) # CLI may not work if issuing too quickly else: if not hw_fpd_upgd(self.ctx, fpd_location, fpd_type): cmd = 'upgrade hw-module location ' + fpd_location + ' fpd ' + fpd_type self.ctx.error("Fail to issue {}".format(cmd)) return wait_for_fpd_upgd(self.ctx, fpd_location, fpd_type) if not fpd_location and fpd_type: # check if RP0 / RP1 is to be reloaded location = None if upgd_locations: for location in upgd_locations: if 'RP' in location or 'RSP' in location: location = 'all' break if location == 'all': if not hw_fpd_reload(self.ctx, location): cmd = 'admin hw-module location ' + location + ' reload' self.ctx.error("Fail to issue {}".format(cmd)) return else: if upgd_locations: for location in upgd_locations: if not hw_fpd_reload(self.ctx, location): cmd = 'admin hw-module location ' + location + ' reload' self.ctx.error("Fail to issue {}".format(cmd)) return time.sleep(10) else: if not hw_fpd_reload(self.ctx, fpd_location): cmd = 'admin hw-module location ' + fpd_location + ' reload' self.ctx.error("Fail to issue {}".format(cmd)) return success = wait_for_reload(self.ctx) if not success: self.ctx.error("Reload or boot failure") return self.ctx.info("Refreshing package and inventory information") self.ctx.post_status("Refreshing package and inventory information") # Refresh package and inventory information get_package(self.ctx) get_inventory(self.ctx) update_device_info_udi(self.ctx) if fpd_check_status(self.ctx, fpd_location, fpd_type): self.ctx.info("FPD-Upgrade Successfully") return True else: self.ctx.error("FPD-Upgrade Completed but the status of one or more nodes is not Current or N/A") return False