From 2f48e633aa877a0d279180790da56e143d693146 Mon Sep 17 00:00:00 2001 From: Yanks Yoon <37652070+yanksyoon@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:44:19 +0800 Subject: [PATCH] fix: juju 3.1 compatible cos stack (#70) * fix: juju 2.9 compatible cos stack * fix: use model * fix: cos stack revisions to juju 2.9 compatible * fix: juju lib version to 2.9 compatible libs * chore: add json schema pkg dep for ingress lib * chore: remove jsonschema dependency that cannot be built by charmcraft * fix: update updated juju lib syntax * fix: juju 3.1 based jenkins * chore: use strict microk8s for juju 3.1 * chore: update microk8s group to snap mk8s group * test: fix jenkins auto update test fix for juju 3.1 * ci: update microk8s version --- .github/workflows/integration_test.yaml | 9 ++++--- tests/integration/conftest.py | 34 ++++++++++++------------- tests/integration/pre_run_script.sh | 6 ++--- tests/integration/test_jenkins.py | 14 +++++----- tox.ini | 2 +- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.github/workflows/integration_test.yaml b/.github/workflows/integration_test.yaml index 93aed98a..85cbae0f 100644 --- a/.github/workflows/integration_test.yaml +++ b/.github/workflows/integration_test.yaml @@ -8,11 +8,12 @@ jobs: uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main secrets: inherit with: + channel: 1.28-strict/stable + extra-arguments: | + --kube-config ${GITHUB_WORKSPACE}/kube-config + modules: '["test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]' pre-run-script: | -c "sudo microk8s config > ${GITHUB_WORKSPACE}/kube-config chmod +x tests/integration/pre_run_script.sh ./tests/integration/pre_run_script.sh" - extra-arguments: | - --kube-config ${GITHUB_WORKSPACE}/kube-config - modules: '["test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]' - + juju-channel: 3.1/stable diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 6e55ecf6..7a859798 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -172,7 +172,7 @@ async def jenkins_k8s_agents_fixture( yield agent_app - await model.remove_application(agent_app.name, block_until_done=True, force=True) + await model.remove_application(agent_app.name, block_until_done=True) @pytest_asyncio.fixture(scope="function", name="k8s_agent_related_app") @@ -474,7 +474,7 @@ async def jenkins_with_proxy_fixture( async with ops_test.fast_forward(fast_interval="5h"): yield application - await model_with_proxy.remove_application(application.name, force=True, block_until_done=True) + await model_with_proxy.remove_application(application.name, block_until_done=True) @pytest_asyncio.fixture(scope="module", name="proxy_jenkins_unit_ip") @@ -589,14 +589,14 @@ async def ldap_server_ip_fixture( @pytest_asyncio.fixture(scope="module", name="prometheus_related") -async def prometheus_related_fixture(application: Application): +async def prometheus_related_fixture(application: Application, model: Model): """The prometheus-k8s application related to Jenkins via metrics-endpoint relation.""" - prometheus = await application.model.deploy("prometheus-k8s", channel="1.0/stable", trust=True) - await application.model.wait_for_idle( + prometheus = await model.deploy("prometheus-k8s", channel="1.0/stable", trust=True) + await model.wait_for_idle( status="active", apps=[prometheus.name], raise_on_error=False, timeout=30 * 60 ) - await application.model.add_relation(f"{application.name}:metrics-endpoint", prometheus.name) - await application.model.wait_for_idle( + await model.add_relation(f"{application.name}:metrics-endpoint", prometheus.name) + await model.wait_for_idle( status="active", apps=[prometheus.name, application.name], timeout=20 * 60, @@ -607,14 +607,14 @@ async def prometheus_related_fixture(application: Application): @pytest_asyncio.fixture(scope="module", name="loki_related") -async def loki_related_fixture(application: Application): +async def loki_related_fixture(application: Application, model: Model): """The loki-k8s application related to Jenkins via logging relation.""" - loki = await application.model.deploy("loki-k8s", channel="1.0/stable", trust=True) - await application.model.wait_for_idle( + loki = await model.deploy("loki-k8s", channel="1.0/stable", trust=True) + await model.wait_for_idle( status="active", apps=[loki.name], raise_on_error=False, timeout=30 * 60 ) - await application.model.add_relation(f"{application.name}:logging", loki.name) - await application.model.wait_for_idle( + await model.add_relation(f"{application.name}:logging", loki.name) + await model.wait_for_idle( status="active", apps=[loki.name, application.name], timeout=20 * 60, @@ -625,14 +625,14 @@ async def loki_related_fixture(application: Application): @pytest_asyncio.fixture(scope="module", name="grafana_related") -async def grafana_related_fixture(application: Application): +async def grafana_related_fixture(application: Application, model: Model): """The grafana-k8s application related to Jenkins via grafana-dashboard relation.""" - grafana = await application.model.deploy("grafana-k8s", channel="1.0/stable", trust=True) - await application.model.wait_for_idle( + grafana = await model.deploy("grafana-k8s", channel="1.0/stable", trust=True) + await model.wait_for_idle( status="active", apps=[grafana.name], raise_on_error=False, timeout=30 * 60 ) - await application.model.add_relation(f"{application.name}:grafana-dashboard", grafana.name) - await application.model.wait_for_idle( + await model.add_relation(f"{application.name}:grafana-dashboard", grafana.name) + await model.wait_for_idle( status="active", apps=[grafana.name, application.name], timeout=20 * 60, diff --git a/tests/integration/pre_run_script.sh b/tests/integration/pre_run_script.sh index d4d58f5f..ef7171c4 100644 --- a/tests/integration/pre_run_script.sh +++ b/tests/integration/pre_run_script.sh @@ -13,8 +13,8 @@ TESTING_MODEL="$(juju switch)" # lxd should be install and init by a previous step in integration test action. echo "bootstrapping lxd juju controller" -sg microk8s -c "microk8s status --wait-ready" -sg microk8s -c "juju bootstrap localhost localhost" +sg snap_microk8s -c "microk8s status --wait-ready" +sg snap_microk8s -c "juju bootstrap localhost localhost" echo "Switching to testing model" -sg microk8s -c "juju switch $TESTING_MODEL" +sg snap_microk8s -c "juju switch $TESTING_MODEL" diff --git a/tests/integration/test_jenkins.py b/tests/integration/test_jenkins.py index 32cb3916..445bb196 100644 --- a/tests/integration/test_jenkins.py +++ b/tests/integration/test_jenkins.py @@ -48,14 +48,14 @@ async def test_jenkins_automatic_update_out_of_range( """ extra_plugin = "oic-auth" await install_plugins(ops_test, unit_web_client.unit, unit_web_client.client, (extra_plugin,)) - ret_code, _, stderr = await ops_test.juju( - "run", - "--unit", - unit_web_client.unit.name, - "--", - f"{' '.join(libfaketime_env)} {' '.join(update_status_env)} ./dispatch", + action: Action = await unit_web_client.unit.run( + f"-- {' '.join(libfaketime_env)} {' '.join(update_status_env)} ./dispatch" ) - assert not ret_code, f"Failed to execute update-status-hook, {stderr}" + await action.wait() + assert ( + action.status == "completed" + ), f"Failed to execute update-status-hook, {action.data['message']}" + assert unit_web_client.client.has_plugin( extra_plugin ), "additionally installed plugin cleanedup." diff --git a/tox.ini b/tox.ini index b6484ec8..7b7cf0f6 100644 --- a/tox.ini +++ b/tox.ini @@ -104,7 +104,7 @@ commands = description = Run integration tests deps = pytest - juju==3.0.4 + juju>=3,<4 ops pytest-operator pytest-asyncio