Skip to content

Commit 332cdb6

Browse files
[DPE-5588] Check against invalid arch (#563)
1 parent c1acb20 commit 332cdb6

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

src/charm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
"""Charmed Machine Operator for MySQL."""
66

7+
from charms.mysql.v0.architecture import WrongArchitectureWarningCharm, is_wrong_architecture
8+
from ops.main import main
9+
10+
if is_wrong_architecture() and __name__ == "__main__":
11+
main(WrongArchitectureWarningCharm)
12+
713
import logging
814
import random
915
import socket
@@ -55,7 +61,6 @@
5561
Unit,
5662
WaitingStatus,
5763
)
58-
from ops.main import main
5964
from tenacity import (
6065
RetryError,
6166
Retrying,

tests/integration/helpers.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import string
99
import subprocess
1010
import tempfile
11-
from typing import Dict, List, Optional, Set
11+
from pathlib import Path
12+
from typing import Dict, List, Optional, Set, Union
1213

1314
import juju.unit
1415
import yaml
@@ -979,3 +980,17 @@ def get_unit_by_index(app_name: str, units: list, index: int):
979980
for unit in units:
980981
if unit.name == f"{app_name}/{index}":
981982
return unit
983+
984+
985+
async def get_charm(charm_path: Union[str, Path], architecture: str, bases_index: int) -> Path:
986+
"""Fetches packed charm from CI runner without checking for architecture."""
987+
charm_path = Path(charm_path)
988+
charmcraft_yaml = yaml.safe_load((charm_path / "charmcraft.yaml").read_text())
989+
assert charmcraft_yaml["type"] == "charm"
990+
991+
base = charmcraft_yaml["bases"][bases_index]
992+
build_on = base.get("build-on", [base])[0]
993+
version = build_on["channel"]
994+
packed_charms = list(charm_path.glob(f"*{version}-{architecture}.charm"))
995+
996+
return packed_charms[0].resolve(strict=True)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2024 Canonical Ltd.
3+
# See LICENSE file for licensing details.
4+
5+
import pytest
6+
from pytest_operator.plugin import OpsTest
7+
8+
from . import markers
9+
from .helpers import get_charm
10+
11+
MYSQL_APP_NAME = "mysql"
12+
13+
14+
@pytest.mark.group(1)
15+
@markers.amd64_only
16+
async def test_arm_charm_on_amd_host(ops_test: OpsTest) -> None:
17+
"""Tries deploying an arm64 charm on amd64 host."""
18+
charm = await get_charm(".", "arm64", 1)
19+
20+
await ops_test.model.deploy(
21+
charm,
22+
application_name=MYSQL_APP_NAME,
23+
num_units=1,
24+
config={"profile": "testing"},
25+
26+
)
27+
28+
await ops_test.model.wait_for_idle(
29+
apps=[MYSQL_APP_NAME],
30+
status="error",
31+
raise_on_error=False,
32+
)
33+
34+
35+
@pytest.mark.group(1)
36+
@markers.arm64_only
37+
async def test_amd_charm_on_arm_host(ops_test: OpsTest) -> None:
38+
"""Tries deploying an amd64 charm on arm64 host."""
39+
charm = await get_charm(".", "amd64", 0)
40+
41+
await ops_test.model.deploy(
42+
charm,
43+
application_name=MYSQL_APP_NAME,
44+
num_units=1,
45+
config={"profile": "testing"},
46+
47+
)
48+
49+
await ops_test.model.wait_for_idle(
50+
apps=[MYSQL_APP_NAME],
51+
status="error",
52+
raise_on_error=False,
53+
)

0 commit comments

Comments
 (0)