示例#1
0
 def test_put_job(self):
     job_config = JobConfig.from_json(_JOB_TEMPLATE % 100)
     self._repository.put_job(job_config)
     self.assertEqual(1, len(self._repository.configs))
     self.assertEqual(
         _JOB_TEMPLATE % 100,
         self._repository.configs['/workflow/some_workflow/job/some_job'])
示例#2
0
 def test_put_job(self):
     job_config = JobConfig.from_json(_JOB_TEMPLATE % 100)
     self._repository.put_job(job_config)
     self.assertEqual(1, len(self._repository.configs))
     self.assertEqual(
         _JOB_TEMPLATE % 100,
         self._repository.configs['/workflow/some_workflow/job/some_job'])
示例#3
0
    def get_job(self, workflow, job):
        """Retrieve config for a given job.

        Args:
            workflow: The workflow name where the job is defined.
            job: The name of the job whose config should be retrieved.
        Returns:
            The job config.
        """
        path = Path(workflow=workflow, job=job)
        job_json = self._get_config(path.get_job_path())
        return JobConfig.from_json(job_json)
示例#4
0
    def get_job(self, workflow, job):
        """Retrieve config for a given job.

        Args:
            workflow: The workflow name where the job is defined.
            job: The name of the job whose config should be retrieved.
        Returns:
            The job config.
        """
        path = Path(workflow=workflow, job=job)
        job_json = self._get_config(path.get_job_path())
        return JobConfig.from_json(job_json)
示例#5
0
 def test_format(self):
     job_json = "{%s, %s}" % (JobConfigTestCase._REQUIRED_JOB_JSON, JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     formatted_config = job_config.format()
     self.assertEqual(["*****@*****.**", "*****@*****.**"], formatted_config["emails"])
     self.assertEqual("some_job", formatted_config["job"])
     self.assertEqual(10, formatted_config["max_attempts"])
     self.assertEqual(30, formatted_config["retry_delay_sec"])
     self.assertEqual(["some_parent_job", "some_other_parent_job"], formatted_config["parents"])
     self.assertEqual(123, formatted_config["priority"])
     self.assertEqual("some_template", formatted_config["template"])
     self.assertEqual({"some_param": "some_value"}, formatted_config["template_params"])
     self.assertEqual("some_workflow", formatted_config["workflow"])
示例#6
0
 def test_from_json(self):
     job_json = "{%s, %s}" % (JobConfigTestCase._REQUIRED_JOB_JSON, JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     self.assertFalse(job_config.is_condition)
     self.assertEqual(["*****@*****.**", "*****@*****.**"], job_config.emails)
     self.assertEqual("some_job", job_config.job)
     self.assertEqual(10, job_config.max_attempts)
     self.assertEqual(30, job_config.retry_delay_sec)
     self.assertEqual(["some_parent_job", "some_other_parent_job"], job_config.parents)
     self.assertEqual(123, job_config.priority)
     self.assertEqual("some_template", job_config.template)
     template_params = {"some_param": "some_value"}
     self.assertEqual(template_params, job_config.template_params)
     self.assertEqual("some_workflow", job_config.workflow)
     self.assertEqual(10, job_config.warn_timeout_sec)
     self.assertEqual(20, job_config.abort_timeout_sec)
示例#7
0
 def test_format(self):
     job_json = '{%s, %s}' % (JobConfigTestCase._REQUIRED_JOB_JSON,
                              JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     formatted_config = job_config.format()
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      formatted_config['emails'])
     self.assertEqual('some_job', formatted_config['job'])
     self.assertEqual(10, formatted_config['max_attempts'])
     self.assertEqual(30, formatted_config['retry_delay_sec'])
     self.assertEqual(['some_parent_job', 'some_other_parent_job'],
                      formatted_config['parents'])
     self.assertEqual(123, formatted_config['priority'])
     self.assertEqual('some_template', formatted_config['template'])
     self.assertEqual({'some_param': 'some_value'},
                      formatted_config['template_params'])
     self.assertEqual('some_workflow', formatted_config['workflow'])
示例#8
0
 def test_format(self):
     job_json = '{{{0!s}, {1!s}}}'.format(JobConfigTestCase._REQUIRED_JOB_JSON,
                              JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     formatted_config = job_config.format()
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      formatted_config['emails'])
     self.assertEqual('some_job', formatted_config['job'])
     self.assertEqual(10, formatted_config['max_attempts'])
     self.assertEqual(30, formatted_config['retry_delay_sec'])
     self.assertEqual(['some_parent_job', 'some_other_parent_job'],
                      formatted_config['parents'])
     self.assertEqual(123, formatted_config['priority'])
     self.assertEqual('some_template', formatted_config['template'])
     self.assertEqual({'some_param': 'some_value'},
                      formatted_config['template_params'])
     self.assertEqual('some_workflow', formatted_config['workflow'])
示例#9
0
 def test_from_json(self):
     job_json = '{%s, %s}' % (JobConfigTestCase._REQUIRED_JOB_JSON,
                              JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     self.assertFalse(job_config.is_condition)
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      job_config.emails)
     self.assertEqual('some_job', job_config.job)
     self.assertEqual(10, job_config.max_attempts)
     self.assertEqual(30, job_config.retry_delay_sec)
     self.assertEqual(['some_parent_job', 'some_other_parent_job'],
                      job_config.parents)
     self.assertEqual(123, job_config.priority)
     self.assertEqual('some_template', job_config.template)
     template_params = {'some_param': 'some_value'}
     self.assertEqual(template_params, job_config.template_params)
     self.assertEqual('some_workflow', job_config.workflow)
     self.assertEqual(10, job_config.warn_timeout_sec)
     self.assertEqual(20, job_config.abort_timeout_sec)
示例#10
0
 def test_from_json(self):
     job_json = '{{{0!s}, {1!s}}}'.format(JobConfigTestCase._REQUIRED_JOB_JSON,
                              JobConfigTestCase._OPTIONAL_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     self.assertFalse(job_config.is_condition)
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      job_config.emails)
     self.assertEqual('some_job', job_config.job)
     self.assertEqual(10, job_config.max_attempts)
     self.assertEqual(30, job_config.retry_delay_sec)
     self.assertEqual(['some_parent_job', 'some_other_parent_job'],
                      job_config.parents)
     self.assertEqual(123, job_config.priority)
     self.assertEqual('some_template', job_config.template)
     template_params = {'some_param': 'some_value'}
     self.assertEqual(template_params, job_config.template_params)
     self.assertEqual('some_workflow', job_config.workflow)
     self.assertEqual(10, job_config.warn_timeout_sec)
     self.assertEqual(20, job_config.abort_timeout_sec)
示例#11
0
 def test_required_from_json(self):
     job_json = '{%s}' % JobConfigTestCase._REQUIRED_JOB_JSON
     job_config = JobConfig.from_json(job_json)
     self.assertEqual('some_workflow', job_config.workflow)
     self.assertIsNone(job_config.warn_timeout_sec)
     self.assertIsNone(job_config.abort_timeout_sec)
    def test_get_workflow_tokens(self, repository_mock):
        repository = mock.Mock()
        repository_mock.return_value = repository

        repository.get_job_names.return_value = ['some_job']

        job_config = JobConfig()
        job_config.workflow = 'some_workflow'
        job_config.job = 'some_job'
        job_config.is_condition = False
        job_config.template = ('tests.pinball.parser.'
                               'repository_config_parser_test.SomeJobTemplate')
        job_config.template_params = {'some_param': 'some_value'}
        job_config.parents = []
        job_config.emails = ['*****@*****.**',
                             '*****@*****.**']
        job_config.max_attempts = 10
        job_config.retry_delay_sec = 20
        job_config.priority = 100
        repository.get_job.return_value = job_config

        parser = RepositoryConfigParser()

        workflow_tokens = parser.get_workflow_tokens('some_workflow')

        self.assertEqual(2, len(workflow_tokens))

        # Verify the triggering event token.
        if Name.from_event_token_name(workflow_tokens[0].name).workflow:
            event_token = workflow_tokens[0]
        else:
            event_token = workflow_tokens[1]

        event_name = Name.from_event_token_name(event_token.name)
        self.assertEqual('some_workflow', event_name.workflow)
        self.assertEqual('some_job', event_name.job)
        self.assertEqual('__WORKFLOW_START__', event_name.input)

        event = pickle.loads(event_token.data)
        self.assertEqual('repository_config_parser', event.creator)

        repository.get_job_names.assert_called_once_with('some_workflow')
        repository.get_job.assert_called_once_with('some_workflow', 'some_job')
示例#13
0
 def test_required_from_json(self):
     job_json = '{{{0!s}}}'.format(JobConfigTestCase._REQUIRED_JOB_JSON)
     job_config = JobConfig.from_json(job_json)
     self.assertEqual('some_workflow', job_config.workflow)
     self.assertIsNone(job_config.warn_timeout_sec)
     self.assertIsNone(job_config.abort_timeout_sec)
示例#14
0
 def test_delete_job(self):
     job_config = JobConfig.from_json(_JOB_TEMPLATE % 100)
     self._repository.put_job(job_config)
     self._repository.delete_job('some_workflow', 'some_job')
     self.assertEqual({}, self._repository.configs)
示例#15
0
 def test_delete_job(self):
     job_config = JobConfig.from_json(_JOB_TEMPLATE % 100)
     self._repository.put_job(job_config)
     self._repository.delete_job('some_workflow', 'some_job')
     self.assertEqual({}, self._repository.configs)
示例#16
0
    def test_get_workflow_tokens(self, repository_mock):
        repository = mock.Mock()
        repository_mock.return_value = repository

        repository.get_job_names.return_value = ['some_job']

        job_config = JobConfig()
        job_config.workflow = 'some_workflow'
        job_config.job = 'some_job'
        job_config.is_condition = False
        job_config.template = ('tests.pinball.parser.'
                               'repository_config_parser_test.SomeJobTemplate')
        job_config.template_params = {'some_param': 'some_value'}
        job_config.parents = []
        job_config.emails = [
            '*****@*****.**', '*****@*****.**'
        ]
        job_config.max_attempts = 10
        job_config.retry_delay_sec = 20
        job_config.priority = 100
        repository.get_job.return_value = job_config

        parser = RepositoryConfigParser()

        workflow_tokens = parser.get_workflow_tokens('some_workflow')

        self.assertEqual(2, len(workflow_tokens))

        # Verify the triggering event token.
        if Name.from_event_token_name(workflow_tokens[0].name).workflow:
            event_token = workflow_tokens[0]
        else:
            event_token = workflow_tokens[1]

        event_name = Name.from_event_token_name(event_token.name)
        self.assertEqual('some_workflow', event_name.workflow)
        self.assertEqual('some_job', event_name.job)
        self.assertEqual('__WORKFLOW_START__', event_name.input)

        event = pickle.loads(event_token.data)
        self.assertEqual('repository_config_parser', event.creator)

        repository.get_job_names.assert_called_once_with('some_workflow')
        repository.get_job.assert_called_once_with('some_workflow', 'some_job')
示例#17
0
 def test_required_from_json(self):
     job_json = "{%s}" % JobConfigTestCase._REQUIRED_JOB_JSON
     job_config = JobConfig.from_json(job_json)
     self.assertEqual("some_workflow", job_config.workflow)
     self.assertIsNone(job_config.warn_timeout_sec)
     self.assertIsNone(job_config.abort_timeout_sec)