SQLReporter: Log error of artifact name too long
Instead of leaving the build report hanging when an artifact has a longer name than expected, log the error and truncate the artifact name instead of propagating the error out of the reporter. Change-Id: Ie825891004bb727aaf41137ccfaf33751708ed76
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
data:
|
||||
zuul:
|
||||
log_url: "http://logs.example.com/looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"
|
||||
artifacts:
|
||||
- name: tarball_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_name
|
||||
url: http://example.com/path/to/package.tar.gz
|
||||
metadata:
|
||||
version: 3.0
|
||||
- name: debug message
|
||||
ansible.builtin.debug:
|
||||
msg: debug
|
||||
msg: debug
|
||||
|
||||
@@ -22,7 +22,10 @@ import types
|
||||
import sqlalchemy as sa
|
||||
|
||||
import zuul
|
||||
from zuul.driver.sql.sqlreporter import DATA_LENGTH_ERROR
|
||||
from zuul.driver.sql.sqlreporter import (
|
||||
DATA_LENGTH_ERROR,
|
||||
SQL_MAX_STRING_LENGTH
|
||||
)
|
||||
from zuul.lib import yamlutil
|
||||
from tests.base import (
|
||||
AnsibleZuulTestCase,
|
||||
@@ -475,6 +478,7 @@ class TestSQLReporterLongValues(AnsibleZuulTestCase):
|
||||
|
||||
def check_results():
|
||||
looong_log = "http://logs.example.com/l" + ("o" * 271) + "ng"
|
||||
looong_artifact_name = "tarball_l" + ("o" * 239) + "ong_name"
|
||||
# Grab the sa tables
|
||||
connection = self.scheds.first.connections.getSqlConnection()
|
||||
with connection.getSession() as db:
|
||||
@@ -489,6 +493,18 @@ class TestSQLReporterLongValues(AnsibleZuulTestCase):
|
||||
self.assertEqual(
|
||||
None,
|
||||
build.log_url)
|
||||
# Check if the artifact name was correctly truncated
|
||||
self.assertEqual(
|
||||
(looong_artifact_name[:SQL_MAX_STRING_LENGTH - 15]
|
||||
+ '... (truncated)'),
|
||||
build.artifacts[0].name)
|
||||
# Also check if the error was recorded with the
|
||||
# original artifact name
|
||||
self.assertTrue(
|
||||
DATA_LENGTH_ERROR % ("artifact name",
|
||||
looong_artifact_name) in
|
||||
build.error_detail,
|
||||
build.error_detail)
|
||||
return
|
||||
jobs.append(build.job_name)
|
||||
raise Exception(
|
||||
|
||||
@@ -217,6 +217,16 @@ class SQLReporter(BaseReporter):
|
||||
if 'metadata' in artifact:
|
||||
artifact['metadata'] = json.dumps(
|
||||
artifact['metadata'])
|
||||
if artifact['name'] is not None:
|
||||
if len(artifact['name']) > SQL_MAX_STRING_LENGTH:
|
||||
db_build.error_detail = (db_build.error_detail or "") + (
|
||||
DATA_LENGTH_ERROR % ("artifact name", artifact['name'])
|
||||
)
|
||||
|
||||
artifact['name'] = (
|
||||
artifact['name'][:SQL_MAX_STRING_LENGTH - 15] +
|
||||
'... (truncated)'
|
||||
)
|
||||
db_build.createArtifact(**artifact)
|
||||
|
||||
for event in build.events:
|
||||
|
||||
Reference in New Issue
Block a user