summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-05 07:17:27 +0000
committerGerrit Code Review <review@openstack.org>2019-01-05 07:17:27 +0000
commit2a2dbc51dc837c83e4479317892813d93a3cc930 (patch)
treefc5327dd468d708ff6da4b61d96f5b35c92d20e9
parent2fd688352f5e220fda0dfc72b164144910670d95 (diff)
parentb7c68c2f76a6d3bf90718407ba16cc06c91708e8 (diff)
Merge "Combine artifact URLs with log_url if relative"
-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():