From d8018e0d0c1c410536417745e7d5b5a977263538 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 21 Feb 2018 18:47:54 -0500 Subject: [PATCH] use deliverable model objects to validate driverfixes branches Change-Id: I5c29ba1ed724e50f73d6ac673fc58300189d5c5d Signed-off-by: Doug Hellmann --- openstack_releases/cmds/validate.py | 41 ++++++------- openstack_releases/tests/test_validate.py | 70 ++++++++++++++++------- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 53975b8988..192cd332c4 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -1011,62 +1011,64 @@ def validate_feature_branches(deliv, workdir, messages): ) -def validate_driverfixes_branches(deliverable_info, - deliverable_name, - workdir, - messages): +def validate_driverfixes_branches(deliv, workdir, messages): "Apply the rules for driverfixes branches." header('Validate driverfixes Branches') + + if deliv.type == 'tempest-plugin' and deliv.branches: + messages.error('Tempest plugins do not support branching.') + return + known_series = sorted(list( d for d in os.listdir('deliverables') if not d.startswith('_') )) - branches = deliverable_info.get('branches', []) - d_type = _guess_deliverable_type(deliverable_name, deliverable_info) - if d_type == 'tempest-plugin' and branches: - messages.error('Tempest plugins do not support branching.') - return - - for branch in branches: + for branch in deliv.branches: try: - prefix, series = branch['name'].split('/') + prefix, series = branch.name.split('/') except ValueError: messages.error( ('driverfixes branch name expected to be driverfixes/name ' - 'but got %s') % (branch['name'],)) + 'but got %s') % (branch.name,)) continue + if prefix != 'driverfixes': + LOG.debug('{} is not a driverfixes branch, skipping'.format( + branch.name)) continue - location = branch['location'] + if series not in known_series: messages.error( ('driverfixes branches must be named for known series ' 'but %s was not found in %s' % ( - branch['name'], known_series)) + branch.name, known_series)) ) + + location = branch.location if not isinstance(location, dict): messages.error( ('branch location for %s is ' 'expected to be a mapping but got a %s' % ( - branch['name'], type(location))) + 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): messages.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']))) + (loc, repo, branch.name))) ) if not gitutils.commit_exists(workdir, repo, loc): messages.error( ('driverfixes branches should be created from merged ' 'commits but location %s for branch %s of %s does not ' 'exist' % ( - (loc, repo, branch['name']))) + (loc, repo, branch.name))) ) _require_gitreview(workdir, repo, messages) @@ -1341,8 +1343,7 @@ def main(): messages, ) validate_driverfixes_branches( - deliv._data, - deliv.name, + deliv, workdir, messages, ) diff --git a/openstack_releases/tests/test_validate.py b/openstack_releases/tests/test_validate.py index 03c26ca0a8..9788d38c57 100644 --- a/openstack_releases/tests/test_validate.py +++ b/openstack_releases/tests/test_validate.py @@ -2023,10 +2023,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2045,10 +2049,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): - name: driverfixes/austin location: 1.5.0 ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2068,10 +2076,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: 1.5.0 ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2091,10 +2103,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2114,10 +2130,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2137,10 +2157,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: de2885f544637e6ee6139df7dc7bf937925804dd ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, ) @@ -2161,10 +2185,14 @@ class TestValidateDriverfixesBranches(base.BaseTestCase): location: openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd ''') - deliverable_info = yamlutils.loads(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='ocata', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) validate.validate_driverfixes_branches( - deliverable_info, - 'name', + deliv, self.tmpdir, self.msg, )