Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/operator workflow integration test #132

Merged
merged 26 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e4f435f
Create a scirpts directory
yhaliaw Oct 6, 2023
b6540ec
Use operator-workflow for integration tests
yhaliaw Oct 6, 2023
c8efc56
Non-parallel integration tests
yhaliaw Oct 6, 2023
9696033
Try using extra matrix
yhaliaw Oct 6, 2023
1552ded
Fix typo
yhaliaw Oct 6, 2023
20715bc
Update scripts/pre-integration-test.sh
yhaliaw Oct 6, 2023
245e4ff
Debug
yhaliaw Oct 6, 2023
c1215b8
Run integration test in sequence
yhaliaw Oct 6, 2023
52d1396
Fix arg name
yhaliaw Oct 8, 2023
63a3a47
Use modules input
yhaliaw Oct 11, 2023
491f969
Integration test for network access of runner (#99)
yhaliaw Oct 6, 2023
818eb9e
Remove LXD profile prior to retrying creating LXD instance (#131)
yhaliaw Oct 9, 2023
8808652
Adapt charm to support COS integration (#127)
cbartz Oct 10, 2023
548fafd
Merge branch 'main' into feat/operator-workflow-integration-test
yhaliaw Oct 11, 2023
1ef0d5b
Debug
yhaliaw Oct 11, 2023
43d02ff
Revert scripts
yhaliaw Oct 11, 2023
85ea806
Update pre-integration-test.sh
yhaliaw Oct 12, 2023
898675f
Merge branch 'main' into feat/operator-workflow-integration-test
yhaliaw Oct 12, 2023
92fb70a
Write lxd-profile.yaml to built charm
yhaliaw Oct 16, 2023
98f9d1b
Fix typo
yhaliaw Oct 16, 2023
0f9e5e2
Add missing new line
yhaliaw Oct 16, 2023
e619a85
Use str instead of path for charm_file args
yhaliaw Oct 17, 2023
4593f6e
Fix typing
yhaliaw Oct 17, 2023
f2839e3
Update the name of workflow
yhaliaw Oct 17, 2023
bd6c716
Merge branch 'main' into feat/operator-workflow-integration-test
yhaliaw Oct 17, 2023
7c3e140
Parallelize integration test
yhaliaw Oct 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 22 additions & 139 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
@@ -1,144 +1,27 @@
name: integration-tests
name: Integration tests

on:
pull_request:

jobs:
integration-test-charm-no-runner:
name: Integration test charm with no runner
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju: [3.1, 2.9]
steps:
- uses: actions/checkout@v4
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: ${{ matrix.juju }}/stable
provider: lxd
- name: Enable br_netfilter
run: sudo modprobe br_netfilter
- name: Run Integration tests
run: |
tox -e integration-juju${{ matrix.juju }} -- \
--keep-models \
--path ${{secrets.E2E_TESTING_REPO}} \
--token ${{secrets.E2E_TESTING_TOKEN}} \
--token-alt ${{secrets.E2E_TESTING_TOKEN_ALT}} \
tests/integration/test_charm_no_runner.py
integration-test-charm:
name: Integration test charm
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju: [3.1, 2.9]
steps:
- uses: actions/checkout@v4
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: ${{ matrix.juju }}/stable
provider: lxd
- name: Enable br_netfilter
run: sudo modprobe br_netfilter
- name: Run Integration tests
run: |
tox -e integration-juju${{ matrix.juju }} -- \
--keep-models \
--path ${{secrets.E2E_TESTING_REPO}} \
--token ${{secrets.E2E_TESTING_TOKEN}} \
--token-alt ${{secrets.E2E_TESTING_TOKEN_ALT}} \
tests/integration/test_charm.py
integration-test-charm-fork-repo:
name: Integration test charm with fork repo
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju: [3.1, 2.9]
steps:
- uses: actions/checkout@v4
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: ${{ matrix.juju }}/stable
provider: lxd
- name: Enable br_netfilter
run: sudo modprobe br_netfilter
- name: Run Integration tests
run: |
tox -e integration-juju${{ matrix.juju }} -- \
--keep-models \
--path ${{secrets.E2E_TESTING_REPO}} \
--token ${{secrets.E2E_TESTING_TOKEN}} \
--token-alt ${{secrets.E2E_TESTING_TOKEN_ALT}} \
tests/integration/test_charm_fork_repo.py
integration-test-charm-scheduled-events:
name: Integration test charm scheduled events
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju: [3.1, 2.9]
steps:
- uses: actions/checkout@v4
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: ${{ matrix.juju }}/stable
provider: lxd
- name: Enable br_netfilter
run: sudo modprobe br_netfilter
- name: Run Integration tests
run: |
tox -e integration-juju${{ matrix.juju }} -- \
--keep-models \
--path ${{secrets.E2E_TESTING_REPO}} \
--token ${{secrets.E2E_TESTING_TOKEN}} \
--token-alt ${{secrets.E2E_TESTING_TOKEN_ALT}} \
tests/integration/test_charm_scheduled_events.py
integration-test-charm-metrics:
name: Integration test charm metrics
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju: [ 3.1, 2.9 ]
steps:
- uses: actions/checkout@v4
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: ${{ matrix.juju }}/stable
provider: lxd
- name: Enable br_netfilter
run: sudo modprobe br_netfilter
- name: Run Integration tests
run: |
tox -e integration-juju${{ matrix.juju }} -- \
--keep-models \
--path ${{secrets.E2E_TESTING_REPO}} \
--token ${{secrets.E2E_TESTING_TOKEN}} \
--token-alt ${{secrets.E2E_TESTING_TOKEN_ALT}} \
tests/integration/test_charm_metrics.py
required_status_checks:
name: Required Integration Test Status Checks
runs-on: ubuntu-latest
needs:
- integration-test-charm-no-runner
- integration-test-charm
- integration-test-charm-fork-repo
- integration-test-charm-scheduled-events
- integration-test-charm-metrics
if: always() && !cancelled()
timeout-minutes: 30
steps:
- run: |
[ '${{ needs.integration-test-charm-no-runner.result }}' = 'success' ] || (echo integration-test-charm-no-runner failed && false)
[ '${{ needs.integration-test-charm.result }}' = 'success' ] || (echo integration-test-charm failed && false)
[ '${{ needs.integration-test-charm-fork-repo.result }}' = 'success' ] || (echo integration-test-charm-fork-repo failed && false)
[ '${{ needs.integration-test-charm-scheduled-events.result }}' = 'success' ] || (echo integration-test-charm-schedule-events failed && false)
[ '${{ needs.integration-test-charm-metrics.result }}' = 'success' ] || (echo integration-test-charm-metrics failed && false)
integration-tests-juju2:
name: Integration test
yhaliaw marked this conversation as resolved.
Show resolved Hide resolved
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
juju-channel: 2.9/stable
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju2.9
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics"]'
integration-tests:
name: Integration test
needs: integration-test-juju2
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
arturo-seijas marked this conversation as resolved.
Show resolved Hide resolved
secrets: inherit
with:
juju-channel: 3.1/stable
pre-run-script: scripts/pre-integration-test.sh
provider: lxd
test-tox-env: integration-juju3.1
modules: '["test_charm_fork_repo", "test_charm_no_runner", "test_charm_scheduled_events", "test_charm_one_runner", "test_charm_metrics"]'
7 changes: 7 additions & 0 deletions scripts/pre-integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

# Enable kernel module br_netfilter
yhaliaw marked this conversation as resolved.
Show resolved Hide resolved
sudo modprobe br_netfilter
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def pytest_addoption(parser: Parser):
"""Add options to pytest parser."""
parser.addoption("--path", action="store")
parser.addoption("--token", action="store")
parser.addoption("--charm-file", action="store")
parser.addoption("--token-alt", action="store")
parser.addoption("--http-proxy", action="store")
parser.addoption("--https-proxy", action="store")
Expand Down
73 changes: 30 additions & 43 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import secrets
import subprocess
import zipfile
from pathlib import Path
from typing import Any, AsyncIterator

Expand Down Expand Up @@ -34,14 +35,31 @@ def app_name() -> str:
return f"integration-id{secrets.token_hex(2)}"


@pytest_asyncio.fixture(scope="module")
async def charm_path(ops_test: OpsTest, lxd_profile: Path) -> AsyncIterator[Path]:
"""Path to the built charm.

Including lxd_profile fixture as an argument, will make lxd_profile.yaml
file present under the charm directory during the building of the charm.
"""
yield await ops_test.build_charm(".")
@pytest.fixture(scope="module")
def charm_file(pytestconfig: pytest.Config) -> str:
"""Path to the built charm."""
charm = pytestconfig.getoption("--charm-file")
assert charm, "Please specify the --charm-file command line option"

with zipfile.ZipFile(charm, mode="a") as charm_file:
charm_file.writestr(
"lxd-profile.yaml",
"""config:
security.nesting: true
security.privileged: true
raw.lxc: |
lxc.apparmor.profile=unconfined
lxc.mount.auto=proc:rw sys:rw cgroup:rw
lxc.cgroup.devices.allow=a
lxc.cap.drop=
devices:
kmsg:
path: /dev/kmsg
source: /dev/kmsg
type: unix-char
""",
)
return f"./{charm}"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -97,41 +115,10 @@ def model(ops_test: OpsTest) -> Model:
return ops_test.model


@pytest_asyncio.fixture(scope="module")
async def lxd_profile() -> AsyncIterator[Path]:
"""File containing LXD profile for test mode.

The file needs to be in the charm directory while building a test version
of the charm.
"""
lxd_profile_path = Path("lxd-profile.yaml")

lxd_profile_path.write_text(
"""config:
security.nesting: true
security.privileged: true
raw.lxc: |
lxc.apparmor.profile=unconfined
lxc.mount.auto=proc:rw sys:rw cgroup:rw
lxc.cgroup.devices.allow=a
lxc.cap.drop=
devices:
kmsg:
path: /dev/kmsg
source: /dev/kmsg
type: unix-char
"""
)

yield lxd_profile_path

lxd_profile_path.unlink(missing_ok=True)


@pytest_asyncio.fixture(scope="module")
async def app_no_runner(
model: Model,
charm_path: Path,
charm_file: str,
app_name: str,
path: str,
token: str,
Expand All @@ -152,7 +139,7 @@ async def app_no_runner(
)

application = await model.deploy(
charm_path,
charm_file,
application_name=app_name,
series="jammy",
config={
Expand Down Expand Up @@ -185,7 +172,7 @@ async def app(model: Model, app_no_runner: Application) -> AsyncIterator[Applica
@pytest_asyncio.fixture(scope="module")
async def app_scheduled_events(
model: Model,
charm_path: Path,
charm_file: str,
app_name: str,
path: str,
token: str,
Expand Down Expand Up @@ -215,7 +202,7 @@ async def app_scheduled_events(
)

application = await model.deploy(
charm_path,
charm_file,
application_name=app_name,
series="jammy",
config={
Expand Down
Loading