Skip to content

Commit

Permalink
Add Ubuntu 22.04 (jammy) support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Mar 28, 2023
1 parent 6df8527 commit 605e9bd
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 13 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ jobs:
# https://bugs.launchpad.net/charm-keystone/+bug/1990243
# - integration-shared-db
- integration-database
name: ${{ matrix.tox-environments }}
ubuntu-versions:
# Update whenever charmcraft.yaml is changed
- series: focal
bases-index: 0
- series: jammy
bases-index: 1
name: ${{ matrix.tox-environments }} | ${{ matrix.ubuntu-versions.series }}
needs:
- lib-check
- lint
Expand All @@ -86,7 +92,7 @@ jobs:
uses: charmed-kubernetes/actions-operator@main
with:
provider: lxd
bootstrap-options: "--agent-version 2.9.38"
bootstrap-options: "--agent-version 2.9.42"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
Expand All @@ -103,6 +109,6 @@ jobs:
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}'
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}' --mysql-router-charm-series=${{ matrix.ubuntu-versions.series }} --mysql-router-charm-bases-index=${{ matrix.ubuntu-versions.bases-index }}
env:
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}
9 changes: 9 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@

type: charm
bases:
# Whenever "bases" is changed:
# - Update tests/integration/conftest.py::pytest_configure()
# - Update .github/workflow/ci.yaml integration-test matrix
- build-on:
- name: "ubuntu"
channel: "20.04"
run-on:
- name: "ubuntu"
channel: "20.04"
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"
parts:
charm:
charm-binary-python-packages:
Expand Down
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
from argparse import ArgumentError


def pytest_addoption(parser):
parser.addoption(
"--mysql-router-charm-series", help="Ubuntu series for mysql router charm (e.g. jammy)"
)
parser.addoption(
"--mysql-router-charm-bases-index",
type=int,
help="Index of charmcraft.yaml base that matches --mysql-router-charm-series",
)


def pytest_configure(config):
if (config.option.mysql_router_charm_series is None) ^ (
config.option.mysql_router_charm_bases_index is None
):
raise ArgumentError(
None,
"--mysql-router-charm-series and --mysql-router-charm-bases-index must be given together",
)
# Note: Update defaults whenever charmcraft.yaml is changed
if config.option.mysql_router_charm_series is None:
config.option.mysql_router_charm_series = "jammy"
if config.option.mysql_router_charm_bases_index is None:
config.option.mysql_router_charm_bases_index = 1
26 changes: 22 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,37 @@
from pytest_operator.plugin import OpsTest


@pytest.fixture
def ops_test(ops_test: OpsTest) -> OpsTest:
@pytest.fixture(scope="session")
def mysql_router_charm_series(pytestconfig) -> str:
return pytestconfig.option.mysql_router_charm_series


@pytest.fixture(scope="module")
def ops_test(ops_test: OpsTest, pytestconfig) -> OpsTest:
if os.environ.get("CI") == "true":
# Running in GitHub Actions; skip build step
# (GitHub Actions uses a separate, cached build step. See .github/workflows/ci.yaml)
packed_charms = json.loads(os.environ["CI_PACKED_CHARMS"])

async def build_charm(charm_path, bases_index: int = None) -> Path:
async def _build_charm(charm_path, bases_index: int = None) -> Path:
for charm in packed_charms:
if Path(charm_path) == Path(charm["directory_path"]):
if bases_index is None or bases_index == charm["bases_index"]:
return charm["file_path"]
raise ValueError(f"Unable to find .charm file for {bases_index=} at {charm_path=}")

ops_test.build_charm = build_charm
else:
_build_charm = ops_test.build_charm

async def build_charm(charm_path) -> Path:
if Path(charm_path) == Path("."):
# Building mysql charm
return await _build_charm(
charm_path,
bases_index=pytestconfig.option.mysql_router_charm_bases_index,
)
else:
return await _build_charm(charm_path)

ops_test.build_charm = build_charm
return ops_test
7 changes: 5 additions & 2 deletions tests/integration/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@pytest.mark.order(1)
@pytest.mark.abort_on_fail
async def test_database_relation(ops_test: OpsTest) -> None:
async def test_database_relation(ops_test: OpsTest, mysql_router_charm_series: str) -> None:
"""Test the database relation."""
# Build and deploy applications
mysqlrouter_charm = await ops_test.build_charm(".")
Expand All @@ -38,7 +38,10 @@ async def test_database_relation(ops_test: OpsTest) -> None:
"mysql", channel="latest/edge", application_name=MYSQL_APP_NAME, num_units=1
),
ops_test.model.deploy(
mysqlrouter_charm, application_name=MYSQL_ROUTER_APP_NAME, num_units=None
mysqlrouter_charm,
application_name=MYSQL_ROUTER_APP_NAME,
num_units=None,
series=mysql_router_charm_series,
),
ops_test.model.deploy(
APPLICATION_APP_NAME,
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/test_shared_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@pytest.mark.order(1)
@pytest.mark.abort_on_fail
async def test_shared_db(ops_test: OpsTest):
async def test_shared_db(ops_test: OpsTest, mysql_router_charm_series: str):
"""Test the shared-db legacy relation."""
charm = await ops_test.build_charm(".")

Expand All @@ -33,7 +33,10 @@ async def test_shared_db(ops_test: OpsTest):
# MySQLRouter is a subordinate charm, and thus needs to be deployed with no units
# Instead, they will be deployed with the keystone units when related with the keystone app
mysqlrouter_app = await ops_test.model.deploy(
charm, application_name=MYSQLROUTER_APP_NAME, num_units=None
charm,
application_name=MYSQLROUTER_APP_NAME,
num_units=None,
series=mysql_router_charm_series,
)

await ops_test.model.relate(
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@pytest.mark.abort_on_fail
@pytest.mark.order(1)
async def test_build_deploy_and_relate(ops_test: OpsTest) -> None:
async def test_build_deploy_and_relate(ops_test: OpsTest, mysql_router_charm_series: str) -> None:
"""Test encryption when backend database is using TLS."""
# Deploy TLS Certificates operator.
await ops_test.model.set_config(MODEL_CONFIG)
Expand All @@ -35,7 +35,10 @@ async def test_build_deploy_and_relate(ops_test: OpsTest) -> None:
# tls, test app and router
await asyncio.gather(
ops_test.model.deploy(
mysqlrouter_charm, application_name=MYSQL_ROUTER_APP_NAME, num_units=None
mysqlrouter_charm,
application_name=MYSQL_ROUTER_APP_NAME,
num_units=None,
series=mysql_router_charm_series,
),
ops_test.model.deploy(
TLS_APP_NAME, application_name=TLS_APP_NAME, channel="stable", config=tls_config
Expand Down

0 comments on commit 605e9bd

Please sign in to comment.