Check zuul/main.yaml projects
Check that projects in zuul/main.yaml exist in gerrit. This would have avoided https://review.opendev.org/659697. Use yaml.safe_load in one case. Depends-On: https://review.opendev.org/659735 Change-Id: I6fb3d90c18b57c004caf02dd6e5d5c34b1ce1ff9
This commit is contained in:
parent
1dab1e2d01
commit
10de11d7a9
@ -86,6 +86,47 @@ def check_repo(repo_path):
|
||||
return found_errors
|
||||
|
||||
|
||||
# Check that name exists in set project_names
|
||||
def check_project_exists(name, project_names):
|
||||
|
||||
if name not in project_names:
|
||||
print(" Error: project %s does not exist in gerrit" % name)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
def check_zuul_main(zuul_main, projects):
|
||||
found_errors = 0
|
||||
|
||||
main_content = yaml.safe_load(open(zuul_main, 'r'))
|
||||
|
||||
print("Checking %s" % zuul_main)
|
||||
|
||||
project_names = set()
|
||||
for p in projects:
|
||||
name = p.get('project')
|
||||
project_names.add(name)
|
||||
|
||||
# Check that for each gerrit source, we have a project defined in gerrit.
|
||||
for tenant in main_content:
|
||||
t = tenant.get('tenant')
|
||||
sources = t.get('source')
|
||||
if sources and sources.get('gerrit'):
|
||||
for project_types in sources['gerrit']:
|
||||
for entry in sources['gerrit'][project_types]:
|
||||
if isinstance(entry, dict):
|
||||
for x in entry.keys():
|
||||
found_errors += check_project_exists(
|
||||
x, project_names)
|
||||
else:
|
||||
found_errors += check_project_exists(
|
||||
entry, project_names)
|
||||
|
||||
# Just an empty line for nicer formatting
|
||||
print("")
|
||||
return found_errors
|
||||
|
||||
|
||||
def main():
|
||||
found_errors = 0
|
||||
|
||||
@ -102,9 +143,13 @@ def main():
|
||||
'acldir',
|
||||
help='Path to gerrit/acl',
|
||||
)
|
||||
parser.add_argument(
|
||||
'zuul_main_file',
|
||||
help='Path to zuul/main.yaml',
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
projects = yaml.load(open(args.infile, 'r'))
|
||||
projects = yaml.safe_load(open(args.infile, 'r'))
|
||||
|
||||
VALID_LABELS = ["acl-config", "description", "docimpact-group",
|
||||
"groups", "homepage", "options", "project",
|
||||
@ -259,6 +304,7 @@ def main():
|
||||
found_errors += 1
|
||||
print("Error: groups entry for project %s is not a list." % name)
|
||||
|
||||
found_errors += check_zuul_main(args.zuul_main_file, projects)
|
||||
if found_errors:
|
||||
print("Found %d error(s) in %s" % (found_errors, args.infile))
|
||||
sys.exit(1)
|
||||
|
2
tox.ini
2
tox.ini
@ -60,7 +60,7 @@ deps =
|
||||
ruamel.yaml
|
||||
GitPython
|
||||
commands =
|
||||
{toxinidir}/tools/check_valid_gerrit_projects.py gerrit/projects.yaml gerrit/acls
|
||||
{toxinidir}/tools/check_valid_gerrit_projects.py gerrit/projects.yaml gerrit/acls zuul/main.yaml
|
||||
{toxinidir}/tools/check_projects_yaml_alphabetized.sh gerrit/projects.yaml
|
||||
{toxinidir}/tools/check_valid_gerrit_config.sh gerrit/acls/
|
||||
{toxinidir}/tools/check_gerrit_projects_changed.sh
|
||||
|
Loading…
x
Reference in New Issue
Block a user