def download_url(urlpath, output_dir=".", binary=False): http = PoolManager() req = http.request("GET", urlpath) if req.status != 200: raise Exception("Could not get file from " + urlpath) parsed = urlparse(urlpath) filename = os.path.basename(parsed.path) writemod = "wb" if binary else "w" contents = req.data if output_dir != ".": if not os.path.exists(output_dir): log.error("{0} does not exist".format(output_dir)) log.error("Writing file to {0}".format(os.getcwd())) else: filename = "/".join([output_dir, filename]) with open(filename, writemod) as downloaded: try: downloaded.write(contents) except TypeError: with open(filename, "wb") as downloaded: downloaded.write(contents) if not os.path.exists(filename): raise Exception("Could not write to {}".format(filename)) return filename
def __init__(self, test_env_path): super(JenkinsConfigurator, self).__init__() self.file_path = test_env_path if not os.path.exists(self.file_path): raise Exception("The test environment file {} doesn't exist".format(self.file_path)) cfgparser = ConfigParser.ConfigParser() cfgparser.read([self.file_path]) get = partial(cfgparser.get, "test_environment") self.dict_args = dict([(k.lower(), get(k)) for k in self.fields if get(k) is not None]) dict_keys = {"distro": self._make_distro()} if self.dict_args["rhelx"] == "6": dict_keys["project_id"] = "RHEL6" elif self.dict_args["rhelx"] == "7": dict_keys["project_id"] = "RedHatEnterpriseLinux7" else: log.error("Unknown project ID") dict_keys["result_path"] = self.dict_args["build_url"] dict_keys["testrun_suffix"] = self.dict_args["compose_id"] self.jenkins_record = JenkinsRecord(**dict_keys)
def kickstart(yaml_path=None, args=None): """ Kicks everything off by creating the configuration function pipeline :return: """ # Create the CLIConfigurator first, because it may override defaults (eg, it can override the # default location of pylarion_path or exporter_config, which are needed by PylarionConfigurator # and YAMLConfigurator) cli_cfg = CLIConfigurator() start_map = pyr.m() init_map = cli_cfg(start_map) pyl_path = init_map.get("pylarion_path") yaml_path = init_map.get("exporter_config") env_path = init_map.get("environment_file") pyl_cfg = PylarionConfigurator(path=pyl_path) env_cfg = OSEnvironmentConfigurator() yml_cfg = YAMLConfigurator(cfg_path=yaml_path) jnk_cfg = None if env_path: jnk_cfg = JenkinsConfigurator(env_path) cli_cfg = CLIConfigurator(args=args) if env_path: pipeline = compose(cli_cfg, jnk_cfg, yml_cfg, env_cfg, pyl_cfg) else: pipeline = compose(cli_cfg, yml_cfg, env_cfg, pyl_cfg) end_map = pipeline(start_map) log.log(DEFAULT_LOG_LEVEL, "================ end_map ===================") dprint(end_map) try: final = ConfigRecord(**end_map) except pyr._checked_types.InvariantException as ex: print ex if ex.missing_fields: log.error("Following fields not configured: " + str(ex.missing_fields)) if False and ex.invariant_errors: log.error("Invariants broken: " + str(ex.invariant_errors)) log.error("Please correct the above and run again") sys.exit(1) log.log(logging.INFO, "================= final ====================") dprint(final, log_lvl=logging.INFO) log.log(logging.INFO, "============================================\n") result = {"pyl_cfg": pyl_cfg, "env_cfg": env_cfg, "yml_cfg": yml_cfg, "cli_cfg": cli_cfg, "config": final} return result
def status(self, val): log.error("Can not set self.status. Value of {} being ignored".format(val))
def original_map(self, omap): if self._original_map is None: self._original_map = omap else: log.error(u'Can not set original-map')
def create_test_run(self, template_id, test_run_base=None, runner=None): """ Creates a new Polarion TestRun :param template_id: id of the template to use for TestRun :param test_run_base: a str to look up most recent TestRuns (eg "Jenkins Run" if the full name of TestRuns is "Jenkins Run 200" :param runner: str of the user id (eg stoner, not "Sean Toner") :return: None """ from pylarion.test_run import TestRun runner = self.get_runner(runner) tr_temp = self.get_template(template_id) log.info(tr_temp.plannedin) for s, testngs in self.tests.items(): if not testngs: continue if test_run_base is None: base_name = self.transformer.generate_base_testrun_id(s) else: base_name = test_run_base # Find our latest run. If it doesn't exist, we'll generate one tr = get_latest_test_run(base_name) if tr: new_id = make_test_run_id_from_latest(tr) else: base_name = remove_run(base_name) new_id = base_name + " Run 1" log.info("Creating new Test Run ID: {}".format(new_id)) plannedin = self.transformer.config.testrun_plannedin assignee = self.transformer.config.testrun_assignee retries = 3 while retries > 0: retries -= 1 if not plannedin: if hasattr(tr_temp, "plannedin") and tr_temp.plannedin: plannedin = tr_temp.plannedin else: raise PlannedinException("No plannedin value in template or from config") if not assignee: if hasattr(tr_temp, "assignee") and tr_temp.assignee: assignee = tr_temp.assignee else: raise AssigneeException("No assignee value in template or from config") try: test_run = TestRun.create(self.project, new_id, template_id, plannedin=plannedin, assignee=assignee) break except PlannedinException as pex: log.error(pex.message) raise pex except AssigneeException as aex: log.error(aex.message) raise aex except Exception as ex: log.warning("Retrying {} more times".format(retries)) else: raise Exception("Could not create a new TestRun") test_run.status = "inprogress" test_run.variant = [self.transformer.config.distro.variant.lower()] test_run.jenkinsjobs = self.transformer.config.testrun_jenkinsjobs test_run.notes = self.transformer.config.testrun_notes test_run.arch = [self.transformer.config.distro.arch.replace("_", "")] test_run.group_id = self.transformer.config.testrun_group_id for tc in testngs: tc.create_test_record(test_run, run_by=runner) test_run.status = "finished" test_run.update() log.info("Created test run for {}".format(new_id))
def status(self, val): log.error( "Can not set self.status. Value of {} being ignored".format(val))
def existing_requirements(self, val): log.error("Can not set existing_requirements after initialization")