Skip to content

Commit

Permalink
Add architecture integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclert-canonical committed Dec 13, 2024
1 parent e03fc8c commit a7836d9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See LICENSE file for licensing details.

import argparse
import subprocess

import pytest

Expand Down Expand Up @@ -32,6 +33,30 @@ def pytest_configure(config):
config.option.mysql_router_charm_bases_index = 1


@pytest.fixture(autouse=True)
def architecture() -> str:
return subprocess.run(
["dpkg", "--print-architecture"],
capture_output=True,
check=True,
encoding="utf-8",
).stdout.strip()


@pytest.fixture
def only_amd64(architecture):
"""Pretty way to skip ARM tests."""
if architecture != "amd64":
pytest.skip("Requires amd64 architecture")


@pytest.fixture
def only_arm64(architecture):
"""Pretty way to skip AMD tests."""
if architecture != "arm64":
pytest.skip("Requires arm64 architecture")


@pytest.fixture
def only_with_juju_secrets(juju_has_secrets):
"""Pretty way to skip Juju 3 tests."""
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import logging
import subprocess
import tempfile
from typing import Dict, List, Optional
from pathlib import Path
from typing import Dict, List, Optional, Union

import tenacity
import yaml
from juju.model import Model
from juju.unit import Unit
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -486,3 +488,17 @@ async def get_machine_address(ops_test: OpsTest, unit: Unit) -> str:
return line.split()[2]

assert False, "Unable to find the unit's machine"


async def get_charm(charm_path: Union[str, Path], architecture: str, bases_index: int) -> Path:
"""Fetches packed charm from CI runner without checking for architecture."""
charm_path = Path(charm_path)
charmcraft_yaml = yaml.safe_load((charm_path / "charmcraft.yaml").read_text())
assert charmcraft_yaml["type"] == "charm"

base = charmcraft_yaml["bases"][bases_index]
build_on = base.get("build-on", [base])[0]
version = build_on["channel"]
packed_charms = list(charm_path.glob(f"*{version}-{architecture}.charm"))

return packed_charms[0].resolve(strict=True)
52 changes: 52 additions & 0 deletions tests/integration/test_architecture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import pytest
from pytest_operator.plugin import OpsTest

from .helpers import get_charm

MYSQL_ROUTER_APP_NAME = "mysql-router"


@pytest.mark.group(1)
@pytest.mark.usefixtures("only_amd64")
async def test_arm_charm_on_amd_host(ops_test: OpsTest) -> None:
"""Tries deploying an arm64 charm on amd64 host."""
charm = await get_charm(".", "arm64", 2)

await ops_test.model.deploy(
charm,
application_name=MYSQL_ROUTER_APP_NAME,
num_units=1,
config={"profile": "testing"},
base="[email protected]",
)

await ops_test.model.wait_for_idle(
apps=[MYSQL_ROUTER_APP_NAME],
status="error",
raise_on_error=False,
)


@pytest.mark.group(1)
@pytest.mark.usefixtures("only_arm64")
async def test_amd_charm_on_arm_host(ops_test: OpsTest) -> None:
"""Tries deploying an amd64 charm on arm64 host."""
charm = await get_charm(".", "amd64", 1)

await ops_test.model.deploy(
charm,
application_name=MYSQL_ROUTER_APP_NAME,
num_units=1,
config={"profile": "testing"},
base="[email protected]",
)

await ops_test.model.wait_for_idle(
apps=[MYSQL_ROUTER_APP_NAME],
status="error",
raise_on_error=False,
)

0 comments on commit a7836d9

Please sign in to comment.