Skip to content

Commit

Permalink
Add redeployment doc (#75)
Browse files Browse the repository at this point in the history
* add redeployment doc

* Update docs/reference/charm-redeployment.md

Co-authored-by: Yanks Yoon <[email protected]>

* fix: integration test pytest compatibility

* fix: add comment for pytest pin

* revert pytest pin(fixed)

* wait for active

* remove wait for active

* remove wait for active

* wait for active in correct places

* Don't check for active status until we've added the nginx-route relation

* Query by unit rather than service - nii no longer includes service IP in message status

---------

Co-authored-by: mthaddon <[email protected]>
Co-authored-by: Yanks Yoon <[email protected]>
Co-authored-by: charlie4284 <[email protected]>
  • Loading branch information
4 people authored Apr 30, 2024
1 parent 49a8b90 commit 48a7da9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
5 changes: 5 additions & 0 deletions docs/reference/charm-redeployment.md
Original file line number Diff line number Diff line change
@@ -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.
Hence going through a normal deployment process using the same configuration options and relations
as your original deployment will suffice.
19 changes: 4 additions & 15 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
return nginx_integrator_app


@fixture(scope="module")
Expand Down Expand Up @@ -148,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,
Expand All @@ -166,9 +162,8 @@ 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.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
Expand Down Expand Up @@ -200,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]
4 changes: 1 addition & 3 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
requests
pytest-operator
python-keystoneclient
python-swiftclient
Pillow
pytest
pytest-cov

13 changes: 9 additions & 4 deletions tests/integration/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import re
import secrets
from typing import List

import juju.action
import pytest
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ commands =
[testenv:integration]
description = Run integration tests
deps =
pytest
pytest-cov
pytest-operator
# Last compatible version with Juju 2.9
juju==3.0.4
-r{toxinidir}/requirements.txt
Expand Down

0 comments on commit 48a7da9

Please sign in to comment.