Merge "add validation for feature branch names and locations"
This commit is contained in:
commit
546eb95902
openstack_releases
@ -389,8 +389,40 @@ def validate_stable_branches(deliverable_info, mk_warning, mk_error):
|
||||
branch['name'], known_series))
|
||||
)
|
||||
|
||||
|
||||
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('/')
|
||||
if prefix != 'feature':
|
||||
continue
|
||||
location = branch['location']
|
||||
if not isinstance(location, dict):
|
||||
mk_error(
|
||||
('branch location for %s is '
|
||||
'expected to be a mapping but got a %s' % (
|
||||
branch['name'], type(location)))
|
||||
)
|
||||
# The other rules aren't going to be testable, so skip them.
|
||||
continue
|
||||
for repo, loc in sorted(location.items()):
|
||||
if not is_a_hash(loc):
|
||||
mk_error(
|
||||
('feature branches should be created from commits by SHA '
|
||||
'but location %s for branch %s of %s does not look '
|
||||
'like a SHA' % (
|
||||
(loc, repo, branch['name'])))
|
||||
)
|
||||
if not gitutils.commit_exists(repo, loc):
|
||||
mk_error(
|
||||
('feature branches should be created from merged commits '
|
||||
'but location %s for branch %s of %s does not exist' % (
|
||||
(loc, repo, branch['name'])))
|
||||
)
|
||||
|
||||
|
||||
# if the branch already exists, the name is by definition valid
|
||||
# feature branches map between repo names and SHA values
|
||||
# driverfixes branches map between repo names and SHA or version number
|
||||
# if the branch exists, the data in the map must match reality
|
||||
# if the branch does not exist, the references in the map must exist
|
||||
@ -491,6 +523,12 @@ def main():
|
||||
mk_warning,
|
||||
mk_error,
|
||||
)
|
||||
validate_feature_branches(
|
||||
deliverable_info,
|
||||
workdir,
|
||||
mk_warning,
|
||||
mk_error,
|
||||
)
|
||||
|
||||
if warnings:
|
||||
print('\n\n%s warnings found' % len(warnings))
|
||||
|
@ -751,3 +751,109 @@ class TestValidateStableBranches(base.BaseTestCase):
|
||||
print(warnings, errors)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
|
||||
class TestValidateFeatureBranches(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestValidateFeatureBranches, self).setUp()
|
||||
self.tmpdir = self.useFixture(fixtures.TempDir()).path
|
||||
|
||||
def test_location_not_a_dict(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: feature/abc
|
||||
location: 1.5.0
|
||||
''')
|
||||
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_not_a_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: feature/abc
|
||||
location:
|
||||
openstack/automaton: 1.5.0
|
||||
''')
|
||||
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_a_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: feature/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(0, len(errors))
|
||||
|
||||
def test_location_no_such_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: feature/abc
|
||||
location:
|
||||
openstack/automaton: de2885f544637e6ee6139df7dc7bf937925804dd
|
||||
''')
|
||||
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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user