Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from jat-canonical/test-arm-runner
Browse files Browse the repository at this point in the history
feat(tests,ci): add support for testing from edge snap revision for ci
  • Loading branch information
morphis authored Apr 4, 2024
2 parents 2b96b3e + 1763cee commit 6a17f76
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 15 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ name: Build & Test

on:
workflow_call:
outputs:
inputs:
snap_risk_level:
type: string
description: |
The track of the snap to test against. Defaults to the default risk
level defined in the charm.
default: ""
required: false
outputs:
artifact-prefix:
description: "The charms build by this workflow"
description: "The charms built by this workflow"
value: ${{ jobs.build.outputs.artifact-prefix }}
jobs:
lint:
Expand Down Expand Up @@ -45,7 +53,6 @@ jobs:
run: |
# Reverse lookup for artifact base index to its architecture
./scripts/ci/get-runners.py
cat $GITHUB_OUTPUT
outputs:
bases: ${{ steps.charm-to-runner.outputs.bases }}

Expand Down Expand Up @@ -86,12 +93,13 @@ jobs:
juju-channel: "${{ env.channel }}"
bootstrap-options: "--agent-version ${{ matrix.agent-versions }}"
- name: Run integration tests
env:
snap_channel: 1.21/stable
run: |
mv ${{ steps.downloaded-charm.outputs.download-path }}/*.charm ams.charm
args="--charm=./ams.charm"
if [ "${{ matrix.base.arch }}" == "arm64" ]; then
args="${args} --constraints arch=arm64"
fi
if [ -n "${{ inputs.snap_risk_level }}" ]; then
args="${args} --snap-risk-level ${{ inputs.snap_risk_level }}"
fi
tox -e integration-${{ env.libjuju }} -- ${args}
22 changes: 22 additions & 0 deletions .github/workflows/get-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Get current version

on:
workflow_call:
outputs:
charm_version:
description: "Get the current version of the charm"
value: ${{ jobs.get-charm-version.outputs.version }}

jobs:
get-charm-version:
runs-on: [self-hosted, linux, X64, jammy, large]
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: Get charm version
id: charm_version
run: |
echo "version=$(cat version)" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.charm_version.outputs.version }}

2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ concurrency:
jobs:
test:
uses: ./.github/workflows/build-and-test.yaml
with:
snap_risk_level: edge
14 changes: 13 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Release To Edge

on:
push:
branches:
Expand All @@ -8,21 +10,31 @@ on:
- .github/renovate.json5
- pyproject.toml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
get-version:
uses: ./.github/workflows/get-version.yaml

ci:
name: Build & Test
uses: ./.github/workflows/build-and-test.yaml
secrets: inherit
with:
snap_risk_level: edge

release:
name: Release charm
needs:
- ci
- get-version
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
# TODO: change this when we actually want to cutover the charm to main
# channels
channel: 1.21-ops/edge
channel: ${{ needs.get-version.outputs.version }}-ops/edge
artifact-prefix: ${{ needs.ci.outputs.artifact-prefix }}
secrets:
charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
11 changes: 11 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
def pytest_addoption(parser):
parser.addoption("--constraints", default="", action="store", help="Model constraints")
parser.addoption("--charm", default="", action="store", help="Path to a built charm")
parser.addoption(
"--snap-risk-level",
default="",
action="store",
help="Risk level to use for the snap deployed by the charm",
)


@pytest.fixture
Expand All @@ -42,6 +48,11 @@ def constraints(request) -> dict:
return cts


@pytest.fixture(scope="module")
def snap_risk_level(request):
return request.config.getoption("--snap-risk-level")


@pytest.fixture
def charm_path(request):
return request.config.getoption("--charm")
12 changes: 10 additions & 2 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@
logger = logging.getLogger(__name__)


@pytest.fixture(scope="module")
def charm_config(snap_risk_level) -> dict:
cfg = {"use_embedded_etcd": True}
if snap_risk_level:
cfg.update(snap_risk_level=snap_risk_level)
return cfg


@pytest.mark.abort_on_fail
async def test_can_deploy_with_embedded_etcd(
ops_test: OpsTest, constraints, charm_name, charm_path
ops_test: OpsTest, constraints, charm_name, charm_path, charm_config
):
"""Build the charm-under-test and deploy it together with related charms.
Expand All @@ -39,7 +47,7 @@ async def test_can_deploy_with_embedded_etcd(
await ops_test.model.deploy(
charm_path,
application_name=charm_name,
config={"use_embedded_etcd": True},
config=charm_config,
)
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(apps=[charm_name], status="active", timeout=1000)
16 changes: 14 additions & 2 deletions tests/integration/test_etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@
APP_NAMES = [ETCD_CHARM_NAME, TLS_CHARM_NAME]


@pytest.fixture(scope="module")
def charm_config(snap_risk_level) -> dict:
cfg = {}
if snap_risk_level:
cfg.update(snap_risk_level=snap_risk_level)
return cfg


@pytest.mark.abort_on_fail
async def test_can_relate_to_etcd(ops_test: OpsTest, charm_name, constraints, charm_path):
async def test_can_relate_to_etcd(
ops_test: OpsTest, charm_name, constraints, charm_config, charm_path
):
"""Build the charm-under-test and deploy it together with related charms.
Assert on the unit status before any relations/configurations take place.
Expand All @@ -39,7 +49,9 @@ async def test_can_relate_to_etcd(ops_test: OpsTest, charm_name, constraints, ch
if constraints:
await ops_test.model.set_constraints(constraints)
await asyncio.gather(
ops_test.model.deploy(charm_path, application_name=charm_name, num_units=1),
ops_test.model.deploy(
charm_path, application_name=charm_name, num_units=1, config=charm_config
),
ops_test.model.deploy(
ETCD_CHARM_NAME,
application_name=ETCD_CHARM_NAME,
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/test_lxd_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@
INTEGRATOR_CHARM_NAME = "lxd-integrator"


@pytest.fixture(scope="module")
def charm_config(snap_risk_level) -> dict:
cfg = {"use_embedded_etcd": True}
if snap_risk_level:
cfg.update(snap_risk_level=snap_risk_level)
return cfg


@pytest.mark.abort_on_fail
async def test_can_relate_to_lxd(ops_test: OpsTest, constraints, charm_name, charm_path):
async def test_can_relate_to_lxd(
ops_test: OpsTest, constraints, charm_name, charm_config, charm_path
):
"""Build the charm-under-test and deploy it together with related charms.
Assert on the unit status before any relations/configurations take place.
Expand All @@ -51,7 +61,7 @@ async def test_can_relate_to_lxd(ops_test: OpsTest, constraints, charm_name, cha
charm_path,
application_name=charm_name,
num_units=1,
config={"use_embedded_etcd": True},
config=charm_config,
),
ops_test.model.deploy(
INTEGRATOR_CHARM_NAME,
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/test_rest_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@
TEST_APP_CHARM_NAME = "ams-api-tester"


@pytest.fixture(scope="module")
def charm_config(snap_risk_level) -> dict:
cfg = {"use_embedded_etcd": True}
if snap_risk_level:
cfg.update(snap_risk_level=snap_risk_level)
return cfg


@pytest.mark.abort_on_fail
async def test_can_relate_to_client_charms(ops_test: OpsTest, charm_name, constraints, charm_path):
async def test_can_relate_to_client_charms(
ops_test: OpsTest, charm_name, charm_config, constraints, charm_path
):
"""Build the charm-under-test and deploy it together with related charms.
Assert on the unit status before any relations/configurations take place.
Expand All @@ -43,7 +53,7 @@ async def test_can_relate_to_client_charms(ops_test: OpsTest, charm_name, constr
charm_path,
application_name=charm_name,
num_units=1,
config={"use_embedded_etcd": True},
config=charm_config,
),
ops_test.model.deploy(
client_charm_path,
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.21
1.22

0 comments on commit 6a17f76

Please sign in to comment.