Improve tools/layout-checks.py
Instead of hard-coding first entries, use the section headers directly. Make the output a bit nicer. Change-Id: I0a5f947d42ada5f010853de04f3ca651039eeb60
This commit is contained in:
@@ -25,6 +25,8 @@ def check_merge_template():
|
|||||||
"""Check that each job has a merge-check template."""
|
"""Check that each job has a merge-check template."""
|
||||||
|
|
||||||
errors = False
|
errors = False
|
||||||
|
print("\nChecking for usage of merge template")
|
||||||
|
print("====================================")
|
||||||
for project in layout['projects']:
|
for project in layout['projects']:
|
||||||
if project['name'] == 'z/tempest':
|
if project['name'] == 'z/tempest':
|
||||||
continue
|
continue
|
||||||
@@ -47,85 +49,41 @@ def normalize(s):
|
|||||||
|
|
||||||
|
|
||||||
def check_sections():
|
def check_sections():
|
||||||
"""Check that the openstack/* projects are in alphabetical order."""
|
"""Check that the projects are in alphabetical order per section."""
|
||||||
|
|
||||||
# Note that openstack/ has different sections and we need to sort
|
print("Checking sections for alphabetical order")
|
||||||
# entries within these sections:
|
print("========================================")
|
||||||
# Section: OpenStack server projects
|
# Note that the file has different sections and we need to sort
|
||||||
# Section: OpenStack client projects (python-*)
|
# entries within these sections.
|
||||||
# Section: oslo projects
|
|
||||||
# Section: Other OpenStack projects
|
|
||||||
# Section: OpenStack API projects
|
|
||||||
# Section: OpenStack documentation projects
|
|
||||||
# Record the first project in each section and use that to
|
|
||||||
# identify them. This list needs to be adjusted if entries get
|
|
||||||
# added.
|
|
||||||
section_starters = ['openstack/barbican',
|
|
||||||
'openstack/python-barbicanclient',
|
|
||||||
'openstack/cliff',
|
|
||||||
'openstack/dib-utils',
|
|
||||||
'openstack/compute-api',
|
|
||||||
'openstack/api-site',
|
|
||||||
'openstack-dev/bashate']
|
|
||||||
errors = False
|
errors = False
|
||||||
for i in range(0, len(section_starters) - 1):
|
# Skip all entries before the first section header
|
||||||
print("Checking section from %s to %s" %
|
firstEntry = True
|
||||||
(section_starters[i], section_starters[i + 1]))
|
last = ""
|
||||||
last = layout['projects'][0]['name']
|
for line in open('zuul/layout.yaml', 'r'):
|
||||||
in_section = False
|
if line.startswith('# Section:'):
|
||||||
for project in layout['projects']:
|
last = ""
|
||||||
current = project['name']
|
section = line[10:].strip()
|
||||||
if current == section_starters[i]:
|
print("Checking section '%s'" % section)
|
||||||
in_section = True
|
firstEntry = False
|
||||||
last = current
|
if line.startswith(' - name: ') and not firstEntry:
|
||||||
continue
|
current = line[10:].strip()
|
||||||
# Did we reach end of section?
|
if (normalize(last) > normalize(current) and
|
||||||
if current == section_starters[i + 1]:
|
last != 'z/tempest'):
|
||||||
break
|
|
||||||
if not in_section:
|
|
||||||
last = current
|
|
||||||
continue
|
|
||||||
if last == 'z/tempest':
|
|
||||||
last = current
|
|
||||||
continue
|
|
||||||
if normalize(last) > normalize(current):
|
|
||||||
print(" Wrong alphabetical order: %(last)s, %(current)s" %
|
print(" Wrong alphabetical order: %(last)s, %(current)s" %
|
||||||
{"last": last, "current": current})
|
{"last": last, "current": current})
|
||||||
errors = True
|
errors = True
|
||||||
last = current
|
last = current
|
||||||
|
|
||||||
return errors
|
|
||||||
|
|
||||||
|
|
||||||
def check_alphabetical():
|
|
||||||
"""Check that projects are sorted alphabetical."""
|
|
||||||
|
|
||||||
errors = False
|
|
||||||
# For now, only check sorting of some projects.
|
|
||||||
last = layout['projects'][0]['name']
|
|
||||||
for project in layout['projects']:
|
|
||||||
current = project['name']
|
|
||||||
if not last.startswith(("openstack-dev/", "openstack-infra/",
|
|
||||||
"stackforge/")):
|
|
||||||
last = current
|
|
||||||
continue
|
|
||||||
if normalize(last) > normalize(current):
|
|
||||||
print("Wrong alphabetical order: %(last)s, %(current)s" %
|
|
||||||
{"last": last, "current": current})
|
|
||||||
errors = True
|
|
||||||
last = current
|
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
def check_all():
|
def check_all():
|
||||||
errors = check_sections()
|
errors = check_sections()
|
||||||
errors = check_alphabetical() or errors
|
|
||||||
errors = check_merge_template() or errors
|
errors = check_merge_template() or errors
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
print("Found errors in layout.yaml!")
|
print("\nFound errors in layout.yaml!")
|
||||||
else:
|
else:
|
||||||
print("No errors found in layout.yaml!")
|
print("\nNo errors found in layout.yaml!")
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user