Skip to content

Commit aeaa27f

Browse files
test: use jubilant for integration (#719)
1 parent b2ea49f commit aeaa27f

4 files changed

Lines changed: 40 additions & 35 deletions

File tree

tests/integration/test_charm_fork_path_change.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
import logging
1010

11+
import jubilant
1112
import pytest
1213
from github.Repository import Repository
1314
from juju.application import Application
14-
from juju.model import Model
15-
from ops.model import ActiveStatus
1615

1716
from charm_state import PATH_CONFIG_NAME
1817
from tests.integration.conftest import GitHubConfig
@@ -26,7 +25,7 @@
2625
@pytest.mark.asyncio
2726
@pytest.mark.abort_on_fail
2827
async def test_path_config_change(
29-
model: Model,
28+
juju: jubilant.Juju,
3029
app_with_forked_repo: Application,
3130
github_repository: Repository,
3231
github_config: GitHubConfig,
@@ -38,16 +37,18 @@ async def test_path_config_change(
3837
assert: No runners connected to the forked repository and one runner in the main repository.
3938
"""
4039
logger.info("test_path_config_change")
41-
await model.wait_for_idle(
42-
apps=[app_with_forked_repo.name], status=ActiveStatus.name, idle_period=30, timeout=10 * 60
40+
juju.wait(
41+
lambda status: jubilant.all_active(status, app_with_forked_repo.name),
42+
delay=10,
43+
timeout=10 * 60,
4344
)
4445

4546
unit = app_with_forked_repo.units[0]
4647

4748
logger.info("Ensure there is a runner (this calls reconcile)")
4849
await instance_helper.ensure_charm_has_runner(app_with_forked_repo)
4950

50-
await app_with_forked_repo.set_config({PATH_CONFIG_NAME: github_config.path})
51+
juju.config(app_with_forked_repo.name, values={PATH_CONFIG_NAME: github_config.path})
5152

5253
logger.info("Reconciling (again)")
5354
await wait_for_runner_ready(app=app_with_forked_repo)

tests/integration/test_charm_metrics_failure.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from asyncio import sleep
88
from typing import AsyncIterator
99

10+
import jubilant
1011
import pytest
1112
import pytest_asyncio
1213
from github.Branch import Branch
@@ -30,18 +31,16 @@
3031

3132

3233
@pytest_asyncio.fixture(scope="function", name="app")
33-
async def app_fixture(app_for_metric: Application) -> AsyncIterator[Application]:
34+
async def app_fixture(
35+
juju: jubilant.Juju, app_for_metric: Application
36+
) -> AsyncIterator[Application]:
3437
"""Setup and teardown the charm after each test.
3538
3639
Clear the metrics log before each test.
3740
"""
3841
unit = app_for_metric.units[0]
3942
await clear_metrics_log(unit)
40-
await app_for_metric.set_config(
41-
{
42-
BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0",
43-
}
44-
)
43+
juju.config(app_for_metric.name, values={BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0"})
4544
await wait_for_reconcile(app=app_for_metric)
4645

4746
yield app_for_metric
@@ -51,6 +50,7 @@ async def app_fixture(app_for_metric: Application) -> AsyncIterator[Application]
5150
@pytest.mark.asyncio
5251
@pytest.mark.abort_on_fail
5352
async def test_charm_issues_metrics_for_abnormal_termination(
53+
juju: jubilant.Juju,
5454
app: Application,
5555
github_repository: Repository,
5656
test_github_branch: Branch,
@@ -62,8 +62,8 @@ async def test_charm_issues_metrics_for_abnormal_termination(
6262
assert: The RunnerStart, RunnerStop and Reconciliation metric is logged.
6363
The Reconciliation metric has the post job status set to Abnormal.
6464
"""
65-
await app.set_config({PATH_CONFIG_NAME: github_repository.full_name})
66-
await app.set_config({BASE_VIRTUAL_MACHINES_CONFIG_NAME: "1"})
65+
juju.config(app.name, values={PATH_CONFIG_NAME: github_repository.full_name})
66+
juju.config(app.name, values={BASE_VIRTUAL_MACHINES_CONFIG_NAME: "1"})
6767
await instance_helper.ensure_charm_has_runner(app)
6868

6969
unit = app.units[0]

tests/integration/test_charm_metrics_success.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import json
77
from typing import AsyncIterator
88

9+
import jubilant
910
import pytest
1011
import pytest_asyncio
1112
from github.Branch import Branch
1213
from github.Repository import Repository
1314
from github_runner_manager.manager.vm_manager import PostJobStatus
1415
from juju.application import Application
15-
from juju.model import Model
1616

1717
from charm_state import BASE_VIRTUAL_MACHINES_CONFIG_NAME
1818
from tests.integration.helpers.charm_metrics import (
@@ -29,7 +29,7 @@
2929

3030

3131
@pytest_asyncio.fixture(scope="function", name="app")
32-
async def app_fixture(model: Model, app_for_metric: Application) -> AsyncIterator[Application]:
32+
async def app_fixture(app_for_metric: Application) -> AsyncIterator[Application]:
3333
"""Setup and teardown the charm after each test.
3434
3535
Clear the metrics log before each test.
@@ -44,7 +44,7 @@ async def app_fixture(model: Model, app_for_metric: Application) -> AsyncIterato
4444
@pytest.mark.asyncio
4545
@pytest.mark.abort_on_fail
4646
async def test_charm_issues_runner_installed_metric(
47-
app: Application, instance_helper: OpenStackInstanceHelper
47+
juju: jubilant.Juju, app: Application, instance_helper: OpenStackInstanceHelper
4848
):
4949
"""
5050
arrange: A working charm deployment.
@@ -54,7 +54,7 @@ async def test_charm_issues_runner_installed_metric(
5454
await instance_helper.ensure_charm_has_runner(app)
5555

5656
# Set the number of virtual machines to 0 to speedup reconciliation
57-
await app.set_config({BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0"})
57+
juju.config(app.name, values={BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0"})
5858
await wait_for_reconcile(app=app)
5959

6060
metrics_log = await get_metrics_log(app.units[0])
@@ -73,6 +73,7 @@ async def test_charm_issues_runner_installed_metric(
7373
@pytest.mark.asyncio
7474
@pytest.mark.abort_on_fail
7575
async def test_charm_issues_metrics_after_reconciliation(
76+
juju: jubilant.Juju,
7677
app: Application,
7778
github_repository: Repository,
7879
test_github_branch: Branch,
@@ -98,7 +99,7 @@ async def test_charm_issues_metrics_after_reconciliation(
9899
)
99100

100101
# Set the number of virtual machines to 0 to speedup reconciliation
101-
await app.set_config({BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0"})
102+
juju.config(app.name, values={BASE_VIRTUAL_MACHINES_CONFIG_NAME: "0"})
102103
await wait_for_reconcile(app=app)
103104

104105
await assert_events_after_reconciliation(

tests/integration/test_charm_upgrade.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import functools
77
import pathlib
88

9+
import jubilant
910
import pytest
1011
from juju.application import Application
1112
from juju.client import client
1213
from juju.model import Model
13-
from pytest_operator.plugin import OpsTest
1414

1515
from charm_state import (
1616
BASE_VIRTUAL_MACHINES_CONFIG_NAME,
@@ -32,8 +32,8 @@
3232

3333
@pytest.mark.asyncio
3434
async def test_charm_upgrade(
35+
juju: jubilant.Juju,
3536
model: Model,
36-
ops_test: OpsTest,
3737
charm_file: str,
3838
app_name: str,
3939
github_config: GitHubConfig,
@@ -48,20 +48,23 @@ async def test_charm_upgrade(
4848
"""
4949
latest_edge_path = tmp_path / "github-runner.charm"
5050
# download the charm
51-
retcode, stdout, stderr = await ops_test.juju(
52-
"download",
53-
"github-runner",
54-
# do not specify revision
55-
# --revision cannot be specified together with --arch, --base, --channel
56-
"--channel",
57-
"latest/edge",
58-
"--series",
59-
"jammy",
60-
"--filepath",
61-
str(latest_edge_path),
62-
"--no-progress",
63-
)
64-
assert retcode == 0, f"failed to download charm, {stdout} {stderr}"
51+
try:
52+
juju.cli(
53+
"download",
54+
"github-runner",
55+
# do not specify revision
56+
# --revision cannot be specified together with --arch, --base, --channel
57+
"--channel",
58+
"latest/edge",
59+
"--series",
60+
"jammy",
61+
"--filepath",
62+
str(latest_edge_path),
63+
"--no-progress",
64+
include_model=False,
65+
)
66+
except jubilant.CLIError as exc:
67+
pytest.fail(f"failed to download charm, {exc}")
6568

6669
# deploy latest edge version of the charm
6770
application = await deploy_github_runner_charm(

0 commit comments

Comments
 (0)