def test_incorrect_template_params(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(
            os.path.join(self.fixtures_path,
                         "failure_formatting_component.yaml"))

        reg = registry.ModuleRegistry(config)
        reg.set_parser_data(yp.data)

        self.assertRaises(errors.JenkinsJobsException, yp.expandYaml, reg)
        self.assertIn("Problem formatting with args", self.logger.output)
예제 #2
0
    def test_incorrect_template_dimensions(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(
            os.path.join(self.fixtures_path,
                         "incorrect_template_dimensions.yaml"))

        reg = registry.ModuleRegistry(config)

        e = self.assertRaises(Exception, yp.expandYaml, reg)
        self.assertIn("'NoneType' object is not iterable", str(e))
        self.assertIn("- branch: current\n  current: null", self.logger.output)
예제 #3
0
    def test_invalid_view(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(os.path.join(self.fixtures_path, "invalid_view.yaml"))

        reg = registry.ModuleRegistry(config)
        _, view_data = yp.expandYaml(reg)

        # Generate the XML tree
        xml_generator = xml_config.XmlViewGenerator(reg)
        e = self.assertRaises(errors.JenkinsJobsException,
                              xml_generator.generateXML, view_data)
        self.assertIn("Unrecognized view type:", str(e))
예제 #4
0
    def test_yaml_snippet(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(
            os.path.join(self.fixtures_path,
                         "failure_formatting_{}.yaml".format(self.name)))

        reg = registry.ModuleRegistry(config)

        self.assertRaises(Exception, yp.expandYaml, reg)
        self.assertIn("Failure formatting {}".format(self.name),
                      self.logger.output)
        self.assertIn("Problem formatting with args", self.logger.output)
예제 #5
0
    def test_incorrect_template_params(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(
            os.path.join(self.fixtures_path,
                         "failure_formatting_component.yaml"))

        reg = registry.ModuleRegistry(config)
        reg.set_parser_data(yp.data)
        job_data_list, view_data_list = yp.expandYaml(reg)

        xml_generator = xml_config.XmlJobGenerator(reg)
        self.assertRaises(Exception, xml_generator.generateXML, job_data_list)
        self.assertIn("Failure formatting component", self.logger.output)
        self.assertIn("Problem formatting with args", self.logger.output)
예제 #6
0
    def get_jobs(self, jobs_glob=None, fn=None):
        if fn:
            r = registry.ModuleRegistry(self.jjb_config, self.jenkins.plugins_list)
            p = parser.YamlParser(self.jjb_config)
            p.load_files(fn)
            p.expandYaml(r, jobs_glob)
            jobs = [j["name"] for j in p.jobs]
        else:
            jobs = [
                j["name"]
                for j in self.jenkins.get_jobs()
                if not jobs_glob or parser.matches(j["name"], jobs_glob)
            ]

        jobs = sorted(jobs)
        for duplicate in list_duplicates(jobs):
            logging.warning("Found duplicate job name '%s', likely bug.", duplicate)

        logging.debug("Builder.get_jobs: returning %r", jobs)

        return jobs
예제 #7
0
    def _generate_jobs(self, config):
        module_path = config.arguments['module_path'].split(os.pathsep)

        library_path = config.arguments['library_path']
        if library_path is not None:
            library_path = library_path.split(os.pathsep)

        logging.debug("Module path: {0}".format(module_path))
        logging.debug("Library path: {0}".format(library_path))

        loader = jenkins_manager.loader.PythonLoader(module_path, library_path)
        logging.debug("Jobs loaded: {0}".format(pprint.pformat(loader.jobs)))

        jjbconfig = jjb_config.JJBConfig(config.arguments['conf'])
        jjbconfig.do_magical_things()
        jjbconfig.builder['ignore_cache'] = (not config.arguments['use_cache'])

        bldr = builder.Builder(jjbconfig)
        module_registry = registry.ModuleRegistry(jjbconfig, bldr.plugins_list)
        xml_generator = xml_config.XmlJobGenerator(module_registry)

        xml_jobs = xml_generator.generateXML(loader.jobs)

        return xml_jobs, bldr