Add TenantProjectConfig object
We were attaching tenant-specific metadata (include/exclude) to
Project objects which is incorrect since those objects may span
tenants.
Instead, create a new TenantProjectConfig class which holds such
metadata, and attach it to the Tenant class.
Change-Id: Id69f9ec3a5116460beef2f83e065f5a1021dc147
diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py
index f4ca96f..3ab3305 100644
--- a/tests/unit/test_model.py
+++ b/tests/unit/test_model.py
@@ -42,7 +42,8 @@
self.tenant = model.Tenant('tenant')
self.layout = model.Layout()
self.project = model.Project('project', self.source)
- self.tenant.addUntrustedProject(self.project)
+ self.tpc = model.TenantProjectConfig(self.project)
+ self.tenant.addUntrustedProject(self.tpc)
self.pipeline = model.Pipeline('gate', self.layout)
self.layout.addPipeline(self.pipeline)
self.queue = model.ChangeQueue(self.pipeline)
@@ -175,7 +176,8 @@
layout.addPipeline(pipeline)
queue = model.ChangeQueue(pipeline)
project = model.Project('project', self.source)
- tenant.addUntrustedProject(project)
+ tpc = model.TenantProjectConfig(project)
+ tenant.addUntrustedProject(tpc)
base = configloader.JobParser.fromYaml(tenant, layout, {
'_source_context': self.context,
@@ -442,7 +444,8 @@
def test_job_inheritance_job_tree(self):
tenant = model.Tenant('tenant')
layout = model.Layout()
- tenant.addUntrustedProject(self.project)
+ tpc = model.TenantProjectConfig(self.project)
+ tenant.addUntrustedProject(tpc)
pipeline = model.Pipeline('gate', layout)
layout.addPipeline(pipeline)
@@ -523,7 +526,8 @@
layout.addPipeline(pipeline)
queue = model.ChangeQueue(pipeline)
project = model.Project('project', self.source)
- tenant.addUntrustedProject(project)
+ tpc = model.TenantProjectConfig(project)
+ tenant.addUntrustedProject(tpc)
base = configloader.JobParser.fromYaml(tenant, layout, {
'_source_context': self.context,
@@ -604,7 +608,8 @@
self.layout.addJob(job)
project2 = model.Project('project2', self.source)
- self.tenant.addUntrustedProject(project2)
+ tpc2 = model.TenantProjectConfig(project2)
+ self.tenant.addUntrustedProject(tpc2)
context2 = model.SourceContext(project2, 'master',
'test', True)
@@ -805,7 +810,8 @@
connection=connection1)
source1_project1 = model.Project('project1', source1)
- tenant.addConfigProject(source1_project1)
+ source1_project1_tpc = model.TenantProjectConfig(source1_project1)
+ tenant.addConfigProject(source1_project1_tpc)
d = {'project1':
{'git1.example.com': source1_project1}}
self.assertEqual(d, tenant.projects)
@@ -815,7 +821,8 @@
tenant.getProject('git1.example.com/project1'))
source1_project2 = model.Project('project2', source1)
- tenant.addUntrustedProject(source1_project2)
+ tpc = model.TenantProjectConfig(source1_project2)
+ tenant.addUntrustedProject(tpc)
d = {'project1':
{'git1.example.com': source1_project1},
'project2':
@@ -832,7 +839,8 @@
connection=connection2)
source2_project1 = model.Project('project1', source2)
- tenant.addUntrustedProject(source2_project1)
+ tpc = model.TenantProjectConfig(source2_project1)
+ tenant.addUntrustedProject(tpc)
d = {'project1':
{'git1.example.com': source1_project1,
'git2.example.com': source2_project1},
@@ -851,7 +859,8 @@
tenant.getProject('git2.example.com/project1'))
source2_project2 = model.Project('project2', source2)
- tenant.addConfigProject(source2_project2)
+ tpc = model.TenantProjectConfig(source2_project2)
+ tenant.addConfigProject(tpc)
d = {'project1':
{'git1.example.com': source1_project1,
'git2.example.com': source2_project1},
@@ -877,7 +886,8 @@
tenant.getProject('git2.example.com/project2'))
source1_project2b = model.Project('subpath/project2', source1)
- tenant.addConfigProject(source1_project2b)
+ tpc = model.TenantProjectConfig(source1_project2b)
+ tenant.addConfigProject(tpc)
d = {'project1':
{'git1.example.com': source1_project1,
'git2.example.com': source2_project1},
@@ -898,7 +908,8 @@
tenant.getProject('git1.example.com/subpath/project2'))
source2_project2b = model.Project('subpath/project2', source2)
- tenant.addConfigProject(source2_project2b)
+ tpc = model.TenantProjectConfig(source2_project2b)
+ tenant.addConfigProject(tpc)
d = {'project1':
{'git1.example.com': source1_project1,
'git2.example.com': source2_project1},
@@ -927,4 +938,4 @@
with testtools.ExpectedException(
Exception,
"Project project1 is already in project index"):
- tenant._addProject(source1_project1)
+ tenant._addProject(source1_project1_tpc)