Skip to content

Commit

Permalink
Run integration tests on arm64 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored May 30, 2024
1 parent 2a3136a commit 6950ba8
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 47 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ jobs:
juju:
- agent: 2.9.49 # renovate: latest juju 2
libjuju: ==2.9.49.0 # renovate: latest libjuju 2
allure: false
allure_on_amd64: false
- agent: 3.1.8 # renovate: latest juju 3
allure: true
name: Integration test charm | ${{ matrix.juju.agent }}
allure_on_amd64: true
architecture:
- amd64
- arm64
name: Integration test charm | ${{ matrix.juju.agent }} | ${{ matrix.architecture }}
needs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
architecture: ${{ matrix.architecture }}
cloud: lxd
juju-agent-version: ${{ matrix.juju.agent }}
libjuju-version-constraint: ${{ matrix.juju.libjuju }}
_beta_allure_report: ${{ matrix.juju.allure }}
_beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }}
permissions:
contents: write # Needed for Allure Report beta
secrets:
Expand Down
11 changes: 0 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/integration/architecture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
import subprocess

architecture = subprocess.run(
["dpkg", "--print-architecture"], capture_output=True, check=True, encoding="utf-8"
).stdout.strip()
17 changes: 15 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@
from pytest_operator.plugin import OpsTest
from tenacity import Retrying, stop_after_delay, wait_fixed

from . import architecture
from .helpers.helpers import CLIENT_APP_NAME
from .helpers.postgresql_helpers import get_leader_unit


@pytest.fixture(scope="module")
async def pgb_charm_focal(ops_test: OpsTest):
"""Build the pgbouncer charm."""
return await ops_test.build_charm(".", bases_index=0)
if architecture.architecture == "amd64":
index = 0
elif architecture.architecture == "arm64":
index = 1
else:
raise ValueError(architecture.architecture)
return await ops_test.build_charm(".", bases_index=index)


@pytest.fixture(scope="module")
async def pgb_charm_jammy(ops_test: OpsTest):
"""Build the pgbouncer charm."""
return await ops_test.build_charm(".", bases_index=2)
if architecture.architecture == "amd64":
index = 2
elif architecture.architecture == "arm64":
index = 3
else:
raise ValueError(architecture.architecture)
return await ops_test.build_charm(".", bases_index=index)


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers/postgresql_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from juju.unit import Unit
from pytest_operator.plugin import OpsTest

from tests.integration.helpers.helpers import PG
from .helpers import PG


async def build_connection_string(
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

import pytest

from . import architecture
from .juju_ import juju_major_version

juju2 = pytest.mark.skipif(juju_major_version != 2, reason="Requires juju 2")
juju3 = pytest.mark.skipif(juju_major_version != 3, reason="Requires juju 3")
juju_secrets = pytest.mark.skipif(juju_major_version < 3, reason="Requires juju secrets")
amd64_only = pytest.mark.skipif(
architecture.architecture != "amd64", reason="Requires amd64 architecture"
)
arm64_only = pytest.mark.skipif(
architecture.architecture != "arm64", reason="Requires arm64 architecture"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,33 @@
from pytest_operator.plugin import OpsTest

from constants import BACKEND_RELATION_NAME
from tests.integration.helpers.helpers import (

from ... import architecture
from ...helpers.helpers import (
PG,
PGB,
)
from tests.integration.juju_ import juju_major_version
from tests.integration.relations.pgbouncer_provider.helpers import check_exposed_connection
from ...juju_ import juju_major_version
from .helpers import check_exposed_connection

logger = logging.getLogger(__name__)

DATA_INTEGRATOR_APP_NAME = "data-integrator"

if juju_major_version < 3:
TLS_CERTIFICATES_APP_NAME = "tls-certificates-operator"
TLS_CHANNEL = "legacy/stable"
TLS_CONFIG = {"generate-self-signed-certificates": "true", "ca-common-name": "Test CA"}
tls_certificates_app_name = "tls-certificates-operator"
if architecture.architecture == "arm64":
tls_channel = "legacy/edge"
else:
tls_channel = "legacy/stable"
tls_config = {"generate-self-signed-certificates": "true", "ca-common-name": "Test CA"}
else:
TLS_CERTIFICATES_APP_NAME = "self-signed-certificates"
TLS_CHANNEL = "latest/stable"
TLS_CONFIG = {"ca-common-name": "Test CA"}
tls_certificates_app_name = "self-signed-certificates"
if architecture.architecture == "arm64":
tls_channel = "latest/edge"
else:
tls_channel = "latest/stable"
tls_config = {"ca-common-name": "Test CA"}


async def fetch_action_get_credentials(unit: Unit) -> Dict:
Expand Down Expand Up @@ -72,7 +80,7 @@ async def test_deploy_and_relate(ops_test: OpsTest, pgb_charm_jammy):
config=config,
),
ops_test.model.deploy(
TLS_CERTIFICATES_APP_NAME, config=TLS_CONFIG, channel=TLS_CHANNEL
tls_certificates_app_name, config=tls_config, channel=tls_channel
),
)
await ops_test.model.add_relation(f"{PGB}:{BACKEND_RELATION_NAME}", f"{PG}:database")
Expand All @@ -88,7 +96,7 @@ async def test_deploy_and_relate(ops_test: OpsTest, pgb_charm_jammy):

@pytest.mark.group(1)
async def test_add_tls(ops_test: OpsTest, pgb_charm_jammy):
await ops_test.model.add_relation(PGB, TLS_CERTIFICATES_APP_NAME)
await ops_test.model.add_relation(PGB, tls_certificates_app_name)
await ops_test.model.wait_for_idle(status="active")

credentials = await fetch_action_get_credentials(
Expand All @@ -100,7 +108,7 @@ async def test_add_tls(ops_test: OpsTest, pgb_charm_jammy):
@pytest.mark.group(1)
async def test_remove_tls(ops_test: OpsTest, pgb_charm_jammy):
await ops_test.model.applications[PGB].remove_relation(
f"{PGB}:certificates", f"{TLS_CERTIFICATES_APP_NAME}:certificates"
f"{PGB}:certificates", f"{tls_certificates_app_name}:certificates"
)
await ops_test.model.wait_for_idle(status="active")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from pytest_operator.plugin import OpsTest

from constants import BACKEND_RELATION_NAME, PEER_RELATION_NAME
from tests.integration.helpers.helpers import (

from ...helpers.helpers import (
CLIENT_APP_NAME,
FIRST_DATABASE_RELATION_NAME,
PG,
Expand All @@ -23,8 +24,8 @@
get_cfg,
scale_application,
)
from tests.integration.helpers.postgresql_helpers import check_database_users_existence
from tests.integration.relations.pgbouncer_provider.helpers import (
from ...helpers.postgresql_helpers import check_database_users_existence
from .helpers import (
build_connection_string,
check_new_relation,
get_application_relation_data,
Expand Down
11 changes: 8 additions & 3 deletions tests/integration/relations/test_backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from pytest_operator.plugin import OpsTest
from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed

from tests.integration.helpers.helpers import (
from .. import architecture
from ..helpers.helpers import (
CLIENT_APP_NAME,
FIRST_DATABASE_RELATION_NAME,
MAILMAN3,
Expand All @@ -22,7 +23,7 @@
run_command_on_unit,
wait_for_relation_removed_between,
)
from tests.integration.helpers.postgresql_helpers import (
from ..helpers.postgresql_helpers import (
check_database_users_existence,
get_postgres_primary,
)
Expand All @@ -31,6 +32,10 @@

TLS = "tls-certificates-operator"
RELATION = "backend-database"
if architecture.architecture == "arm64":
tls_channel = "legacy/edge"
else:
tls_channel = "latest/stable"


@pytest.mark.group(1)
Expand Down Expand Up @@ -94,7 +99,7 @@ async def test_tls_encrypted_connection_to_postgres(ops_test: OpsTest, pgb_charm

# Deploy TLS Certificates operator.
config = {"generate-self-signed-certificates": "true", "ca-common-name": "Test CA"}
await ops_test.model.deploy(TLS, config=config)
await ops_test.model.deploy(TLS, config=config, channel=tls_channel)
await ops_test.model.wait_for_idle(apps=[TLS], status="active", timeout=1000)

# Relate it to the PostgreSQL to enable TLS.
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/relations/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from tenacity import Retrying, stop_after_attempt, wait_fixed

from constants import EXTENSIONS_BLOCKING_MESSAGE
from tests.integration.helpers.helpers import (

from ..helpers.helpers import (
CLIENT_APP_NAME,
MAILMAN3,
PG,
Expand All @@ -21,7 +22,7 @@
get_legacy_relation_username,
run_command_on_unit,
)
from tests.integration.helpers.postgresql_helpers import (
from ..helpers.postgresql_helpers import (
check_database_users_existence,
check_databases_creation,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relations/test_db_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import Retrying, stop_after_attempt, wait_fixed

from tests.integration.helpers.helpers import (
from ..helpers.helpers import (
PG,
PGB,
deploy_and_relate_application_with_pgbouncer_bundle,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/relations/test_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from pytest_operator.plugin import OpsTest

from constants import BACKEND_RELATION_NAME
from tests.integration.helpers.helpers import (

from ..helpers.helpers import (
CLIENT_APP_NAME,
FIRST_DATABASE_RELATION_NAME,
PG,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/unit/relations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
3 changes: 2 additions & 1 deletion tests/unit/relations/test_backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from charm import PgBouncerCharm
from constants import BACKEND_RELATION_NAME, PEER_RELATION_NAME, PGB_CONF_DIR
from tests.helpers import patch_network_get

from ..helpers import patch_network_get


@patch_network_get(private_address="1.1.1.1")
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/relations/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
from unittest.mock import Mock, PropertyMock, patch, sentinel

from charms.pgbouncer_k8s.v0.pgb import parse_dict_to_kv_string
from ops.model import Unit
from ops.testing import Harness

Expand All @@ -14,8 +15,8 @@
DB_RELATION_NAME,
PEER_RELATION_NAME,
)
from lib.charms.pgbouncer_k8s.v0.pgb import parse_dict_to_kv_string
from tests.helpers import patch_network_get

from ..helpers import patch_network_get


class TestDb(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/relations/test_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
BACKEND_RELATION_NAME,
PEER_RELATION_NAME,
)
from tests.helpers import patch_network_get

from ..helpers import patch_network_get


@patch_network_get(private_address="1.1.1.1")
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/relations/test_pgbouncer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from charm import PgBouncerCharm
from constants import BACKEND_RELATION_NAME, CLIENT_RELATION_NAME, PEER_RELATION_NAME
from tests.helpers import patch_network_get

from ..helpers import patch_network_get


class TestPgbouncerProvider(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
SECRET_INTERNAL_LABEL,
SNAP_PACKAGES,
)
from tests.helpers import patch_network_get

from .helpers import patch_network_get

DATA_DIR = "tests/unit/data"
TEST_VALID_INI = f"{DATA_DIR}/test.ini"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ all_path = {[vars]src_path} {[vars]tests_path}

[testenv]
set_env =
PYTHONPATH = {tox_root}:{tox_root}/lib:{[vars]src_path}
PYTHONPATH = {[vars]src_path}:{tox_root}/lib
PYTHONBREAKPOINT=ipdb.set_trace
PY_COLORS=1
pass_env =
Expand Down

0 comments on commit 6950ba8

Please sign in to comment.