use deliverable model objects to validate feature branches

Change-Id: I2ba56e28d5849bdea033165be091cfc0340da1d6
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann
2018-02-21 18:40:45 -05:00
parent bb6c61a8c8
commit 11e7b283de
2 changed files with 57 additions and 34 deletions

View File

@@ -963,51 +963,51 @@ def validate_stable_branches(deliv, workdir, series_name, messages):
) )
def validate_feature_branches(deliverable_info, def validate_feature_branches(deliv, workdir, messages):
deliverable_name,
workdir,
messages):
"Apply the rules for feature branches." "Apply the rules for feature branches."
header('Validate Feature Branches') header('Validate Feature Branches')
branches = deliverable_info.get('branches', [])
d_type = _guess_deliverable_type(deliverable_name, deliverable_info) if deliv.type == 'tempest-plugin' and deliv.branches:
if d_type == 'tempest-plugin' and branches:
messages.error('Tempest plugins do not support branching.') messages.error('Tempest plugins do not support branching.')
return return
for branch in branches: for branch in deliv.branches:
try: try:
prefix, series = branch['name'].split('/') prefix, series = branch.name.split('/')
except ValueError: except ValueError:
messages.error( messages.error(
('feature branch name expected to be feature/name ' ('feature branch name expected to be feature/name '
'but got %s') % (branch['name'],)) 'but got %s') % (branch.name,))
continue continue
if prefix != 'feature': if prefix != 'feature':
LOG.debug('{} is not a feature branch, skipping'.format(
branch.name))
continue continue
location = branch['location']
location = branch.location
if not isinstance(location, dict): if not isinstance(location, dict):
messages.error( messages.error(
('branch location for %s is ' ('branch location for %s is '
'expected to be a mapping but got a %s' % ( '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. # The other rules aren't going to be testable, so skip them.
continue continue
for repo, loc in sorted(location.items()): for repo, loc in sorted(location.items()):
if not is_a_hash(loc): if not is_a_hash(loc):
messages.error( messages.error(
('feature branches should be created from commits by SHA ' ('feature branches should be created from commits by SHA '
'but location %s for branch %s of %s does not look ' 'but location %s for branch %s of %s does not look '
'like a SHA' % ( 'like a SHA' % (
(loc, repo, branch['name']))) (loc, repo, branch.name)))
) )
if not gitutils.commit_exists(workdir, repo, loc): if not gitutils.commit_exists(workdir, repo, loc):
messages.error( messages.error(
('feature branches should be created from merged commits ' ('feature branches should be created from merged commits '
'but location %s for branch %s of %s does not exist' % ( 'but location %s for branch %s of %s does not exist' % (
(loc, repo, branch['name']))) (loc, repo, branch.name)))
) )
@@ -1336,8 +1336,7 @@ def main():
messages, messages,
) )
validate_feature_branches( validate_feature_branches(
deliv._data, deliv,
deliv.name,
workdir, workdir,
messages, messages,
) )

View File

@@ -1851,10 +1851,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
- name: feature/abc - name: feature/abc
location: 0.0.3 location: 0.0.3
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )
@@ -1874,10 +1878,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
location: location:
openstack/release-test: 0.0.3 openstack/release-test: 0.0.3
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )
@@ -1897,10 +1905,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
location: location:
openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660 openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )
@@ -1920,10 +1932,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
location: location:
openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660 openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )
@@ -1943,10 +1959,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
location: location:
openstack/release-test: de2885f544637e6ee6139df7dc7bf937925804dd openstack/release-test: de2885f544637e6ee6139df7dc7bf937925804dd
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )
@@ -1967,10 +1987,14 @@ class TestValidateFeatureBranches(base.BaseTestCase):
location: location:
openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660 openstack/release-test: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660
''') ''')
deliverable_info = yamlutils.loads(deliverable_data) deliv = deliverable.Deliverable(
team='team',
series='ocata',
name='release-test',
data=yamlutils.loads(deliverable_data),
)
validate.validate_feature_branches( validate.validate_feature_branches(
deliverable_info, deliv,
'name',
self.tmpdir, self.tmpdir,
self.msg, self.msg,
) )