|
4 | 4 | # pylint: disable=unused-argument |
5 | 5 | """Fixtures for charm tests.""" |
6 | 6 |
|
7 | | -import pathlib |
8 | | -import subprocess # nosec B404 |
9 | 7 | import typing |
10 | 8 |
|
11 | 9 | import jubilant |
|
15 | 13 |
|
16 | 14 |
|
17 | 15 | @pytest.fixture(name="aproxy_charm_file", scope="session") |
18 | | -def aproxy_charm_file_fixture(pytestconfig: pytest.Config) -> str: |
19 | | - """Build or get the aproxy charm file. |
| 16 | +def aproxy_charm_file_fixture(charm_paths: dict, pytestconfig: pytest.Config) -> str: |
| 17 | + """Return the path to the built aproxy charm for the requested base. |
| 18 | +
|
| 19 | + The ``charm_paths`` fixture is provided by the opcli (canonical/charm-ci) |
| 20 | + pytest plugin and resolves builds from ``artifacts.build.yaml`` for the |
| 21 | + current architecture. |
20 | 22 |
|
21 | 23 | Args: |
| 24 | + charm_paths: Mapping of charm name to its per-base build paths. |
22 | 25 | pytestconfig: Pytest configuration object. |
23 | 26 |
|
24 | 27 | Returns: |
25 | | - Path to the built or provided aproxy charm file. |
| 28 | + Path to the built aproxy charm file for the requested base. |
26 | 29 | """ |
27 | | - charms = pytestconfig.getoption("--charm-file") |
28 | 30 | base = pytestconfig.getoption("--base") |
29 | | - |
30 | | - if charms: |
31 | | - # Filter by requested base |
32 | | - matching_charms = [file for file in charms if base in file] |
33 | | - if matching_charms: |
34 | | - return matching_charms[0] |
35 | | - raise AssertionError(f"No matching charm found for base {base}.") |
36 | | - |
37 | | - # Otherwise, build the charm for the requested base |
38 | | - base_index_map = {"20.04": 0, "22.04": 1, "24.04": 2} |
39 | | - bases_index = base_index_map.get(base, 2) |
40 | | - |
41 | | - try: |
42 | | - subprocess.run( # nosec B603 |
43 | | - ["/usr/bin/charmcraft", "pack", f"--bases-index={bases_index}"], |
44 | | - check=True, |
45 | | - capture_output=True, |
46 | | - text=True, |
47 | | - ) |
48 | | - except subprocess.CalledProcessError as exc: |
49 | | - raise OSError(f"Error packing charm: {exc}; Stderr:\n{exc.stderr}") from None |
50 | | - |
51 | | - charm_path = pathlib.Path(__file__).parent.parent.parent |
52 | | - charms = [p.absolute() for p in charm_path.glob("aproxy_*.charm")] |
53 | | - # Filter for the requested base |
54 | | - matching_charms = [c for c in charms if base in str(c)] |
55 | | - if matching_charms: |
56 | | - return str(matching_charms[0]) |
57 | | - raise AssertionError(f"No matching charm found for base {base}.") |
| 31 | + return str(charm_paths["aproxy"][f"ubuntu@{base}"]) |
58 | 32 |
|
59 | 33 |
|
60 | 34 | @pytest.fixture(name="juju", scope="module") |
|
0 commit comments