Exemplo n.º 1
0
    def setUp(self):
        super(TestJob, self).setUp()
        self.connections = zuul.lib.connections.ConnectionRegistry()
        self.addCleanup(self.connections.stop)
        self.connection = Dummy(connection_name='dummy_connection')
        self.source = Dummy(canonical_hostname='git.example.com',
                            connection=self.connection)
        self.tenant = model.Tenant('tenant')
        self.tenant.default_ansible_version = AnsibleManager().default_version
        self.layout = model.Layout(self.tenant)
        self.project = model.Project('project', self.source)
        self.context = model.SourceContext(self.project, 'master', 'test',
                                           True)
        self.untrusted_context = model.SourceContext(self.project, 'master',
                                                     'test', False)
        self.tpc = model.TenantProjectConfig(self.project)
        self.tenant.addUntrustedProject(self.tpc)
        self.pipeline = model.Pipeline('gate', self.tenant)
        self.pipeline.source_context = self.context
        self.layout.addPipeline(self.pipeline)
        self.queue = model.ChangeQueue(self.pipeline)
        self.pcontext = configloader.ParseContext(self.connections,
                                                  None, self.tenant,
                                                  AnsibleManager())

        private_key_file = os.path.join(FIXTURE_DIR, 'private.pem')
        with open(private_key_file, "rb") as f:
            priv, pub = encryption.deserialize_rsa_keypair(f.read())
            self.project.private_secrets_key = priv
            self.project.public_secrets_key = pub
        m = yaml.Mark('name', 0, 0, 0, '', 0)
        self.start_mark = configloader.ZuulMark(m, m, '')
Exemplo n.º 2
0
    def test_inheritance_keeps_matchers(self):
        pipeline = model.Pipeline('gate', self.layout)
        self.layout.addPipeline(pipeline)
        queue = model.ChangeQueue(pipeline)

        base = self.pcontext.job_parser.fromYaml({
            '_source_context': self.context,
            '_start_mark': self.start_mark,
            'name': 'base',
            'parent': None,
            'timeout': 30,
        })
        self.layout.addJob(base)
        python27 = self.pcontext.job_parser.fromYaml({
            '_source_context':
            self.context,
            '_start_mark':
            self.start_mark,
            'name':
            'python27',
            'parent':
            'base',
            'timeout':
            40,
            'irrelevant-files': ['^ignored-file$'],
        })
        self.layout.addJob(python27)

        project_config = self.pcontext.project_parser.fromYaml([{
            '_source_context':
            self.context,
            '_start_mark':
            self.start_mark,
            'name':
            'project',
            'gate': {
                'jobs': [
                    'python27',
                ]
            }
        }])
        self.layout.addProjectConfig(project_config)

        change = model.Change(self.project)
        change.branch = 'master'
        change.files = ['/COMMIT_MSG', 'ignored-file']
        item = queue.enqueueChange(change)
        item.layout = self.layout

        self.assertTrue(base.changeMatches(change))
        self.assertFalse(python27.changeMatches(change))

        item.freezeJobGraph()
        self.assertEqual([], item.getJobs())
Exemplo n.º 3
0
    def test_job_inheritance_job_tree(self):
        pipeline = model.Pipeline('gate', self.layout)
        self.layout.addPipeline(pipeline)
        queue = model.ChangeQueue(pipeline)

        base = self.pcontext.job_parser.fromYaml({
            '_source_context': self.context,
            '_start_mark': self.start_mark,
            'name': 'base',
            'parent': None,
            'timeout': 30,
        })
        self.layout.addJob(base)
        python27 = self.pcontext.job_parser.fromYaml({
            '_source_context': self.context,
            '_start_mark': self.start_mark,
            'name': 'python27',
            'parent': 'base',
            'timeout': 40,
        })
        self.layout.addJob(python27)
        python27diablo = self.pcontext.job_parser.fromYaml({
            '_source_context':
            self.context,
            '_start_mark':
            self.start_mark,
            'name':
            'python27',
            'branches': ['stable/diablo'],
            'timeout':
            50,
        })
        self.layout.addJob(python27diablo)

        project_config = self.pcontext.project_parser.fromYaml([{
            '_source_context':
            self.context,
            '_start_mark':
            self.start_mark,
            'name':
            'project',
            'gate': {
                'jobs': [{
                    'python27': {
                        'timeout': 70,
                        'run': 'playbooks/python27.yaml'
                    }
                }]
            }
        }])
        self.layout.addProjectConfig(project_config)

        change = model.Change(self.project)
        change.branch = 'master'
        item = queue.enqueueChange(change)
        item.layout = self.layout

        self.assertTrue(base.changeMatches(change))
        self.assertTrue(python27.changeMatches(change))
        self.assertFalse(python27diablo.changeMatches(change))

        item.freezeJobGraph()
        self.assertEqual(len(item.getJobs()), 1)
        job = item.getJobs()[0]
        self.assertEqual(job.name, 'python27')
        self.assertEqual(job.timeout, 70)

        change.branch = 'stable/diablo'
        item = queue.enqueueChange(change)
        item.layout = self.layout

        self.assertTrue(base.changeMatches(change))
        self.assertTrue(python27.changeMatches(change))
        self.assertTrue(python27diablo.changeMatches(change))

        item.freezeJobGraph()
        self.assertEqual(len(item.getJobs()), 1)
        job = item.getJobs()[0]
        self.assertEqual(job.name, 'python27')
        self.assertEqual(job.timeout, 70)