Skip to content

Commit 3bc05b7

Browse files
Use reusable integration test workflow (#161)
- Use https://github.com/canonical/data-platform-workflows/blob/main/.github/workflows/integration_test_charm.md - Parameterize `ops.JujuVersion.has_secrets` as pytest fixture & test combinations of relations with & without secrets at the same time instead of splitting the unit test CI into two workflows and passing "libjuju agent version" env var (when libjuju is not being used in unit tests) Note that this PR increases the number of combination options by about a factor of 2, which increases the number of combinations exponentially (~300 tests to ~3400 tests [plus an exponential increase of tests within each test with a for loop, that aren't tracked by pytest individually]). In the future we may want to add a "quick" version/subset of the unit tests for local runs & for PRs or to gate the integration CI (which currently waits for unit tests to pass before starting)
1 parent fad69b1 commit 3bc05b7

File tree

12 files changed

+236
-596
lines changed

12 files changed

+236
-596
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
unit-test:
3232
name: Unit test charm
3333
runs-on: ubuntu-latest
34-
timeout-minutes: 8
34+
timeout-minutes: 15
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v4
@@ -44,101 +44,27 @@ jobs:
4444

4545
build:
4646
name: Build charm
47-
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4.2.3
47+
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v6.2.0
4848
permissions:
4949
actions: write # Needed to manage GitHub Actions cache
5050

51-
gh-hosted-collect-integration-tests:
52-
name: (GH hosted) Collect integration test groups
53-
needs:
54-
- lint
55-
- unit-test
56-
runs-on: ubuntu-latest
57-
steps:
58-
- name: Checkout
59-
uses: actions/checkout@v4
60-
- name: Install tox & poetry
61-
run: |
62-
pipx install tox
63-
pipx install poetry
64-
- name: Select test stability level
65-
id: select-test-stability
66-
run: |
67-
if [[ "${{ github.event_name }}" == "schedule" ]]
68-
then
69-
echo Running unstable and stable tests
70-
echo "mark_expression=" >> "$GITHUB_OUTPUT"
71-
else
72-
echo Skipping unstable tests
73-
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
74-
fi
75-
- name: Collect test groups
76-
id: collect-groups
77-
run: tox run -e integration -- tests/integration -m '${{ steps.select-test-stability.outputs.mark_expression }}' --collect-groups
78-
outputs:
79-
groups: ${{ steps.collect-groups.outputs.groups }}
80-
81-
gh-hosted-integration-test:
51+
integration-test:
8252
strategy:
8353
fail-fast: false
8454
matrix:
85-
groups: ${{ fromJSON(needs.gh-hosted-collect-integration-tests.outputs.groups) }}
86-
juju-snap-channel: ["2.9/stable", "3.1/stable"]
87-
include:
88-
- juju-snap-channel: "3.1/stable"
89-
agent-version: "3.1.6"
90-
libjuju-version: "3.2.2"
91-
- juju-snap-channel: "2.9/stable"
92-
agent-version: "2.9.45"
93-
libjuju-version: "2.9.44.1"
94-
name: ${{ matrix.juju-snap-channel }} - (GH hosted) ${{ matrix.groups.job_name }} | ${{ matrix.ubuntu-versions.series }}
55+
juju:
56+
- agent: 2.9.45
57+
libjuju: ^2
58+
- agent: 3.1.6
59+
name: Integration test charm | ${{ matrix.juju.agent }}
9560
needs:
9661
- lint
9762
- unit-test
9863
- build
99-
- gh-hosted-collect-integration-tests
100-
runs-on: ubuntu-latest
101-
timeout-minutes: 120
102-
steps:
103-
- name: Checkout
104-
uses: actions/checkout@v4
105-
- name: Install tox & poetry
106-
run: |
107-
pipx install tox
108-
pipx install poetry
109-
- name: Free up disk space
110-
run: |
111-
# From https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
112-
sudo rm -rf /usr/share/dotnet
113-
sudo rm -rf /opt/ghc
114-
sudo rm -rf /usr/local/share/boost
115-
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
116-
- name: Setup operator environment
117-
uses: charmed-kubernetes/actions-operator@main
118-
with:
119-
provider: microk8s
120-
channel: "1.28-strict/stable"
121-
bootstrap-options: "--agent-version ${{ matrix.agent-version }}"
122-
juju-channel: ${{ matrix.juju-snap-channel }}
123-
- name: Update python-libjuju version
124-
if: ${{ matrix.libjuju-version == '2.9.44.1' }}
125-
run: poetry add --lock --group integration juju@'${{ matrix.libjuju-version }}'
126-
- name: Download packed charm(s)
127-
uses: actions/download-artifact@v3
128-
with:
129-
name: ${{ needs.build.outputs.artifact-name }}
130-
- name: Select test stability level
131-
id: select-test-stability
132-
run: |
133-
if [[ "${{ github.event_name }}" == "schedule" ]]
134-
then
135-
echo Running unstable and stable tests
136-
echo "mark_expression=" >> "$GITHUB_OUTPUT"
137-
else
138-
echo Skipping unstable tests
139-
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
140-
fi
141-
- name: Run integration tests
142-
run: tox run -e integration -- "${{ matrix.groups.path_to_test_file }}" --group="${{ matrix.groups.group_number }}" -m '${{ steps.select-test-stability.outputs.mark_expression }}'
143-
env:
144-
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.libjuju-version }}
64+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
65+
with:
66+
artifact-name: ${{ needs.build.outputs.artifact-name }}
67+
cloud: microk8s
68+
microk8s-snap-channel: 1.28-strict/stable
69+
juju-agent-version: ${{ matrix.juju.agent }}
70+
libjuju-version-constraint: ${{ matrix.juju.libjuju }}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ jobs:
3232

3333
build:
3434
name: Build charm
35-
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v4.2.3
35+
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v6.2.0
3636

3737
release:
3838
name: Release charm
3939
needs:
4040
- lib-check
4141
- ci-tests
4242
- build
43-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v4.2.3
43+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v6.2.0
4444
with:
4545
channel: 8.0/edge
4646
artifact-name: ${{ needs.build.outputs.artifact-name }}

.github/workflows/sync_issue_to_jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
sync:
1111
name: Sync GitHub issue to Jira
12-
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v4.2.3
12+
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v6.2.0
1313
with:
1414
jira-base-url: https://warthogs.atlassian.net
1515
jira-project-key: DPE

poetry.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,20 @@ codespell = "^2.2.5"
4848
pytest = "^7.4.0"
4949
pytest-xdist = "^3.3.1"
5050
pytest-cov = "^4.1.0"
51-
ops-scenario = "^5.4.1"
51+
ops-scenario = "^5.6.2"
5252
ops = ">=2.0.0"
5353
pytest-mock = "^3.11.1"
5454

5555
[tool.poetry.group.integration.dependencies]
5656
pytest = "^7.4.0"
5757
pytest-operator = "^0.28.0"
58-
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v4.2.3", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
59-
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v4.2.3", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
60-
juju = "3.2.2"
58+
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.2.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
59+
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.2.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
60+
juju = "^3.2.2"
6161
mysql-connector-python = "~8.0.33"
6262
pyyaml = "^6.0.1"
6363
tenacity = "^8.2.2"
64-
ops = ">=2.0.0"
65-
pytest-mock = "^3.11.1"
64+
ops = "^2.6.0"
6665

6766

6867
[tool.coverage.run]

tests/conftest.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/integration/conftest.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/unit/conftest.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# Copyright 2023 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

4-
from unittest.mock import PropertyMock
5-
64
import pytest
7-
from ops import JujuVersion
8-
from pytest_mock import MockerFixture
95

106

117
@pytest.fixture(autouse=True)
@@ -57,20 +53,7 @@ def kubernetes_patch(monkeypatch):
5753
monkeypatch.setattr("kubernetes_upgrade._Partition.set", lambda *args, **kwargs: None)
5854

5955

60-
@pytest.fixture(autouse=True, params=["juju2", "juju3"])
61-
def juju_has_secrets(mocker: MockerFixture, request):
62-
"""This fixture will force the usage of secrets whenever run on Juju 3.x.
63-
64-
NOTE: This is needed, as normally JujuVersion is set to 0.0.0 in tests
65-
(i.e. not the real juju version)
66-
"""
67-
if request.param == "juju3":
68-
mocker.patch.object(
69-
JujuVersion, "has_secrets", new_callable=PropertyMock
70-
).return_value = False
71-
return False
72-
else:
73-
mocker.patch.object(
74-
JujuVersion, "has_secrets", new_callable=PropertyMock
75-
).return_value = True
76-
return True
56+
@pytest.fixture(params=[True, False])
57+
def juju_has_secrets(request, monkeypatch):
58+
monkeypatch.setattr("ops.JujuVersion.has_secrets", request.param)
59+
return request.param

0 commit comments

Comments
 (0)