-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
971a7e5
to
bfb939b
Compare
dab25f3
to
f23188d
Compare
@@ -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: |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
Nice optimization :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied
There was a problem hiding this comment.
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'])
d4bd5a7
to
ef97451
Compare
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
ef97451
to
dd320f9
Compare
|
||
is_rusable_repo = repo.repo_name in reusable_repos | ||
is_reusable_repo = repo.repo_name in reusable_repos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing that 😉
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