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, '')
def test_job_source_project(self): base_project = model.Project('base_project', self.source) base_context = model.SourceContext(base_project, 'master', 'test', True) tpc = model.TenantProjectConfig(base_project) self.tenant.addUntrustedProject(tpc) base = self.pcontext.job_parser.fromYaml({ '_source_context': base_context, '_start_mark': self.start_mark, 'parent': None, 'name': 'base', }) self.layout.addJob(base) other_project = model.Project('other_project', self.source) other_context = model.SourceContext(other_project, 'master', 'test', True) tpc = model.TenantProjectConfig(other_project) self.tenant.addUntrustedProject(tpc) base2 = self.pcontext.job_parser.fromYaml({ '_source_context': other_context, '_start_mark': self.start_mark, 'name': 'base', }) with testtools.ExpectedException( Exception, "Job base in other_project is not permitted " "to shadow job base in base_project"): self.layout.addJob(base2)