-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CI matrix + env.vars * pyproject updates (libjuju version, pytest-mock, etc) * tox.ini equipped with Juju version selection vars * Juju3 compatible tests * Fixtures that allow detection and 'switching' between Juju versions * snap_microk8s instead of old microk8s user
- Loading branch information
1 parent
bc5f255
commit 128d32f
Showing
9 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ jobs: | |
uses: canonical/data-platform-workflows/.github/workflows/[email protected] | ||
|
||
unit-test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
juju-version: ["2.9", "3.1"] | ||
name: Unit test charm | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
|
@@ -31,6 +35,12 @@ jobs: | |
pipx install poetry | ||
- name: Run tests | ||
run: tox run -e unit | ||
env: | ||
# This env var is only to indicate Juju version to "simulate" in the unit tests | ||
# No libjuju is being actually used in unit testing | ||
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.juju-version }} | ||
- name: Upload Coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
|
||
build: | ||
name: Build charm | ||
|
@@ -75,7 +85,29 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
groups: ${{ fromJSON(needs.gh-hosted-collect-integration-tests.outputs.groups) }} | ||
name: (GH hosted) ${{ matrix.groups.job_name }} | ||
juju-snap-channel: ["2.9/stable", "3.1/candidate"] | ||
include: | ||
- juju-snap-channel: "3.1/candidate" | ||
agent-version: "3.1.6" | ||
libjuju-version: "3.2.2" | ||
- juju-snap-channel: "2.9/stable" | ||
agent-version: "2.9.44" | ||
libjuju-version: "2.9.44.1" | ||
exclude: | ||
# Disabling HA tests, as long as we want to have a limited pipeline on Juju3 | ||
- juju-snap-channel: "3.1/candidate" | ||
groups: | ||
job_name: "high_availability/test_replication.py | group 1" | ||
- juju-snap-channel: "3.1/candidate" | ||
groups: | ||
job_name: "high_availability/test_self_healing.py | group 1" | ||
- juju-snap-channel: "3.1/candidate" | ||
groups: | ||
job_name: "high_availability/test_upgrade.py | group 1" | ||
- juju-snap-channel: "3.1/candidate" | ||
groups: | ||
job_name: "high_availability/test_upgrade_from_stable.py | group 1" | ||
name: ${{ matrix.juju-snap-channel }} - (GH hosted) ${{ matrix.groups.job_name }} | ||
needs: | ||
- lint | ||
- unit-test | ||
|
@@ -94,6 +126,12 @@ jobs: | |
uses: charmed-kubernetes/actions-operator@main | ||
with: | ||
provider: microk8s | ||
channel: "1.28-strict/stable" | ||
bootstrap-options: "--agent-version ${{ matrix.agent-version }}" | ||
juju-channel: ${{ matrix.juju-snap-channel }} | ||
- name: Update python-libjuju version | ||
if: ${{ matrix.libjuju-version != '2.9.44.1' }} | ||
run: poetry add --lock --group integration juju@'${{ matrix.libjuju-version }}' | ||
- name: Download packed charm(s) | ||
uses: actions/download-artifact@v3 | ||
with: | ||
|
@@ -112,6 +150,7 @@ jobs: | |
- name: Run integration tests | ||
run: tox run -e integration -- "${{ matrix.groups.path_to_test_file }}" --group="${{ matrix.groups.group_number }}" -m '${{ steps.select-test-stability.outputs.mark_expression }}' | ||
env: | ||
LIBJUJU_VERSION_SPECIFIER: ${{ matrix.libjuju-version }} | ||
SECRETS_FROM_GITHUB: | | ||
{ | ||
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2022 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import os | ||
from unittest.mock import PropertyMock | ||
|
||
import pytest | ||
from ops import JujuVersion | ||
from pytest_mock import MockerFixture | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def juju_has_secrets(mocker: MockerFixture): | ||
"""This fixture will force the usage of secrets whenever run on Juju 3.x. | ||
NOTE: This is needed, as normally JujuVersion is set to 0.0.0 in tests | ||
(i.e. not the real juju version) | ||
""" | ||
juju_version = os.environ["LIBJUJU_VERSION_SPECIFIER"].split("/")[0] | ||
if juju_version < "3": | ||
mocker.patch.object( | ||
JujuVersion, "has_secrets", new_callable=PropertyMock | ||
).return_value = False | ||
return False | ||
else: | ||
mocker.patch.object( | ||
JujuVersion, "has_secrets", new_callable=PropertyMock | ||
).return_value = True | ||
return True | ||
|
||
|
||
@pytest.fixture | ||
def only_with_juju_secrets(juju_has_secrets): | ||
"""Pretty way to skip Juju 3 tests.""" | ||
if not juju_has_secrets: | ||
pytest.skip("Secrets test only applies on Juju 3.x") | ||
|
||
|
||
@pytest.fixture | ||
def only_without_juju_secrets(juju_has_secrets): | ||
"""Pretty way to skip Juju 2-specific tests. | ||
Typically: to save CI time, when the same check were executed in a Juju 3-specific way already | ||
""" | ||
if juju_has_secrets: | ||
pytest.skip("Skipping legacy secrets tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.