summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-01-02 15:23:14 -0800
committerJames E. Blair <jeblair@redhat.com>2019-01-04 14:01:23 -0800
commitb7c68c2f76a6d3bf90718407ba16cc06c91708e8 (patch)
tree57c8dfde2c05179e0459abe23623adb309765170
parent7d3ad9a7aa0f1bebf54ece9ec390948e8e16b3c2 (diff)
Combine artifact URLs with log_url if relative
The plan for the idea of a "promote" pipeline is to fetch previously uploaded artifacts from the build log server and move them to the final publication location. However, jobs which store data (such as documentation builds, tarballs, or container images) on the log server should not need to know the configuration of the log server in order to return the artifact URL to zuul. To support this, if the job returns a relative URL for an artifact, assume it is relative to the log URL for the build and combine the two when storing the artifact info. Change-Id: I4bce2401c9e59fd469e3b3da2973514c07faecf2
Notes
Notes (review): Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: Clark Boylan <cboylan@sapwetik.org> Workflow+1: Clark Boylan <cboylan@sapwetik.org> Code-Review+1: Andreas Jaeger <jaegerandi@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 05 Jan 2019 07:17:27 +0000 Reviewed-on: https://review.openstack.org/628068 Project: openstack-infra/zuul Branch: refs/heads/master
-rw-r--r--doc/source/user/jobs.rst5
-rw-r--r--tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml4
-rwxr-xr-xtests/unit/test_web.py4
-rw-r--r--zuul/driver/sql/sqlreporter.py25
4 files changed, 34 insertions, 4 deletions
diff --git a/doc/source/user/jobs.rst b/doc/source/user/jobs.rst
index af947dd..1af0bce 100644
--- a/doc/source/user/jobs.rst
+++ b/doc/source/user/jobs.rst
@@ -755,7 +755,10 @@ under the **zuul.artifacts** dictionary. For example:
755 - name: tarball 755 - name: tarball
756 url: http://example.com/path/to/package.tar.gz 756 url: http://example.com/path/to/package.tar.gz
757 - name: docs 757 - name: docs
758 url: http://example.com/path/to/docs 758 url: build/docs/
759
760If the value of **url** is a relative URL, it will be combined with
761the **zuul.log_url** value if set to create an absolute URL.
759 762
760Skipping child jobs 763Skipping child jobs
761~~~~~~~~~~~~~~~~~~~ 764~~~~~~~~~~~~~~~~~~~
diff --git a/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml b/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml
index 7f2d48e..2dce536 100644
--- a/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml
+++ b/tests/fixtures/config/sql-driver/git/common-config/playbooks/project-test1.yaml
@@ -4,8 +4,12 @@
4 zuul_return: 4 zuul_return:
5 data: 5 data:
6 zuul: 6 zuul:
7 log_url: http://logs.example.com/build
8 foo: bar
7 artifacts: 9 artifacts:
8 - name: tarball 10 - name: tarball
9 url: http://example.com/tarball 11 url: http://example.com/tarball
10 - name: docs 12 - name: docs
11 url: http://example.com/docs 13 url: http://example.com/docs
14 - name: relative
15 url: relative/docs
diff --git a/tests/unit/test_web.py b/tests/unit/test_web.py
index 716f2f9..632a0a2 100755
--- a/tests/unit/test_web.py
+++ b/tests/unit/test_web.py
@@ -701,10 +701,12 @@ class TestArtifacts(ZuulDBTestCase, BaseTestWeb, AnsibleZuulTestCase):
701 "project=org/project&" 701 "project=org/project&"
702 "job_name=project-test1").json() 702 "job_name=project-test1").json()
703 self.assertEqual(len(build_query), 1) 703 self.assertEqual(len(build_query), 1)
704 self.assertEqual(len(build_query[0]['artifacts']), 2) 704 self.assertEqual(len(build_query[0]['artifacts']), 3)
705 self.assertEqual(build_query[0]['artifacts'], [ 705 self.assertEqual(build_query[0]['artifacts'], [
706 {'url': 'http://example.com/tarball', 706 {'url': 'http://example.com/tarball',
707 'name': 'tarball'}, 707 'name': 'tarball'},
708 {'url': 'http://example.com/docs', 708 {'url': 'http://example.com/docs',
709 'name': 'docs'}, 709 'name': 'docs'},
710 {'url': 'http://logs.example.com/build/relative/docs',
711 'name': 'relative'},
710 ]) 712 ])
diff --git a/zuul/driver/sql/sqlreporter.py b/zuul/driver/sql/sqlreporter.py
index 2a7ae85..f545da0 100644
--- a/zuul/driver/sql/sqlreporter.py
+++ b/zuul/driver/sql/sqlreporter.py
@@ -16,6 +16,7 @@ import datetime
16import logging 16import logging
17import time 17import time
18import voluptuous as v 18import voluptuous as v
19import urllib.parse
19 20
20from zuul.reporter import BaseReporter 21from zuul.reporter import BaseReporter
21 22
@@ -32,7 +33,9 @@ class SQLReporter(BaseReporter):
32 } 33 }
33 zuul_data = { 34 zuul_data = {
34 'zuul': { 35 'zuul': {
35 'artifacts': [artifact] 36 'log_url': str,
37 'artifacts': [artifact],
38 v.Extra: object,
36 } 39 }
37 } 40 }
38 artifact_schema = v.Schema(zuul_data) 41 artifact_schema = v.Schema(zuul_data)
@@ -103,11 +106,29 @@ class SQLReporter(BaseReporter):
103 if self.validateArtifactSchema(build.result_data): 106 if self.validateArtifactSchema(build.result_data):
104 artifacts = build.result_data.get('zuul', {}).get( 107 artifacts = build.result_data.get('zuul', {}).get(
105 'artifacts', []) 108 'artifacts', [])
109 default_url = build.result_data.get('zuul', {}).get(
110 'log_url')
111 if default_url:
112 if default_url[-1] != '/':
113 default_url += '/'
106 for artifact in artifacts: 114 for artifact in artifacts:
115 url = artifact['url']
116 if default_url:
117 # If the artifact url is relative, it will
118 # be combined with the log_url; if it is
119 # absolute, it will replace it.
120 try:
121 url = urllib.parse.urljoin(default_url, url)
122 except Exception:
123 self.log.debug("Error parsing URL:",
124 exc_info=1)
107 db_build.createArtifact( 125 db_build.createArtifact(
108 name=artifact['name'], 126 name=artifact['name'],
109 url=artifact['url'], 127 url=url,
110 ) 128 )
129 else:
130 self.log.debug("Result data did not pass artifact schema "
131 "validation: %s", build.result_data)
111 132
112 133
113def getSchema(): 134def getSchema():