From bf997c8b46a4be4809d59ff4095b0d2997263581 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 10 May 2017 09:58:40 +1000 Subject: [PATCH] Add tenant to url formatting. Expose the tenant name to the executor and url formatter so that we can store logs per tenant. Change-Id: Ifad1ba668ee5b86e6c6f5cb71eae53ad8d49f3ff Signed-off-by: Jamie Lennox --- tests/fixtures/layouts/reporting-github.yaml | 2 +- tests/unit/test_github_driver.py | 4 ++-- zuul/executor/client.py | 1 + zuul/model.py | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/layouts/reporting-github.yaml b/tests/fixtures/layouts/reporting-github.yaml index 8dd35b0223..43e71c7a72 100644 --- a/tests/fixtures/layouts/reporting-github.yaml +++ b/tests/fixtures/layouts/reporting-github.yaml @@ -29,7 +29,7 @@ github: comment: false status: 'success' - status-url: http://logs.example.com/{pipeline.name}/{change.project}/{change.number}/{change.patchset}/ + status-url: http://logs.example.com/{tenant.name}/{pipeline.name}/{change.project}/{change.number}/{change.patchset}/ failure: github: comment: false diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py index 6cc010ea0c..ab304b2a67 100644 --- a/tests/unit/test_github_driver.py +++ b/tests/unit/test_github_driver.py @@ -300,8 +300,8 @@ class TestGithubDriver(ZuulTestCase): self.assertEqual('tenant-one/reporting', report_status['context']) self.assertEqual('success', report_status['state']) self.assertEqual(2, len(A.comments)) - report_url = ('http://logs.example.com/reporting/%s/%s/%s/' % - (A.project, A.number, A.head_sha)) + report_url = ('http://logs.example.com/tenant-one/reporting/' + '%s/%s/%s/' % (A.project, A.number, A.head_sha)) self.assertEqual(report_url, report_status['url']) @simple_layout('layouts/merging-github.yaml', driver='github') diff --git a/zuul/executor/client.py b/zuul/executor/client.py index cf8d973a54..b7e5a4594d 100644 --- a/zuul/executor/client.py +++ b/zuul/executor/client.py @@ -196,6 +196,7 @@ class ExecutorClient(object): pipeline=pipeline.name, job=job.name, project=project, + tenant=tenant.name, tags=' '.join(sorted(job.tags))) if hasattr(item.change, 'branch'): diff --git a/zuul/model.py b/zuul/model.py index 0d923013a3..59f5531272 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -1588,11 +1588,13 @@ class QueueItem(object): # secrets, etc. safe_change = self.change.getSafeAttributes() safe_pipeline = self.pipeline.getSafeAttributes() + safe_tenant = self.pipeline.layout.tenant.getSafeAttributes() safe_job = job.getSafeAttributes() if job else {} safe_build = build.getSafeAttributes() if build else {} try: url = url_pattern.format(change=safe_change, pipeline=safe_pipeline, + tenant=safe_tenant, job=safe_job, build=safe_build) except KeyError as e: @@ -2432,6 +2434,9 @@ class Tenant(object): self.untrusted_projects.append(project) self._addProject(project) + def getSafeAttributes(self): + return Attributes(name=self.name) + class Abide(object): def __init__(self):