Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ forwards, however, we will be looking to move away from building the cluster
this way, and towards using the [CI
operator](https://github.com/openshift/ci-operator/) as our primary means of
testing.

## Auditing CI Jobs Configuration

Audits CI configuration files to find OpenStack e2e test jobs and reports
their run_if_changed and skip_if_only_changed settings.

Usage: python hack/openstack-job-audit.py <project_path> [output_file]
project_path: Path to the local copy of the release repo
output_file: Output file path (default: ./openstack-ci-report.yaml)

Example: ./openstack-job-audit.py /path/to/openshift/release ./report.yaml
156 changes: 156 additions & 0 deletions hack/openstack-job-audit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env python3
"""
Audits CI configuration files to find OpenStack e2e test jobs and reports
their run_if_changed and skip_if_only_changed settings.

Usage: ./openstack-job-audit.py <project_path> [output_file]
project_path: Path to the project root (ci-operator/config will be appended)
output_file: Output file path (default: ./openstack-ci-report.yaml)

Example: ./openstack-job-audit.py /path/to/openshift/release ./report.yaml
"""

import argparse
import re
import sys
from collections import defaultdict
from pathlib import Path

import yaml
from ruamel.yaml import YAML
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

humm, why do we need 2 yaml libraries? Can't we use PyYAML for writing the report?

Copy link
Contributor Author

@eshulman2 eshulman2 Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PyYAML output was less readable, so switched to ruamel to make the output more readable but PyYAML is still required for parsing. I can switch back to only PyYAML but I prefer the output with ruamel.



def find_vexxhost_files(config_base_path: Path) -> dict[str, list[Path]]:
"""
Find all config files containing vexxhost cluster_profile.

Returns a dict mapping project (org/repo) to list of matching files.
"""
pattern = re.compile(r'cluster_profile:.*vexxhost.*')
projects = defaultdict(list)

for file_path in config_base_path.rglob('*.yaml'):
try:
content = file_path.read_text()
if pattern.search(content):
# Extract project as org/repo from path
# Path structure: config_base_path/org/repo/file.yaml
rel_path = file_path.relative_to(config_base_path)
parts = rel_path.parts
if len(parts) >= 2:
project = f"{parts[0]}/{parts[1]}"
projects[project].append(file_path)
except (OSError, UnicodeDecodeError):
continue

return projects


def extract_vexxhost_tests(file_path: Path) -> list[dict]:
"""
Extract test jobs with vexxhost cluster_profile from a config file.

Returns list of dicts with test name and settings.
"""
try:
with open(file_path) as f:
config = yaml.safe_load(f)
except (OSError, yaml.YAMLError):
return []

if not config or 'tests' not in config:
return []

vexxhost_pattern = re.compile(r'.*vexxhost.*')
results = []

for test in config.get('tests', []):
steps = test.get('steps', {})
cluster_profile = steps.get('cluster_profile', '')

if vexxhost_pattern.match(str(cluster_profile)):
test_data = {
'name': test.get('as', 'unknown'),
'run_if_changed': test.get('run_if_changed', 'not set'),
'skip_if_only_changed': test.get('skip_if_only_changed',
'not set'),
}
if 'interval' in test:
test_data['interval'] = test.get('interval')
if 'minimum_interval' in test:
test_data['minimum_interval'] = test.get('minimum_interval')
results.append(test_data)

return results


def generate_report(config_base_path: Path) -> dict:
"""
Generate the audit report for all projects.

Returns a dict structured for YAML output.
"""
projects = find_vexxhost_files(config_base_path)
report = {}

for project in sorted(projects.keys()):
files = sorted(projects[project])
project_data = []

for file_path in files:
tests = extract_vexxhost_tests(file_path)
if tests:
file_entry = {
'file': str(file_path),
'tests': tests,
}
project_data.append(file_entry)

if project_data:
report[project] = project_data

return report


def main():
parser = argparse.ArgumentParser(
description="Audit CI config files for OpenStack e2e test jobs"
)
parser.add_argument(
"project_path",
type=Path,
help="Path to the project root (ci-operator/config will be appended)",
)
parser.add_argument(
"output_file",
nargs="?",
type=Path,
default=Path("./openstack-ci-report.yaml"),
help="Output file path (default: ./openstack-ci-report.yaml)",
)
args = parser.parse_args()

config_base_path = args.project_path / "ci-operator" / "config"

if not config_base_path.is_dir():
print(
f"Error: {config_base_path} is not a directory",
file=sys.stderr
)
sys.exit(1)

report = generate_report(config_base_path)

ruamel = YAML()
ruamel.default_flow_style = False
ruamel.width = 4096
ruamel.indent(mapping=2, sequence=4, offset=2)

with open(args.output_file, 'w') as f:
ruamel.dump(report, f)

print(f"Report written to {args.output_file}")


if __name__ == "__main__":
main()
Loading