From b2cdb2e4290de65c46f5bf465f0607650730e75f Mon Sep 17 00:00:00 2001 From: gtrkiller Date: Tue, 23 Apr 2024 11:19:19 -0300 Subject: [PATCH 01/11] add redeployment doc --- docs/reference/charm-redeployment.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/reference/charm-redeployment.md diff --git a/docs/reference/charm-redeployment.md b/docs/reference/charm-redeployment.md new file mode 100644 index 0000000..e320944 --- /dev/null +++ b/docs/reference/charm-redeployment.md @@ -0,0 +1,5 @@ +## Charm Redeployment + +If you need to redeploy the [content-cache-k8s](https://charmhub.io/content-cache-k8s) charm it has no underlying state, +so going through a normal deployment process using the same configuration options and relations +as your original deployment will suffice. \ No newline at end of file From a26c2cdf315829caf11b73330da6cdd0653043b5 Mon Sep 17 00:00:00 2001 From: mthaddon Date: Mon, 29 Apr 2024 15:17:28 +0200 Subject: [PATCH 02/11] Update docs/reference/charm-redeployment.md Co-authored-by: Yanks Yoon <37652070+yanksyoon@users.noreply.github.com> --- docs/reference/charm-redeployment.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/charm-redeployment.md b/docs/reference/charm-redeployment.md index e320944..c352bbd 100644 --- a/docs/reference/charm-redeployment.md +++ b/docs/reference/charm-redeployment.md @@ -1,5 +1,5 @@ ## Charm Redeployment -If you need to redeploy the [content-cache-k8s](https://charmhub.io/content-cache-k8s) charm it has no underlying state, -so going through a normal deployment process using the same configuration options and relations +If you need to redeploy the [content-cache-k8s](https://charmhub.io/content-cache-k8s) charm, it has no underlying state. +Hence going through a normal deployment process using the same configuration options and relations as your original deployment will suffice. \ No newline at end of file From 6e177479e6e83d4cb543479d9b34f9062f71d9f2 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Mon, 29 Apr 2024 22:13:23 +0800 Subject: [PATCH 03/11] fix: integration test pytest compatibility --- tests/integration/requirements.txt | 4 +--- tox.ini | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt index 6ff4240..5fe68a2 100644 --- a/tests/integration/requirements.txt +++ b/tests/integration/requirements.txt @@ -1,7 +1,5 @@ requests -pytest-operator python-keystoneclient python-swiftclient Pillow -pytest -pytest-cov \ No newline at end of file + diff --git a/tox.ini b/tox.ini index a379122..60fa7a2 100644 --- a/tox.ini +++ b/tox.ini @@ -105,6 +105,9 @@ commands = [testenv:integration] description = Run integration tests deps = + pytest==8.1.1 + pytest-cov + pytest-operator # Last compatible version with Juju 2.9 juju==3.0.4 -r{toxinidir}/requirements.txt From 198dd3b638ab39ce17b2cb880041abcb9b0d4284 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Mon, 29 Apr 2024 22:14:29 +0800 Subject: [PATCH 04/11] fix: add comment for pytest pin --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 60fa7a2..500f90c 100644 --- a/tox.ini +++ b/tox.ini @@ -105,6 +105,8 @@ commands = [testenv:integration] description = Run integration tests deps = + # Pin version until the issue with pytest-operator is resolved + # https://github.com/charmed-kubernetes/pytest-operator/issues/131 pytest==8.1.1 pytest-cov pytest-operator From e414127f4864d3bf7f6ebfeb9e925edd5c522921 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Mon, 29 Apr 2024 22:31:48 +0800 Subject: [PATCH 05/11] revert pytest pin(fixed) --- tox.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 500f90c..f341365 100644 --- a/tox.ini +++ b/tox.ini @@ -105,9 +105,7 @@ commands = [testenv:integration] description = Run integration tests deps = - # Pin version until the issue with pytest-operator is resolved - # https://github.com/charmed-kubernetes/pytest-operator/issues/131 - pytest==8.1.1 + pytest pytest-cov pytest-operator # Last compatible version with Juju 2.9 From e671bcf3d89de22660578af24b8039a3f8739238 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Mon, 29 Apr 2024 23:14:34 +0800 Subject: [PATCH 06/11] wait for active --- tests/integration/conftest.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 7142d7c..7ef145a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -104,12 +104,8 @@ async def nginx_integrator_app(ops_test: OpsTest): """Deploy nginx-ingress-integrator charm.""" nginx_integrator_app_name = "nginx-ingress-integrator" nginx_integrator_app = await ops_test.model.deploy(nginx_integrator_app_name, trust=True) - await ops_test.model.wait_for_idle() - assert ( - ops_test.model.applications[nginx_integrator_app_name].units[0].workload_status - == ActiveStatus.name - ) - yield nginx_integrator_app + await ops_test.model.wait_for_idle(apps=[nginx_integrator_app.name], wait_for_active=True) + return nginx_integrator_app @fixture(scope="module") From 0f0ff27c16d7a551243021b18d07284c13d3de8f Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Mon, 29 Apr 2024 23:47:16 +0800 Subject: [PATCH 07/11] remove wait for active --- tests/integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 7ef145a..e27f786 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -104,7 +104,7 @@ async def nginx_integrator_app(ops_test: OpsTest): """Deploy nginx-ingress-integrator charm.""" nginx_integrator_app_name = "nginx-ingress-integrator" nginx_integrator_app = await ops_test.model.deploy(nginx_integrator_app_name, trust=True) - await ops_test.model.wait_for_idle(apps=[nginx_integrator_app.name], wait_for_active=True) + await ops_test.model.wait_for_idle(apps=[nginx_integrator_app.name]) return nginx_integrator_app From 9413f243239c705061aeea5d03f997476dad888f Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 30 Apr 2024 22:49:43 +0900 Subject: [PATCH 08/11] remove wait for active --- tests/integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index e27f786..ec25412 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -144,7 +144,7 @@ async def app( config={"src-overwrite": json.dumps(any_charm_src_overwrite)}, ) await run_action(any_app_name, "rpc", method="start_server") - await ops_test.model.wait_for_idle(status="active") + await ops_test.model.wait_for_idle() application = await ops_test.model.deploy( charm_file, From 0d08c5fee23abbdd2142ab122a05d1dfccc3aee7 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 30 Apr 2024 23:15:32 +0900 Subject: [PATCH 09/11] wait for active in correct places --- tests/integration/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index ec25412..feb949f 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -162,9 +162,9 @@ async def app( apps = [app_name, nginx_integrator_app.name, any_app_name] await ops_test.model.add_relation(any_app_name, f"{app_name}:nginx-proxy") - await ops_test.model.wait_for_idle(apps=apps, status=ActiveStatus.name, timeout=60 * 5) + await ops_test.model.wait_for_idle(apps=apps) await ops_test.model.add_relation(nginx_integrator_app.name, f"{app_name}:nginx-route") - await ops_test.model.wait_for_idle(apps=apps, status=ActiveStatus.name, timeout=60 * 5) + await ops_test.model.wait_for_idle(apps=apps, wait_for_active=True) assert ops_test.model.applications[app_name].units[0].workload_status == ActiveStatus.name assert ops_test.model.applications[any_app_name].units[0].workload_status == ActiveStatus.name From 8b40d7a82befb36e241f054c65aec15f9a0fffc2 Mon Sep 17 00:00:00 2001 From: Tom Haddon Date: Tue, 30 Apr 2024 16:37:42 +0200 Subject: [PATCH 10/11] Don't check for active status until we've added the nginx-route relation --- tests/integration/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index feb949f..f11add3 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -162,7 +162,6 @@ async def app( apps = [app_name, nginx_integrator_app.name, any_app_name] await ops_test.model.add_relation(any_app_name, f"{app_name}:nginx-proxy") - await ops_test.model.wait_for_idle(apps=apps) await ops_test.model.add_relation(nginx_integrator_app.name, f"{app_name}:nginx-route") await ops_test.model.wait_for_idle(apps=apps, wait_for_active=True) From d9123f7fe42b24dfa11c89a3c37463a3da62f35c Mon Sep 17 00:00:00 2001 From: Tom Haddon Date: Tue, 30 Apr 2024 17:24:53 +0200 Subject: [PATCH 11/11] Query by unit rather than service - nii no longer includes service IP in message status --- tests/integration/conftest.py | 6 ------ tests/integration/test_core.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f11add3..c504dfb 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -195,9 +195,3 @@ async def ip_address_list(ops_test: OpsTest, app: Application, nginx_integrator_ async def ingress_ip(ip_address_list: List): """First match is the ingress IP.""" yield ip_address_list[0] - - -@pytest_asyncio.fixture(scope="module") -async def service_ip(ip_address_list: List): - """Last match is the service IP.""" - yield ip_address_list[-1] diff --git a/tests/integration/test_core.py b/tests/integration/test_core.py index cdb1f46..8c0f7a8 100644 --- a/tests/integration/test_core.py +++ b/tests/integration/test_core.py @@ -5,6 +5,7 @@ import re import secrets +from typing import List import juju.action import pytest @@ -59,15 +60,19 @@ async def test_an_app_cache_header(ingress_ip: str): @pytest.mark.asyncio @pytest.mark.abort_on_fail -async def test_service_reachable(service_ip: str): +async def test_unit_reachable(unit_ip_list: List): """ arrange: given charm has been built, deployed and related to a dependent application - act: when the dependent application is queried via the service + act: when the dependent application is queried via the unit assert: then the response is HTTP 200 OK. """ - response = requests.get(f"http://{service_ip}:8080", timeout=5) + # Check we are querying at least one unit. + assert len(unit_ip_list) > 0 - assert response.status_code == 200 + for unit_ip in unit_ip_list: + response = requests.get(f"http://{unit_ip}:8080", timeout=5) + + assert response.status_code == 200 async def test_report_visits_by_ip(app: Application):