diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index bc56aae5..098d6ea4 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -1,5 +1,7 @@ import logging +import os import platform +from pathlib import Path import pytest from utils import RESOURCES_DIR, Resource @@ -8,13 +10,19 @@ log = logging.getLogger(__name__) +BASES = { + "ubuntu@20.04": "focal", + "ubuntu@22.04": "jammy", + "ubuntu@24.04": "noble", +} + def pytest_addoption(parser): parser.addoption( "--base", type=str.lower, - default="ubuntu@22.04", - choices=["ubuntu@20.04", "ubuntu@22.04", "ubuntu@24.04"], + default="ubuntu@20.04", + choices=BASES.keys(), help="Set base for the applications.", ) @@ -146,3 +154,21 @@ def required_resources(resources: list[Resource], provided_collectors: set) -> l required_resources.append(resource) return required_resources + + +@pytest.fixture() +def charm_path(base: str) -> Path: + """Fixture to determine the charm path based on the base.""" + env_charm_path = f"CHARM_PATH_{BASES[base].upper()}" + path = os.getenv(env_charm_path) + + if not path: + raise EnvironmentError( + f"Environment variable '{env_charm_path}' is not set for base '{base}'." + ) + if not Path(path).exists(): + raise FileNotFoundError( + f"The path specified in '{env_charm_path}' ({path}) does not exist." + ) + + return Path(path) diff --git a/tests/functional/test_charm.py b/tests/functional/test_charm.py index 837665cd..aed738f1 100644 --- a/tests/functional/test_charm.py +++ b/tests/functional/test_charm.py @@ -56,17 +56,13 @@ class AppStatus(str, Enum): @pytest.mark.abort_on_fail @pytest.mark.skip_if_deployed async def test_build_and_deploy( # noqa: C901, function is too complex - ops_test: OpsTest, base, architecture, provided_collectors, required_resources + ops_test: OpsTest, base, architecture, provided_collectors, required_resources, charm_path ): - """Build the charm-under-test and deploy it together with related charms. + """Deploy the charm together with related charms. Assert on the unit status before any relations/configurations take place. Optionally attach required resources when testing with real hardware. """ - # Build and deploy charm from local source folder - charm = await ops_test.build_charm(".") - assert charm, "Charm was not built successfully." - # This is required for subordinate appliation to choose right revison # on different architecture. # See issue: https://bugs.launchpad.net/juju/+bug/2067749 @@ -77,7 +73,7 @@ async def test_build_and_deploy( # noqa: C901, function is too complex logger.info("Rendering bundle %s", bundle_template_path) bundle = ops_test.render_bundle( bundle_template_path, - charm=charm, + charm=charm_path, base=base, resources={ "storcli-deb": "empty-resource",