-
Notifications
You must be signed in to change notification settings - Fork 0
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
Test configure_apiserver while addressing issue with authorization_modes #25
Conversation
@@ -135,7 +135,7 @@ def configure_apiserver( | |||
"Authorization mode includes 'Webhook' but no webhook config file is present." | |||
"'Webhook' must be removed from authorization mode." | |||
) | |||
authorization_modes = authorization_modes.remove("Webhook") |
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.
This is the original thrust of the bug. Python's list.remove returns None. causing the following stack track:
File "/var/lib/juju/agents/unit-kubernetes-control-plane-0/charm/./src/charm.py", line 541, in reconcile
self.configure_apiserver()
File "/var/lib/juju/agents/unit-kubernetes-control-plane-0/charm/./src/charm.py", line 141, in configure_apiserver
kubernetes_snaps.configure_apiserver(
File "/var/lib/juju/agents/unit-kubernetes-control-plane-0/charm/venv/charms/kubernetes_snaps.py", line 145, in configure_apiserver
api_opts["authorization-mode"] = ",".join(authorization_modes)
TypeError: can only join an iterable
audit_root = "/root/cdk/audit" | ||
audit_log_path = audit_root + "/audit.log" | ||
audit_policy_path = audit_root + "/audit-policy.yaml" | ||
audit_webhook_conf_path = audit_root + "/audit-webhook-config.yaml" | ||
os.makedirs(audit_root, exist_ok=True) | ||
audit_root = Path("/root/cdk/audit") | ||
audit_log_path = audit_root / "audit.log" | ||
audit_policy_path = audit_root / "audit-policy.yaml" | ||
audit_webhook_conf_path = audit_root / "audit-webhook-config.yaml" | ||
audit_root.mkdir(exist_ok=True) | ||
|
||
api_opts["audit-log-path"] = audit_log_path | ||
api_opts["audit-log-path"] = str(audit_log_path) | ||
api_opts["audit-log-maxage"] = "30" |
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.
These make the method more testable
with open(audit_policy_path, "w") as f: | ||
with audit_policy_path.open("w") as f: | ||
f.write(audit_policy) | ||
api_opts["audit-policy-file"] = audit_policy_path | ||
api_opts["audit-policy-file"] = str(audit_policy_path) | ||
else: | ||
remove_if_exists(audit_policy_path) | ||
|
||
if audit_webhook_conf: | ||
with open(audit_webhook_conf_path, "w") as f: | ||
with audit_webhook_conf_path.open("w") as f: | ||
f.write(audit_webhook_conf) | ||
api_opts["audit-webhook-config-file"] = audit_webhook_conf_path | ||
api_opts["audit-webhook-config-file"] = str(audit_webhook_conf_path) | ||
else: |
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.
again -- more test-ability -- only need to mock out Path
|
||
@mock.patch("charms.kubernetes_snaps.configure_kubernetes_service") | ||
@mock.patch("charms.kubernetes_snaps.Path") | ||
def test_configure_apiserver(mock_path, configure_kubernetes_service, external_cloud): |
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.
Nice! Useful test.
Overview
Addresses LP#2071488 by not assigning the output of
list.remove
back to the list. python'slist.remove()
always returns NoneDetails