def assign_ip_petitboot(self): """ Assign host ip in petitboot """ # Lets reduce timeout in petitboot self.cv_SYSTEM.console.run_command( "nvram --update-config petitboot,timeout=10", retry=5) # this will not work without these if not self.conf.args.host_mac \ or not self.conf.args.host_submask \ or not self.conf.args.host_gateway \ or not self.conf.args.host_dns: my_msg = ( "We need host_mac/host_submask/host_gateway/host_dns provided" " on command line args or via configuration files.") noconfig_exception = UnexpectedCase( state="assign_ip_petitboot config", message=my_msg) raise noconfig_exception cmd = ( "ip addr|grep -B1 -i %s |grep BROADCAST|awk -F ':' '{print $2}'" % (self.conf.args.host_mac)) log.debug("ip addr cmd={}".format(cmd, type(cmd))) iface = self.cv_SYSTEM.console.run_command(cmd, retry=5) log.debug("iface={} type={} len={}".format(iface, type(iface), len(iface))) if len(iface) >= 1: iface = self.cv_SYSTEM.console.run_command(cmd)[0].strip() else: my_msg = ( "We did NOT get interface back from query, UNABLE to proceed with trying to " "setup the IP, check that Petitboot or Host OS is configured properly." ) noface_exception = UnexpectedCase( state="assign_ip_petitboot interface", message=my_msg) raise noiface_exception cmd = ("ifconfig %s %s netmask %s" % (iface, self.cv_HOST.ip, self.conf.args.host_submask)) log.debug("ifconfig cmd={}".format(cmd)) self.cv_SYSTEM.console.run_command(cmd, retry=5) cmd = ("route add default gateway %s" % self.conf.args.host_gateway) log.debug("route cmd={}".format(cmd)) self.cv_SYSTEM.console.run_command_ignore_fail(cmd) cmd = ("echo 'nameserver %s' > /etc/resolv.conf" % self.conf.args.host_dns) log.debug("nameserver cmd={}".format(cmd)) self.cv_SYSTEM.console.run_command(cmd, retry=5)
def get_server_ip(self): """ Get IP of server where test runs """ my_ip = "" try: self.configure_host_ip() except Exception as e: my_msg = "Exception trying configure_host_ip, e={}".format(e) configure_exception = UnexpectedCase(state="get_server_ip", message=my_msg) raise configure_exception retry = 30 while retry > 0: try: my_ip = self.cv_SYSTEM.get_my_ip_from_host_perspective() log.debug("get_server_ip my_ip={}".format(my_ip)) if not my_ip: my_msg = "We were not able to get IP from Petitboot or Host, check that the IP is configured" noip_exception = UnexpectedCase(state="get_server_ip", message=my_msg) raise noip_exception output = self.cv_SYSTEM.console.run_command( "ping {} -c 1".format(my_ip), retry=5) log.debug("get_server_ip output={}".format(output)) break except CommandFailed as cf: log.debug("get_server_ip CommandFailed cf={}".format(cf)) if cf.exitcode is 1: time.sleep(1) retry = retry - 1 pass else: log.debug("get_server_ip Exception={}".format(cf)) raise cf return my_ip
def configure_host_ip(self): self.wait_for_network() # Check if ip is assigned in petitboot try: self.ping_network() except CommandFailed as cf: log.debug("configure_host_ip CommandFailed={}".format(cf)) try: self.assign_ip_petitboot() self.ping_network() except Exception as e: log.debug("configure_host_ip Exception={}".format(e)) my_msg = "We failed to setup Petitboot or Host IP, check that the IP's are configured and any other configuration parms" noconfig_exception = UnexpectedCase(state="configure_host_ip", message=my_msg) raise noconfig_exception
def setup(self): self.cv_SYSTEM = self.conf.system() # we hope its not still too early # test no op_system self.capable = self.cv_SYSTEM.cronus_capable() if not self.cv_SYSTEM.cronus_capable(): log.debug("System is NOT cronus_capable={}".format( self.cv_SYSTEM.cronus_capable())) # safeguards self.env_ready = False self.cronus_ready = False return # rc=139 is a segfault (-11) log.debug("gethostbyname starts '{}'".format(self.conf.args.bmc_ip)) just_ip = socket.gethostbyname(self.conf.args.bmc_ip) log.debug("gethostbyname ends '{}'".format(just_ip)) proposed_target = just_ip + "_optest_target" ecmdtargetsetup_string = ("ecmdtargetsetup -n \"{}\" " "-env hw -sc \"k0:eth:{}\" " "-bmc \"k0:eth:{}\" " "-bmcid \"k0:{}\" " "-bmcpw \"k0:{}\"".format( proposed_target, just_ip, just_ip, self.conf.args.bmc_username, self.conf.args.bmc_password)) try: op_cronus_login = "******" self.cronus_env = os.path.join(self.conf.logdir, "cronus.env") if not os.path.isfile(op_cronus_login): log.warning("NO Cronus installed, check the system") return except Exception as e: log.warning("Cronus setup problem check the installation," " Exception={}".format(e)) try: source_string = ("source {} && " "ecmdsetup auto cro {} {} && " "printenv >{}".format( op_cronus_login, self.conf.args.cronus_product, self.conf.args.cronus_code_level, self.cronus_env)) command = "source" stdout_value = self.conf.util.cronus_subcommand( command=source_string, minutes=2) log.debug("source stdout='{}'".format(stdout_value)) if not os.path.isfile(self.cronus_env): log.error("NO Cronus environment " "data captured, this is a problem") raise UnexpectedCase(message="NO Cronus environment " "data captured, this is a problem") ecmd_dict = {} with open(self.cronus_env) as f: for line in f: new_line = line.split("=") for xs in match_list: if xs == new_line[0]: if len(new_line) >= 2: ecmd_dict[new_line[0]] = new_line[1].rstrip() log.debug("ECMD's len(match_list)={} len(ecmd_dict)={}, " "these may not match".format(len(match_list), len(ecmd_dict))) for k, v in sorted(ecmd_dict.items()): log.debug("ecmd_dict[{}]={}".format(k, ecmd_dict[k])) os.environ[k] = ecmd_dict[k] self.env_ready = True log.debug("cronus setup setting self.env_ready={}".format( self.env_ready)) except subprocess.CalledProcessError as e: tb = traceback.format_exc() raise UnexpectedCase( message="Cronus environment issue rc={} " "output={} traceback={}".format(e.returncode, e.output, tb)) except Exception as e: tb = traceback.format_exc() raise UnexpectedCase(message="Cronus environment issue " "Exception={} traceback={}".format(e, tb)) try: command = "ecmdtargetsetup" stdout_value = self.conf.util.cronus_subcommand( command=ecmdtargetsetup_string, minutes=2) log.debug("ecmdtargetsetup stdout='{}'".format(stdout_value)) target_string = "target {}".format(proposed_target) command = "target" stdout_value = self.conf.util.cronus_subcommand( command=target_string, minutes=2) log.debug("target stdout='{}'".format(stdout_value)) self.current_target = proposed_target log.debug("ECMD_TARGET={}".format(self.current_target)) # need to manually update the environment to persist os.environ['ECMD_TARGET'] = self.current_target command = "setupsp" stdout_value = self.conf.util.cronus_subcommand(command=command, minutes=2) log.debug("target stdout='{}'".format(stdout_value)) if self.cv_SYSTEM.get_state() not in [OpSystemState.OFF]: command = "crodetcnfg" crodetcnfg_string = ("crodetcnfg {}".format( self.conf.args.cronus_system_type)) stdout_value = self.conf.util.cronus_subcommand( command=crodetcnfg_string, minutes=2) log.debug("crodetcnfg stdout='{}'".format(stdout_value)) self.cronus_ready = True log.debug("cronus_ready={}".format(self.cronus_ready)) else: log.warning("Cronus problem setting up, we need the " "System powered ON and it is OFF") raise UnexpectedCase( state=self.cv_SYSTEM.get_state(), message=("Cronus setup problem, we need" " the System powered ON and it is OFF")) except subprocess.CalledProcessError as e: tb = traceback.format_exc() raise UnexpectedCase( message="Cronus setup issue rc={} output={}" " traceback={}".format(e.returncode, e.output, tb)) except Exception as e: tb = traceback.format_exc() raise UnexpectedCase(message="Cronus setup issue Exception={}" " traceback={}".format(e, tb))