Esempio n. 1
0
 def _create_job_config(
     self,
     max_executors=_FAKE_MAX_EXECUTORS,
     max_executors_per_slave=_FAKE_MAX_EXECUTORS_PER_SLAVE,
 ):
     atomizer = Atomizer([{'FAKE': 'fake atomizer command'}])
     return JobConfig('', '', '', '', atomizer, max_executors, max_executors_per_slave)
Esempio n. 2
0
    def _construct_job_config(self, job_name, job_values):
        """
        Produce a JobConfig object given a dictionary of values parsed from a yaml config file.
        :param job_name: The name of the job
        :type job_name: str
        :param job_values: The dict of config sections for this job as parsed from the yaml file
        :type job_values: dict
        :return: A JobConfig object wrapping the normalized data for the specified job
        :rtype: JobConfig
        """
        # Each value should be transformed from a list of commands to a single command string.
        setup_build = self._shell_command_list_to_single_command(
            job_values.get(SETUP_BUILD))
        teardown_build = self._shell_command_list_to_single_command(
            job_values.get(TEARDOWN_BUILD))
        command = self._shell_command_list_to_single_command(
            job_values[COMMANDS])

        atomizer = Atomizer(job_values[ATOMIZERS])
        max_executors = job_values.get(MAX_EXECUTORS,
                                       self.DEFAULT_MAX_EXECUTORS)
        max_executors_per_slave = job_values.get(MAX_EXECUTORS_PER_SLAVE,
                                                 self.DEFAULT_MAX_EXECUTORS)

        return JobConfig(job_name, setup_build, teardown_build, command,
                         atomizer, max_executors, max_executors_per_slave)
    def test_teardown_build_runs_teardown(self):
        job_config = JobConfig('name', 'setup', 'teardown', 'command', 'atomizer', 10, 10)
        project_type = ProjectType()
        project_type.job_config = MagicMock(return_value=job_config)
        project_type.execute_command_in_project = MagicMock(return_value=('', 0))

        project_type.teardown_build()

        project_type.execute_command_in_project.assert_called_with('teardown', timeout=None)
Esempio n. 4
0
    def test_construct_from_dict_for_valid_conf_with_only_required_fields(self):
        config_dict = {
            'commands': ['shell command 1', 'shell command 2;'],
            'atomizers': [{'TESTPATH': 'atomizer command'}],
        }
        job_config = JobConfig.construct_from_dict('some_job_name', config_dict)

        self.assertEquals(job_config.command, 'shell command 1 && shell command 2')
        self.assertEquals(job_config.name, 'some_job_name')
Esempio n. 5
0
    def test_construct_from_dict_for_valid_conf_with_only_required_fields(
            self):
        config_dict = {
            'commands': ['shell command 1', 'shell command 2;'],
            'atomizers': [{
                'TESTPATH': 'atomizer command'
            }],
        }
        job_config = JobConfig.construct_from_dict('some_job_name',
                                                   config_dict)

        self.assertEquals(job_config.command,
                          'shell command 1 && shell command 2')
        self.assertEquals(job_config.name, 'some_job_name')
Esempio n. 6
0
    def job_config(self):
        """
        Return the job config found in this project_type and matching any job_name parameter passed in
        :rtype: JobConfig
        """
        if not self._job_config:
            # If the config was specified in the POST request, then there is no need to parse clusterrunner.yaml
            if self._config is not None:
                self._job_config = JobConfig.construct_from_dict(self._job_name, self._config)
                return self._job_config

            # Get job configuration from clusterrunner.yaml in repo.
            config = ClusterRunnerConfig(self._get_clusterrunner_config_file_contents())
            self._job_config = config.get_job_config(self._job_name)

        return self._job_config
Esempio n. 7
0
    def test_construct_from_dict_for_valid_conf_with_all_fields(self):
        config_dict = {
            'commands': ['shell command 1', 'shell command 2;'],
            'atomizers': [{'TESTPATH': 'atomizer command'}],
            'setup_build': ['setup command 1;', 'setup command 2;'],
            'teardown_build': ['teardown command 1;', 'teardown command 2;'],
            'max_executors': 100,
            'max_executors_per_slave': 2,
        }
        job_config = JobConfig.construct_from_dict('some_job_name', config_dict)

        self.assertEquals(job_config.command, 'shell command 1 && shell command 2')
        self.assertEquals(job_config.name, 'some_job_name')
        self.assertEquals(job_config.setup_build, 'setup command 1 && setup command 2')
        self.assertEquals(job_config.teardown_build, 'teardown command 1 && teardown command 2')
        self.assertEquals(job_config.max_executors, 100)
        self.assertEquals(job_config.max_executors_per_slave, 2)
Esempio n. 8
0
    def _parse_raw_config(self):
        """
        Validate the parsed yaml structure. This method raises on validation errors.

        If validation is successful, add the job configs to this class instance.

        :param config: The parsed yaml data
        :type config: dict
        """
        config = yaml.safe_load(self._raw_yaml_contents)

        if not isinstance(config, dict):
            raise ConfigParseError('The yaml config file could not be parsed to a dictionary')

        self._job_configs = {}

        for job_name, job_config_sections in config.items():
            self._job_configs[job_name] = JobConfig.construct_from_dict(job_name, job_config_sections)

        if len(self._job_configs) == 0:
            raise ConfigParseError('No jobs found in the config.')
Esempio n. 9
0
    def test_construct_from_dict_for_valid_conf_with_all_fields(self):
        config_dict = {
            'commands': ['shell command 1', 'shell command 2;'],
            'atomizers': [{
                'TESTPATH': 'atomizer command'
            }],
            'setup_build': ['setup command 1;', 'setup command 2;'],
            'teardown_build': ['teardown command 1;', 'teardown command 2;'],
            'max_executors': 100,
            'max_executors_per_slave': 2,
        }
        job_config = JobConfig.construct_from_dict('some_job_name',
                                                   config_dict)

        self.assertEquals(job_config.command,
                          'shell command 1 && shell command 2')
        self.assertEquals(job_config.name, 'some_job_name')
        self.assertEquals(job_config.setup_build,
                          'setup command 1 && setup command 2')
        self.assertEquals(job_config.teardown_build,
                          'teardown command 1 && teardown command 2')
        self.assertEquals(job_config.max_executors, 100)
        self.assertEquals(job_config.max_executors_per_slave, 2)
Esempio n. 10
0
 def test_construct_from_dict_raise_error_without_requried_fields(
         self, config_dict):
     with self.assertRaises(ConfigValidationError):
         JobConfig.construct_from_dict('some_job_name', config_dict)
Esempio n. 11
0
 def test_construct_from_dict_raise_error_without_requried_fields(self, config_dict):
     with self.assertRaises(ConfigValidationError):
         JobConfig.construct_from_dict('some_job_name', config_dict)
Esempio n. 12
0
 def _create_job_config(self) -> JobConfig:
     max_executors = max_executors_per_slave = maxsize
     atomizer = Atomizer([{'FAKE': 'fake atomizer command'}])
     return JobConfig('', '', '', '', atomizer, max_executors,
                      max_executors_per_slave)