Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tenant_parser.py: add support for extra-config-paths #104

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

swiekr
Copy link

@swiekr swiekr commented Nov 7, 2023

When creating/updating repo_map, 'extra-config-paths' list is extracted from tenant configuration and saved in repo's 'tenants' dictionary (next to 'jobs' and 'roles')

Extra-config-paths values are used for Scraper class initialization. The 'scrape_job_files' method extends the whitelist with it

'test_integration' tests were extended to verify this new functionality

@swiekr swiekr marked this pull request as ready for review November 7, 2023 12:07
@swiekr swiekr requested a review from a team as a code owner November 7, 2023 12:07
zubbi/scraper/tenant_parser.py Show resolved Hide resolved
zubbi/scraper/tenant_parser.py Outdated Show resolved Hide resolved
@swiekr swiekr force-pushed the ks/extra_config_paths branch 4 times, most recently from dab25f3 to f23188d Compare December 5, 2023 14:21
@@ -75,14 +75,36 @@ def _update_repo_map(self, project, connection_name, tenant):
repo_tenant_entry["tenants"]["jobs"].append(tenant)
repo_tenant_entry["tenants"]["roles"].append(tenant)

if extra_config_paths:
Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, this whole block is about creating a default empty list and adding the tenant to it. In that case we could simplify this to:

if extra_config_paths:
    repo_tenant_extra_config_paths = repo_tenant_entry["tenants"].setdefault("extra_config_paths", defaultdict(lambda: []))
    repo_tenant_extra_config_paths[extra_config_path].append(tenant)

Copy link
Author

Choose a reason for hiding this comment

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

yes.
Nice optimization :)

Copy link
Author

Choose a reason for hiding this comment

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

applied

Copy link
Author

@swiekr swiekr Dec 7, 2023

Choose a reason for hiding this comment

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

I have tested the behavior using following test:

from pprint import pprint as pprint
from collections import defaultdict

repo_map = {}
connection_name = "github"

# project_name, tenant , extra_config_paths
test_cases = [
    ("org1/repo1", "foo", []),
    ("org1/repo2", "foo", ["zuul-extra.d"]),
    ("org1/repo2", "bar", ["zuul-extra.d", ".zuul-extra.yaml"]),
    ("org1/repo2", "baz", [".zuul-extra.yaml"]),
    ("org1/repo2", "bud", []),
]

for case in test_cases:
    project_name = case[0]
    tenant = case[1]
    extra_config_paths = case[2]

    repo_tenant_entry = repo_map.setdefault(
        project_name,
        {"tenants": {"jobs": [], "roles": []}, "connection_name": connection_name},
    )

    repo_tenant_entry["tenants"]["jobs"].append(tenant)
    repo_tenant_entry["tenants"]["roles"].append(tenant)

    if extra_config_paths:
        repo_tenant_extra_config_paths = repo_tenant_entry["tenants"].setdefault("extra_config_paths", defaultdict(lambda: []))
        for extra_config_path in extra_config_paths:
            repo_tenant_extra_config_paths[extra_config_path].append(tenant)

    pprint(repo_map)
    print("------------------------------------------------")

for item in repo_map["org1/repo2"]["tenants"]["extra_config_paths"].items():
    print(item)

results are OK (repoMap structure is as we would expect it: no 'extra_config_paths' dict in repos without it defined):

[...]
{'org1/repo1': {'connection_name': 'github',
                'tenants': {'jobs': ['foo'], 'roles': ['foo']}},
 'org1/repo2': {'connection_name': 'github',
                'tenants': {'extra_config_paths': defaultdict(<function <lambda> at 0x7fd5836901f0>,
                                                              {'.zuul-extra.yaml': ['bar',
                                                                                    'baz'],
                                                               'zuul-extra.d': ['foo',
                                                                                'bar']}),
                            'jobs': ['foo', 'bar', 'baz', 'bud'],
                            'roles': ['foo', 'bar', 'baz', 'bud']}}}
------------------------------------------------
('zuul-extra.d', ['foo', 'bar'])
('.zuul-extra.yaml', ['bar', 'baz'])

@swiekr swiekr force-pushed the ks/extra_config_paths branch 3 times, most recently from d4bd5a7 to ef97451 Compare December 7, 2023 12:44
When creating/updating repo_map, 'extra-config-paths' list is extracted from
tenant configuration and saved in repo's 'tenants' dictionary (next to 'jobs'
and 'roles')

Extra-config-paths values are used for Scraper class initialization.
The 'scrape_job_files' method extends the whitelist with it

'test_integration' tests were extended to verify this new functionality

is_rusable_repo = repo.repo_name in reusable_repos
is_reusable_repo = repo.repo_name in reusable_repos
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing that 😉

@felixedel felixedel merged commit bb31afe into bmwcarit:master Dec 11, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants