add validation for driverfixes branches

Change-Id: Ic03800b3bb5f090ea66d7ce773d6de4622b30584
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-11-28 14:22:47 -05:00
parent deb74660fd
commit bbc1e85f6b
2 changed files with 184 additions and 2 deletions

View File

@ -422,10 +422,55 @@ def validate_feature_branches(deliverable_info, workdir, mk_warning, mk_error):
)
def validate_driverfixes_branches(deliverable_info, workdir, mk_warning, mk_error):
"Apply the rules for driverfixes branches."
known_series = sorted(list(
d for d in os.listdir('deliverables')
if not d.startswith('_')
))
branches = deliverable_info.get('branches', [])
for branch in branches:
prefix, series = branch['name'].split('/')
if prefix != 'driverfixes':
continue
location = branch['location']
if series not in known_series:
mk_error(
('driverfixes branches must be named for known series '
'but %s was not found in %s' % (
branch['name'], known_series))
)
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(
('driverfixes 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(
('driverfixes 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
# 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
#
# FIXME(dhellmann): these two rules become more challenging to
# implement when we think about EOLed branches. I'm going to punt on
# that for now, and if it turns into an issue we can think about how
# to handle validation while still allowing branches to be deleted.
def main():
@ -529,6 +574,12 @@ def main():
mk_warning,
mk_error,
)
validate_driverfixes_branches(
deliverable_info,
workdir,
mk_warning,
mk_error,
)
if warnings:
print('\n\n%s warnings found' % len(warnings))

View File

@ -857,3 +857,134 @@ class TestValidateFeatureBranches(base.BaseTestCase):
print(warnings, errors)
self.assertEqual(0, len(warnings))
self.assertEqual(1, len(errors))
class TestValidateDriverfixesBranches(base.BaseTestCase):
def setUp(self):
super(TestValidateDriverfixesBranches, self).setUp()
self.tmpdir = self.useFixture(fixtures.TempDir()).path
def test_unknown_series(self):
deliverable_data = textwrap.dedent('''
releases:
- version: 1.5.0
projects:
- repo: openstack/automaton
hash: be2885f544637e6ee6139df7dc7bf937925804dd
branches:
- name: driverfixes/abc
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_not_a_dict(self):
deliverable_data = textwrap.dedent('''
releases:
- version: 1.5.0
projects:
- repo: openstack/automaton
hash: be2885f544637e6ee6139df7dc7bf937925804dd
branches:
- name: driverfixes/austin
location: 1.5.0
''')
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_not_a_sha(self):
deliverable_data = textwrap.dedent('''
releases:
- version: 1.5.0
projects:
- repo: openstack/automaton
hash: be2885f544637e6ee6139df7dc7bf937925804dd
branches:
- name: driverfixes/austin
location:
openstack/automaton: 1.5.0
''')
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_a_sha(self):
deliverable_data = textwrap.dedent('''
releases:
- version: 1.5.0
projects:
- repo: openstack/automaton
hash: be2885f544637e6ee6139df7dc7bf937925804dd
branches:
- name: driverfixes/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(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: driverfixes/austin
location:
openstack/automaton: de2885f544637e6ee6139df7dc7bf937925804dd
''')
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))