use deliverable model objects to validate branch creation points
Change-Id: I3b94db7ec6fb07baef0bf17d733e93f7ae3b3193 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
@@ -1065,61 +1065,46 @@ def validate_driverfixes_branches(deliv, workdir, messages):
|
|||||||
_require_gitreview(workdir, repo, messages)
|
_require_gitreview(workdir, repo, messages)
|
||||||
|
|
||||||
|
|
||||||
def validate_branch_points(deliverable_info,
|
def validate_branch_points(deliv, workdir, messages):
|
||||||
deliverable_name,
|
"Make sure the branch points given are on the expected branches."
|
||||||
workdir,
|
|
||||||
messages):
|
|
||||||
# Make sure the branch points given are on the expected branches.
|
|
||||||
|
|
||||||
known_releases = {
|
|
||||||
r['version']: r
|
|
||||||
for r in deliverable_info.get('releases', [])
|
|
||||||
}
|
|
||||||
branch_mode = deliverable_info.get('stable-branch-type', 'std')
|
|
||||||
|
|
||||||
# Check for 'upstream' branches. These track upstream release names and
|
# Check for 'upstream' branches. These track upstream release names and
|
||||||
# do not align with OpenStack series names.
|
# do not align with OpenStack series names.
|
||||||
if branch_mode == 'upstream':
|
if deliv.stable_branch_type == 'upstream':
|
||||||
|
LOG.debug('this project follows upstream branching conventions, '
|
||||||
|
'skipping')
|
||||||
return
|
return
|
||||||
|
|
||||||
for branch in deliverable_info.get('branches', []):
|
for branch in deliv.branches:
|
||||||
header('Validate Branch Points: {}'.format(branch['name']))
|
header('Validate Branch Points: {}'.format(branch.name))
|
||||||
try:
|
try:
|
||||||
prefix, series = branch['name'].split('/')
|
prefix, series = branch.name.split('/')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('could not parse the branch name, skipping')
|
print('could not parse the branch name, skipping')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if prefix == 'feature':
|
if prefix == 'feature':
|
||||||
print('rule does not apply to feature branches')
|
LOG.debug('{} is a feature branch, rule does not apply'.format(
|
||||||
|
branch.name))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif prefix == 'stable':
|
elif prefix == 'stable':
|
||||||
expected = set([
|
expected = set([
|
||||||
'master',
|
'master',
|
||||||
branch['name'],
|
branch.name,
|
||||||
])
|
])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# driverfixes
|
# driverfixes
|
||||||
expected = set([
|
expected = set([
|
||||||
branch['name'],
|
branch.name,
|
||||||
'stable/' + series,
|
'stable/' + series,
|
||||||
])
|
])
|
||||||
|
|
||||||
if prefix == 'stable' and branch_mode == 'std':
|
location = branch.get_repo_map()
|
||||||
# location is a version string, so we need to build the
|
|
||||||
# map ourselves
|
|
||||||
print('using hashes from release {}'.format(branch['location']))
|
|
||||||
release = known_releases[branch['location']]
|
|
||||||
location = {
|
|
||||||
p['repo']: p['hash']
|
|
||||||
for p in release['projects']
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
location = branch['location']
|
|
||||||
|
|
||||||
for repo, hash in sorted(location.items()):
|
for repo, hash in sorted(location.items()):
|
||||||
print('\n{}'.format(repo))
|
LOG.debug('{}'.format(repo))
|
||||||
existing_branches = sorted([
|
existing_branches = sorted([
|
||||||
(b.partition('/origin/')[-1]
|
(b.partition('/origin/')[-1]
|
||||||
if b.startswith('remotes/origin/')
|
if b.startswith('remotes/origin/')
|
||||||
@@ -1135,16 +1120,16 @@ def validate_branch_points(deliverable_info,
|
|||||||
workdir, repo, hash)
|
workdir, repo, hash)
|
||||||
)
|
)
|
||||||
|
|
||||||
print('found {} on branches {} in {}'.format(
|
LOG.debug('found {} on branches {} in {}'.format(
|
||||||
hash, containing, repo))
|
hash, containing, repo))
|
||||||
|
|
||||||
for missing in expected.difference(containing):
|
for missing in expected.difference(containing):
|
||||||
if missing not in existing_branches:
|
if missing not in existing_branches:
|
||||||
print('branch {} does not exist in {}, skipping'.format(
|
LOG.debug('branch {} does not exist in {}, '
|
||||||
branch['name'], repo))
|
'skipping'.format(branch.name, repo))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if branch['name'] in existing_branches:
|
if branch.name in existing_branches:
|
||||||
# The branch already exists but there is something
|
# The branch already exists but there is something
|
||||||
# wrong with the specification. This probably
|
# wrong with the specification. This probably
|
||||||
# means someone tried to update the branch setting
|
# means someone tried to update the branch setting
|
||||||
@@ -1153,7 +1138,7 @@ def validate_branch_points(deliverable_info,
|
|||||||
messages.error(
|
messages.error(
|
||||||
'{} branch exists in {} and does not seem '
|
'{} branch exists in {} and does not seem '
|
||||||
'to have been created from {}'.format(
|
'to have been created from {}'.format(
|
||||||
branch['name'], repo, hash),
|
branch.name, repo, hash),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# The branch does not exist and the proposed point
|
# The branch does not exist and the proposed point
|
||||||
@@ -1164,7 +1149,7 @@ def validate_branch_points(deliverable_info,
|
|||||||
'commit {} is not on the {} branch '
|
'commit {} is not on the {} branch '
|
||||||
'but it is listed as the branch point for '
|
'but it is listed as the branch point for '
|
||||||
'{} to be created'.format(
|
'{} to be created'.format(
|
||||||
hash, missing, branch['name']))
|
hash, missing, branch.name))
|
||||||
|
|
||||||
|
|
||||||
# if the branch already exists, the name is by definition valid
|
# if the branch already exists, the name is by definition valid
|
||||||
@@ -1340,8 +1325,7 @@ def main():
|
|||||||
messages,
|
messages,
|
||||||
)
|
)
|
||||||
validate_branch_points(
|
validate_branch_points(
|
||||||
deliv._data,
|
deliv,
|
||||||
deliv.name,
|
|
||||||
workdir,
|
workdir,
|
||||||
messages,
|
messages,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -292,6 +292,16 @@ class Branch(object):
|
|||||||
def series(self):
|
def series(self):
|
||||||
return self.name.split('/')[1]
|
return self.name.split('/')[1]
|
||||||
|
|
||||||
|
def get_repo_map(self):
|
||||||
|
"Return mapping between repo and hash."
|
||||||
|
if isinstance(self.location, dict):
|
||||||
|
return self.location
|
||||||
|
release = self.deliv.get_release(self.location)
|
||||||
|
return {
|
||||||
|
p.repo.name: p.hash
|
||||||
|
for p in release.projects
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@functools.total_ordering
|
@functools.total_ordering
|
||||||
class Deliverable(object):
|
class Deliverable(object):
|
||||||
@@ -439,6 +449,12 @@ class Deliverable(object):
|
|||||||
def releases(self):
|
def releases(self):
|
||||||
return self._releases
|
return self._releases
|
||||||
|
|
||||||
|
def get_release(self, version):
|
||||||
|
for r in self.releases:
|
||||||
|
if r.version == version:
|
||||||
|
return r
|
||||||
|
raise ValueError('Unknown version {}'.format(version))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def branches(self):
|
def branches(self):
|
||||||
return self._branches
|
return self._branches
|
||||||
|
|||||||
@@ -2540,10 +2540,14 @@ class TestValidateBranchPoints(base.BaseTestCase):
|
|||||||
- name: stable/ocata
|
- name: stable/ocata
|
||||||
location: 0.0.3
|
location: 0.0.3
|
||||||
''')
|
''')
|
||||||
deliverable_info = yamlutils.loads(deliverable_data)
|
deliv = deliverable.Deliverable(
|
||||||
|
team='team',
|
||||||
|
series='ocata',
|
||||||
|
name='name',
|
||||||
|
data=yamlutils.loads(deliverable_data),
|
||||||
|
)
|
||||||
validate.validate_branch_points(
|
validate.validate_branch_points(
|
||||||
deliverable_info,
|
deliv,
|
||||||
'name',
|
|
||||||
self.tmpdir,
|
self.tmpdir,
|
||||||
self.msg,
|
self.msg,
|
||||||
)
|
)
|
||||||
@@ -2561,10 +2565,14 @@ class TestValidateBranchPoints(base.BaseTestCase):
|
|||||||
- name: stable/newton
|
- name: stable/newton
|
||||||
location: 0.8.0
|
location: 0.8.0
|
||||||
''')
|
''')
|
||||||
deliverable_info = yamlutils.loads(deliverable_data)
|
deliv = deliverable.Deliverable(
|
||||||
|
team='team',
|
||||||
|
series='newton',
|
||||||
|
name='name',
|
||||||
|
data=yamlutils.loads(deliverable_data),
|
||||||
|
)
|
||||||
validate.validate_branch_points(
|
validate.validate_branch_points(
|
||||||
deliverable_info,
|
deliv,
|
||||||
'name',
|
|
||||||
self.tmpdir,
|
self.tmpdir,
|
||||||
self.msg,
|
self.msg,
|
||||||
)
|
)
|
||||||
@@ -2583,10 +2591,14 @@ class TestValidateBranchPoints(base.BaseTestCase):
|
|||||||
location: 0.12.0 # this comes after the meiji branch
|
location: 0.12.0 # this comes after the meiji branch
|
||||||
# was created at 0.0.2
|
# was created at 0.0.2
|
||||||
''')
|
''')
|
||||||
deliverable_info = yamlutils.loads(deliverable_data)
|
deliv = deliverable.Deliverable(
|
||||||
|
team='team',
|
||||||
|
series='meiji',
|
||||||
|
name='name',
|
||||||
|
data=yamlutils.loads(deliverable_data),
|
||||||
|
)
|
||||||
validate.validate_branch_points(
|
validate.validate_branch_points(
|
||||||
deliverable_info,
|
deliv,
|
||||||
'name',
|
|
||||||
self.tmpdir,
|
self.tmpdir,
|
||||||
self.msg,
|
self.msg,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user