Don't fail tenant validation for deprecations

Warnings are also added to the list of loading errors. For the tenant
validation we need to distinguish between errors and deprecation
warnings and only fail the validation when there are errors.

Alternatively we could also introduce a flag for the tenant validation
to thread deprecation warnings as errors.

Change-Id: I9c8957520c37157a295627848d30e52a36c8da0a
Co-Authored-By: James E. Blair <jim@acmegating.com>
This commit is contained in:
Simon Westphahl 2023-07-27 15:03:18 +02:00 committed by James E. Blair
parent 95814f7734
commit 39e5eb9e2c
3 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,21 @@
- pipeline:
name: gate
manager: dependent
success-message: Build succeeded (gate).
trigger:
gerrit:
- event: comment-added
require-approval:
- username: jenkins
Verified: 1
success:
gerrit:
Verified: 2
submit: true
failure:
gerrit:
Verified: -2
start:
gerrit:
Verified: 0
precedence: high

View File

@ -4811,6 +4811,16 @@ class TestBrokenConfig(ZuulTestCase):
"Zuul encountered a syntax error",
str(tenant.layout.loading_errors[0].error))
@simple_layout('layouts/broken-warnings.yaml')
def test_broken_config_on_startup_warnings(self):
tenant = self.scheds.first.sched.abide.tenants.get('tenant-one')
self.assertEquals(
len(tenant.layout.loading_errors), 1,
"An error should have been stored")
self.assertIn(
"Zuul encountered a deprecated syntax",
str(tenant.layout.loading_errors[0].error))
def test_dynamic_ignore(self):
# Verify dynamic config behaviors inside a tenant broken config
tenant = self.scheds.first.sched.abide.tenants.get('tenant-broken')
@ -5173,6 +5183,23 @@ class TestValidateGood(ZuulTestCase):
pass
class TestValidateWarnings(ZuulTestCase):
# Test we don't fail when we only have configuration warnings
validate_tenants = ['tenant-one']
tenant_config_file = 'config/broken/main.yaml'
def setUp(self):
with self.assertLogs('zuul.ConfigLoader', level='DEBUG') as full_logs:
super().setUp()
self.assertRegexInList('Zuul encountered a deprecated syntax',
full_logs.output)
@simple_layout('layouts/broken-warnings.yaml')
def test_validate_warnings(self):
pass
class RoleTestCase(ZuulTestCase):
def _getRolesPaths(self, build, playbook):
path = os.path.join(self.jobdir_root, build.uuid,

View File

@ -77,6 +77,7 @@ from zuul.model import (
SupercedeEvent,
SystemAttributes,
STATE_FAILED,
SEVERITY_WARNING,
)
from zuul.version import get_version_string
from zuul.zk import ZooKeeperClient
@ -1424,7 +1425,10 @@ class Scheduler(threading.Thread):
loading_errors = []
for tenant in abide.tenants.values():
for error in tenant.layout.loading_errors:
loading_errors.append(repr(error))
if error.severity == SEVERITY_WARNING:
self.log.warning(repr(error))
else:
loading_errors.append(repr(error))
if loading_errors:
summary = '\n\n\n'.join(loading_errors)
raise configloader.ConfigurationSyntaxError(