protect branch name validation from improperly formatted names
If we can't parse the name, indicate that as an error. The result for a name like '0.6.x' ends up being 4 separate errors, but we avoid crashing the validator. Change-Id: Idbdcfd544cdc1c599907898e733fbf6039a5c6fc Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
23a582da77
commit
ce7e5e85c5
@ -563,7 +563,13 @@ def validate_stable_branches(deliverable_info, series_name,
|
||||
if not d.startswith('_')
|
||||
))
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('stable branch name expected to be stable/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'stable':
|
||||
continue
|
||||
if not isinstance(branch['location'], six.string_types):
|
||||
@ -599,7 +605,13 @@ def validate_feature_branches(deliverable_info, workdir, mk_warning, mk_error):
|
||||
"Apply the rules for feature branches."
|
||||
branches = deliverable_info.get('branches', [])
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('feature branch name expected to be feature/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'feature':
|
||||
continue
|
||||
location = branch['location']
|
||||
@ -635,7 +647,13 @@ def validate_driverfixes_branches(deliverable_info, workdir, mk_warning, mk_erro
|
||||
))
|
||||
branches = deliverable_info.get('branches', [])
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('driverfixes branch name expected to be driverfixes/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'driverfixes':
|
||||
continue
|
||||
location = branch['location']
|
||||
|
@ -1139,6 +1139,29 @@ class TestValidateStableBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: ocata
|
||||
location: 1.5.0
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_stable_branches(
|
||||
deliverable_info,
|
||||
'ocata',
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_version_not_in_deliverable(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
@ -1315,6 +1338,31 @@ class TestValidateFeatureBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: abc
|
||||
location:
|
||||
openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_feature_branches(
|
||||
deliverable_info,
|
||||
self.tmpdir,
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
print(warnings, errors)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_location_no_such_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
@ -1446,6 +1494,31 @@ class TestValidateDriverfixesBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: austin
|
||||
location:
|
||||
openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_driverfixes_branches(
|
||||
deliverable_info,
|
||||
self.tmpdir,
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
print(warnings, errors)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_location_no_such_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
|
Loading…
x
Reference in New Issue
Block a user