Skip to content

Commit

Permalink
Workaround in integration tests with Traefik
Browse files Browse the repository at this point in the history
  • Loading branch information
saltiyazan committed Oct 10, 2024
1 parent c6b133e commit 364e4ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def _send_ca_cert(self):
certificates={ca_cert}, relation_id=relation.id
)
logger.info("Sent CA certificate to relation %s", relation.id)

def _configure_juju_workload_version(self):
"""Set the Juju workload version to the Notary version."""
if not self.unit.is_leader():
Expand Down
20 changes: 12 additions & 8 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
TRAEIK_K8S_APPLICATION_NAME = "traefik-k8s"
TLS_PROVIDER_APPLICATION_NAME = "self-signed-certificates"
TLS_REQUIRER_APPLICATION_NAME = "tls-certificates-requirer"
# TODO: Set correct revision when https://github.com/canonical/traefik-k8s-operator/pull/407 is merged
TRAEIK_K8S_REVISION = 1


@pytest.mark.abort_on_fail
Expand Down Expand Up @@ -199,15 +197,19 @@ async def test_given_application_deployed_when_related_to_traefik_k8s_then_all_s
application_name=TRAEIK_K8S_APPLICATION_NAME,
trust=True,
channel="stable",
revision=TRAEIK_K8S_REVISION,
)
# TODO (Tracked in TLSENG-475): This is a workaround so Traefik has the same CA as Notary
# This should be removed and certificate transfer should be used instead
# Notary k8s implements V1 of the certificate transfer interface,
# And the following PR is needed to get Traefik to use it too:
# https://github.com/canonical/traefik-k8s-operator/issues/407
await ops_test.model.integrate(
relation1=f"{APP_NAME}:ingress",
relation2=f"{TRAEIK_K8S_APPLICATION_NAME}:ingress",
relation1=f"{TLS_PROVIDER_APPLICATION_NAME}:certificates",
relation2=f"{TRAEIK_K8S_APPLICATION_NAME}",
)
await ops_test.model.integrate(
relation1=f"{APP_NAME}:send-ca-cert",
relation2=f"{TRAEIK_K8S_APPLICATION_NAME}:receive-ca-cert-v1",
relation1=f"{APP_NAME}:ingress",
relation2=f"{TRAEIK_K8S_APPLICATION_NAME}:ingress",
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME, TRAEIK_K8S_APPLICATION_NAME],
Expand All @@ -226,9 +228,9 @@ async def get_notary_endpoint(ops_test: OpsTest) -> str:
notary_ip = status.applications[APP_NAME].units[f"{APP_NAME}/0"].address
return f"https://{notary_ip}:2111"


async def get_external_notary_endpoint(ops_test: OpsTest) -> str:
assert ops_test.model
status = await ops_test.model.get_status()
traefik_proxied_endpoints = await run_show_traefik_proxied_endpoints_action(ops_test)
return json.loads(traefik_proxied_endpoints).get(APP_NAME, "").get("url", "")

Expand Down Expand Up @@ -259,13 +261,15 @@ async def run_get_certificate_action(ops_test: OpsTest) -> str:
action_output = await ops_test.model.get_action_output(action_uuid=action.entity_id, wait=30)
return action_output.get("certificates", "")


async def run_show_traefik_proxied_endpoints_action(ops_test: OpsTest) -> str:
assert ops_test.model
traefik_k8s_unit = ops_test.model.units[f"{TRAEIK_K8S_APPLICATION_NAME}/0"]
action = await traefik_k8s_unit.run_action(action_name="show-proxied-endpoints") # type: ignore
action_output = await ops_test.model.get_action_output(action_uuid=action.entity_id, wait=30)
return action_output.get("proxied-endpoints", "")


async def get_file_from_notary(ops_test: OpsTest, file_name: str) -> str:
notary_unit = ops_test.model.units[f"{APP_NAME}/0"] # type: ignore
action = await notary_unit.run(f"cat /var/lib/juju/storage/config/0/{file_name}") # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3690,8 +3690,9 @@ def test_given_send_ca_requirer_when_configure_then_ca_cert_sent(
**{
"is_api_available.return_value": True,
"is_initialized.return_value": True,
"login.return_value": "example-token",
"login.return_value": LoginResponse(token="example-token"),
"token_is_valid.return_value": True,
"get_version.return_value": "1.2.3",
},
),
):
Expand Down

0 comments on commit 364e4ec

Please sign in to comment.