Skip to content

Commit

Permalink
[DPE-3733] Update CI (#80)
Browse files Browse the repository at this point in the history
* update CI

* add select test step to job

* rearrange imports on tests

* split CI due to different agent requirements

* skip pod deletion test on discourse
  • Loading branch information
zmraul authored Apr 17, 2024
1 parent 9cddc63 commit 0c12059
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 150 deletions.
148 changes: 101 additions & 47 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,112 +1,166 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
name: Tests

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

on:
workflow_call:
pull_request:
schedule:
- cron: '53 0 * * *' # Daily at 00:53 UTC
# Triggered on push to branch "main" by .github/workflows/release.yaml
workflow_call:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
- name: Install tox
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint
run: tox run -e lint

unit-test:
name: Unit tests
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
- name: Install tox
run: python -m pip install tox
- name: Run tests
run: tox -e unit
run: tox run -e unit

integration-test-general:
name: Integration tests (general)
needs:
- lint
- unit-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-charm
build:
name: Build charms
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v7

integration-test-relation:
name: Integration tests (relation)
integration-test:
strategy:
fail-fast: false
matrix:
tox-environments:
- integration-charm
- integration-password
- integration-redis-relation
name: ${{ matrix.tox-environments }}
needs:
- lint
- unit-test
runs-on: ubuntu-latest
- build
runs-on: ubuntu-22.04
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
# TODO: Replace with custom image on self-hosted runner
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: "1.28-strict/stable"
juju-channel: 2.9/stable
bootstrap-options: "--agent-version 2.9.43"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Select tests
id: select-tests
run: |
if [ "${{ github.event_name }}" == "schedule" ]
then
echo Running unstable and stable tests
echo "mark_expression=" >> $GITHUB_OUTPUT
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox -e integration-relation
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}'
env:
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}

integration-test-relation-single-unit:
name: Integration tests (relation, num_units=1)
name: integration-relation (relation, num_units=1)
needs:
- lint
- unit-test
- build
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
# TODO: Replace with custom image on self-hosted runner
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: "1.28-strict/stable"
juju-channel: 2.9/stable
bootstrap-options: "--agent-version 2.9.43"
- name: Run integration tests
run: tox -e integration-relation -- --num-units 1

integration-test-password:
name: Integration tests (password)
needs:
- lint
- unit-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
provider: microk8s
bootstrap-options: "--agent-version 2.9.43"
name: ${{ needs.build.outputs.artifact-name }}
- name: Select tests
id: select-tests
run: |
if [ "${{ github.event_name }}" == "schedule" ]
then
echo Running unstable and stable tests
echo "mark_expression=" >> $GITHUB_OUTPUT
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox -e integration-password
run: tox run -e integration-redis-relation -- --num-units 1 -m '${{ steps.select-tests.outputs.mark_expression }}'
env:
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}

integration-test-scaling:
name: Integration tests (scaling)
name: integration-scaling
needs:
- lint
- unit-test
- build
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup operator environment
# TODO: Replace with custom image on self-hosted runner
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: "1.28-strict/stable"
juju-channel: 2.9/stable
bootstrap-options: "--agent-version 2.9.29"
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Select tests
id: select-tests
run: |
if [ "${{ github.event_name }}" == "schedule" ]
then
echo Running unstable and stable tests
echo "mark_expression=" >> $GITHUB_OUTPUT
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox -e integration-scaling
run: tox run -e integration-scaling -- -m '${{ steps.select-tests.outputs.mark_expression }}'
env:
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
lib-check:
name: Check libraries
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ show_missing = true
[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"
markers = ["unstable"]

# Formatting tools configuration
[tool.black]
Expand Down
22 changes: 0 additions & 22 deletions tests/helpers.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py → tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

from tests.helpers import NUM_UNITS
from .helpers import NUM_UNITS


def pytest_addoption(parser):
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
"""Helpers for integration tests."""
import logging
import subprocess
from pathlib import Path
from urllib.request import urlopen

import yaml
from pytest_operator.plugin import OpsTest
from tenacity import before_log, retry, stop_after_attempt, wait_fixed

from tests.helpers import APP_NAME
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = METADATA["name"]
STORAGE_PATH = METADATA["storage"]["database"]["location"]
TLS_RESOURCES = {
"cert-file": "tests/tls/redis.crt",
"key-file": "tests/tls/redis.key",
"ca-cert-file": "tests/tls/ca.crt",
}
APPLICATION_DATA = {
"leader-host": "leader-host",
"redis-password": "password",
}
NUM_UNITS = 3

logger = logging.getLogger(__name__)

Expand Down
8 changes: 5 additions & 3 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging

import pytest
Expand All @@ -11,8 +10,11 @@
from pytest_operator.plugin import OpsTest
from redis import Redis

from tests.helpers import APP_NAME, METADATA, NUM_UNITS, TLS_RESOURCES
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
NUM_UNITS,
TLS_RESOURCES,
attach_resource,
change_config,
get_address,
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging

import pytest
from pytest_operator.plugin import OpsTest
from redis import Redis
from redis.exceptions import AuthenticationError

from tests.helpers import APP_NAME, METADATA
from tests.integration.helpers import get_address, get_password
from .helpers import APP_NAME, METADATA, get_address, get_password

logger = logging.getLogger(__name__)

Expand Down
8 changes: 5 additions & 3 deletions tests/integration/test_redis_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from lightkube.resources.core_v1 import Pod
from pytest_operator.plugin import OpsTest

from tests.helpers import APP_NAME, METADATA
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
check_application_status,
get_address,
get_unit_map,
Expand Down Expand Up @@ -122,6 +123,7 @@ async def test_discourse_request(ops_test: OpsTest):
assert response.status == 200


@pytest.mark.skip(reason="Discourse goes into error on CI on primary change")
async def test_delete_redis_pod(ops_test: OpsTest):
"""Delete the leader redis-k8s pod.
Expand All @@ -140,7 +142,7 @@ async def test_delete_redis_pod(ops_test: OpsTest):
)
await ops_test.model.block_until(
lambda: check_application_status(ops_test, FIRST_DISCOURSE_APP_NAME) == "active",
timeout=600,
timeout=1200,
wait_period=5,
)

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging
import time

import pytest
from pytest_operator.plugin import OpsTest
from redis import Redis

from tests.helpers import APP_NAME, METADATA, NUM_UNITS
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
NUM_UNITS,
get_address,
get_password,
get_sentinel_password,
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
from redis.exceptions import RedisError

from charm import RedisK8sCharm
from tests.helpers import APPLICATION_DATA

APPLICATION_DATA = {
"leader-host": "leader-host",
"redis-password": "password",
}


class TestCharm(TestCase):
Expand Down
Loading

0 comments on commit 0c12059

Please sign in to comment.