def post_system_test(self): foreman = Foreman( conf["foreman_api_url"], self.cloud.name, self.cloud.ticket ) quads = Api(API_URL) if not foreman.verify_credentials(): logger.error("Unable to query Foreman for cloud: %s" % self.cloud.name) logger.error("Verify Foreman password is correct: %s" % self.cloud.ticket) self.report = self.report + "Unable to query Foreman for cloud: %s\n" % self.cloud.name self.report = self.report + "Verify Foreman password is correct: %s\n" % self.cloud.ticket return False build_hosts = foreman.get_build_hosts() pending = [] schedules = quads.get_current_schedule(cloud=self.cloud.name) if "result" not in schedules: for schedule in schedules: host = quads.get_hosts(id=schedule["host"]["$oid"]) if host and host['name'] in build_hosts: pending.append(host["name"]) if pending: logger.info("The following hosts are marked for build:") self.report = self.report + "The following hosts are marked for build:\n" for host in pending: logger.info(host) self.report = self.report + "%s\n" % host return False return True
def post_system_test(self): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) password = f"{conf['infra_location']}@{self.cloud.ticket}" foreman = Foreman( conf["foreman_api_url"], self.cloud.name, password, loop=loop, ) if not loop.run_until_complete(foreman.verify_credentials()): logger.error("Unable to query Foreman for cloud: %s" % self.cloud.name) logger.error("Verify Foreman password is correct: %s" % password) self.report = ( self.report + "Unable to query Foreman for cloud: %s\n" % self.cloud.name ) self.report = ( self.report + "Verify Foreman password is correct: %s\n" % password ) return False build_hosts = loop.run_until_complete(foreman.get_build_hosts()) pending = [] schedules = Schedule.current_schedule(cloud=self.cloud) if schedules: for schedule in schedules: if schedule.host and schedule.host.name in build_hosts: pending.append(schedule.host.name) if pending: logger.info( "The following hosts are marked for build and will now be rebooted:" ) self.report = ( self.report + "The following hosts are marked for build:\n" ) for host in pending: logger.info(host) nc = Netcat(host) if not nc.health_check(): logger.warning( "Host %s didn't pass the health check. " "Potential provisioning in process. SKIPPING." % host ) continue nc.close() badfish = None try: badfish = loop.run_until_complete( badfish_factory( "mgmt-" + host, str(conf["ipmi_username"]), str(conf["ipmi_password"]), ) ) if is_supported(host): loop.run_until_complete( badfish.boot_to_type( "foreman", os.path.join( os.path.dirname(__file__), "../../conf/idrac_interfaces.yml", ), ) ) else: loop.run_until_complete(badfish.set_next_boot_pxe()) loop.run_until_complete(badfish.reboot_server()) except BadfishException as ಥ﹏ಥ: logger.debug(ಥ﹏ಥ) if badfish: logger.warning(f"There was something wrong trying to boot from Foreman interface for: {host}") loop.run_until_complete(badfish.reboot_server()) else: logger.error(f"Could not initiate Badfish instance for: {host}") self.report = self.report + "%s\n" % host return False failed = False for host in self.hosts: try: badfish = loop.run_until_complete( badfish_factory( "mgmt-" + host.name, str(conf["ipmi_cloud_username"]), password, ) ) loop.run_until_complete(badfish.validate_credentials()) except BadfishException: logger.info(f"Could not verify badfish credentials for: {host.name}") failed = True return not failed