Skip to content

Commit 4b84263

Browse files
Cache charmcraft pack container, skip unstable tests except on schedule (canonical#69)
1 parent b8a2c0c commit 4b84263

File tree

12 files changed

+151
-191
lines changed

12 files changed

+151
-191
lines changed

.github/workflows/ci.yaml

Lines changed: 48 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
# Copyright 2022 Canonical Ltd.
2+
# See LICENSE file for licensing details.
13
name: Tests
4+
25
on:
36
pull_request:
7+
schedule:
8+
- cron: '53 0 * * *' # Daily at 00:53 UTC
9+
# Triggered on push to branch "main" by .github/workflows/release.yaml
410
workflow_call:
511

612
jobs:
@@ -10,136 +16,74 @@ jobs:
1016
steps:
1117
- name: Checkout
1218
uses: actions/checkout@v3
13-
- name: Install dependencies
19+
- name: Install tox
20+
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
1421
run: python3 -m pip install tox
1522
- name: Run linters
16-
run: tox -e lint
23+
run: tox run -e lint
1724

1825
unit-test:
1926
name: Unit tests
2027
runs-on: ubuntu-latest
2128
steps:
2229
- name: Checkout
2330
uses: actions/checkout@v3
24-
- name: Install dependencies
25-
run: python -m pip install tox
31+
- name: Install tox
32+
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
33+
run: python3 -m pip install tox
2634
- name: Run tests
27-
run: tox -e unit
35+
run: tox run -e unit
2836
- name: Upload Coverage to Codecov
2937
uses: codecov/codecov-action@v3
3038

31-
integration-test-lxd-charm:
32-
name: Integration tests for charm deployment (lxd)
33-
needs:
34-
- lint
35-
- unit-test
36-
runs-on: ubuntu-latest
37-
steps:
38-
- name: Checkout
39-
uses: actions/checkout@v3
40-
- name: Setup operator environment
41-
uses: charmed-kubernetes/actions-operator@main
42-
with:
43-
provider: lxd
44-
- name: Run integration tests
45-
run: tox -e charm-integration
46-
47-
integration-test-lxd-database-relation:
48-
name: Integration tests for database relation (lxd)
49-
needs:
50-
- lint
51-
- unit-test
52-
runs-on: ubuntu-latest
53-
steps:
54-
- name: Checkout
55-
uses: actions/checkout@v3
56-
- name: Setup operator environment
57-
uses: charmed-kubernetes/actions-operator@main
58-
with:
59-
provider: lxd
60-
# This is needed until https://bugs.launchpad.net/juju/+bug/1992833 is fixed.
61-
bootstrap-options: "--agent-version 2.9.34"
62-
- name: Run integration tests
63-
run: tox -e database-relation-integration
64-
65-
integration-test-lxd-db-relation:
66-
name: Integration tests for db relation (lxd)
67-
needs:
68-
- lint
69-
- unit-test
70-
runs-on: ubuntu-latest
71-
steps:
72-
- name: Checkout
73-
uses: actions/checkout@v3
74-
- name: Setup operator environment
75-
uses: charmed-kubernetes/actions-operator@main
76-
with:
77-
provider: lxd
78-
- name: Run integration tests
79-
run: tox -e db-relation-integration
80-
81-
integration-test-lxd-db-admin-relation:
82-
name: Integration tests for db-admin relation (lxd)
83-
needs:
84-
- lint
85-
- unit-test
86-
runs-on: ubuntu-latest
87-
steps:
88-
- name: Checkout
89-
uses: actions/checkout@v3
90-
- name: Setup operator environment
91-
uses: charmed-kubernetes/actions-operator@main
92-
with:
93-
provider: lxd
94-
- name: Run integration tests
95-
run: tox -e db-admin-relation-integration
39+
build:
40+
name: Build charms
41+
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v1
9642

97-
integration-test-ha-self-healing-rotation:
98-
name: Integration tests for high availability self healing (lxd)
43+
integration-test:
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
tox-environments:
48+
- charm-integration
49+
- database-relation-integration
50+
- db-relation-integration
51+
- db-admin-relation-integration
52+
- ha-self-healing-integration
53+
- password-rotation-integration
54+
- tls-integration
55+
name: ${{ matrix.tox-environments }}
9956
needs:
10057
- lint
10158
- unit-test
59+
- build
10260
runs-on: ubuntu-latest
10361
steps:
10462
- name: Checkout
10563
uses: actions/checkout@v3
10664
- name: Setup operator environment
65+
# TODO: Replace with custom image on self-hosted runner
10766
uses: charmed-kubernetes/actions-operator@main
10867
with:
10968
provider: lxd
11069
# This is needed until https://bugs.launchpad.net/juju/+bug/1992833 is fixed.
11170
bootstrap-options: "--agent-version 2.9.34"
112-
- name: Run integration tests
113-
run: tox -e ha-self-healing-integration
114-
115-
integration-test-lxd-password-rotation:
116-
name: Integration tests for password rotation (lxd)
117-
needs:
118-
- lint
119-
- unit-test
120-
runs-on: ubuntu-latest
121-
steps:
122-
- name: Checkout
123-
uses: actions/checkout@v3
124-
- name: Setup operator environment
125-
uses: charmed-kubernetes/actions-operator@main
126-
with:
127-
provider: lxd
128-
- name: Run integration tests
129-
run: tox -e password-rotation-integration
130-
131-
integration-test-lxd-tls:
132-
name: Integration tests for TLS (lxd)
133-
needs:
134-
- lint
135-
- unit-test
136-
runs-on: ubuntu-latest
137-
steps:
138-
- name: Checkout
139-
uses: actions/checkout@v3
140-
- name: Setup operator environment
141-
uses: charmed-kubernetes/actions-operator@main
71+
- name: Download packed charm(s)
72+
uses: actions/download-artifact@v3
14273
with:
143-
provider: lxd
74+
name: ${{ needs.build.outputs.artifact-name }}
75+
- name: Select tests
76+
id: select-tests
77+
run: |
78+
if [ "${{ github.event_name }}" == "schedule" ]
79+
then
80+
echo Running unstable and stable tests
81+
echo "mark_expression=" >> $GITHUB_OUTPUT
82+
else
83+
echo Skipping unstable tests
84+
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
85+
fi
14486
- name: Run integration tests
145-
run: tox -e tls-integration
87+
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}'
88+
env:
89+
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}

CONTRIBUTING.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@ this operator.
2121

2222
## Developing
2323

24-
You can use the environments created by `tox` for development:
24+
You can create an environment for development with `tox`:
2525

2626
```shell
27-
tox --notest -e unit
28-
source .tox/unit/bin/activate
27+
tox devenv -e integration
28+
source venv/bin/activate
2929
```
3030

3131
### Testing
3232

3333
```shell
34-
tox -e fmt # update your code according to linting rules
35-
tox -e lint # code style
36-
tox -e unit # unit tests
37-
tox -e integration # integration tests
38-
tox # runs 'lint' and 'unit' environments
34+
tox run -e format # update your code according to linting rules
35+
tox run -e lint # code style
36+
tox run -e unit # unit tests
37+
tox run -e integration # integration tests
38+
tox # runs 'lint' and 'unit' environments
3939
```
4040

41+
4142
## Build charm
4243

4344
Build the charm in this git repository using:

pyproject.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ exclude_lines = [
1515
minversion = "6.0"
1616
log_cli_level = "INFO"
1717
asyncio_mode = "auto"
18-
markers = [
19-
"charm_tests",
20-
"database_relation_tests",
21-
"db_relation_tests",
22-
"db_admin_relation_tests",
23-
"ha_self_healing_tests",
24-
"password_rotation_tests",
25-
"tls_tests",
26-
]
18+
markers = ["unstable"]
2719

2820
# Formatting tools configuration
2921
[tool.black]

tests/integration/conftest.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
#!/usr/bin/env python3
22
# Copyright 2022 Canonical Ltd.
33
# See LICENSE file for licensing details.
4-
import pytest as pytest
4+
5+
import json
6+
import os
7+
from pathlib import Path
8+
9+
import pytest
510
from pytest_operator.plugin import OpsTest
611

712

13+
@pytest.fixture(scope="module")
14+
def ops_test(ops_test: OpsTest) -> OpsTest:
15+
if os.environ.get("CI") == "true":
16+
# Running in GitHub Actions; skip build step
17+
# (GitHub Actions uses a separate, cached build step. See .github/workflows/ci.yaml)
18+
packed_charms = json.loads(os.environ["CI_PACKED_CHARMS"])
19+
20+
async def build_charm(charm_path, bases_index: int = None) -> Path:
21+
for charm in packed_charms:
22+
if Path(charm_path) == Path(charm["directory_path"]):
23+
if bases_index is None or bases_index == charm["bases_index"]:
24+
return charm["file_path"]
25+
raise ValueError(f"Unable to find .charm file for {bases_index=} at {charm_path=}")
26+
27+
ops_test.build_charm = build_charm
28+
return ops_test
29+
30+
831
@pytest.fixture(scope="module")
932
async def charm(ops_test: OpsTest):
1033
"""Build the charm-under-test."""

tests/integration/ha_tests/test_self_healing.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242

4343
@pytest.mark.abort_on_fail
44-
@pytest.mark.ha_self_healing_tests
4544
async def test_build_and_deploy(ops_test: OpsTest) -> None:
4645
"""Build and deploy three unit of PostgreSQL."""
4746
# It is possible for users to provide their own cluster for HA testing. Hence, check if there
@@ -56,7 +55,7 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
5655
await ops_test.model.wait_for_idle(status="active", timeout=1000)
5756

5857

59-
@pytest.mark.ha_self_healing_tests
58+
@pytest.mark.unstable
6059
@pytest.mark.parametrize("process", DB_PROCESSES)
6160
async def test_kill_db_process(
6261
ops_test: OpsTest, process: str, continuous_writes, master_start_timeout
@@ -116,7 +115,7 @@ async def test_kill_db_process(
116115
), "secondary not up to date with the cluster after restarting."
117116

118117

119-
@pytest.mark.ha_self_healing_tests
118+
@pytest.mark.unstable
120119
@pytest.mark.parametrize("process", DB_PROCESSES)
121120
async def test_freeze_db_process(
122121
ops_test: OpsTest, process: str, continuous_writes, master_start_timeout
@@ -182,7 +181,7 @@ async def test_freeze_db_process(
182181
), "secondary not up to date with the cluster after restarting."
183182

184183

185-
@pytest.mark.ha_self_healing_tests
184+
@pytest.mark.unstable
186185
@pytest.mark.parametrize("process", DB_PROCESSES)
187186
async def test_restart_db_process(
188187
ops_test: OpsTest, process: str, continuous_writes, master_start_timeout
@@ -235,7 +234,7 @@ async def test_restart_db_process(
235234
), "secondary not up to date with the cluster after restarting."
236235

237236

238-
@pytest.mark.ha_self_healing_tests
237+
@pytest.mark.unstable
239238
@pytest.mark.parametrize("process", [PATRONI_PROCESS])
240239
@pytest.mark.parametrize("signal", ["SIGTERM", "SIGKILL"])
241240
async def test_full_cluster_restart(
@@ -293,7 +292,7 @@ async def test_full_cluster_restart(
293292
assert total_expected_writes == actual_writes, "writes to the db were missed."
294293

295294

296-
@pytest.mark.ha_self_healing_tests
295+
@pytest.mark.unstable
297296
async def test_forceful_restart_without_data_and_transaction_logs(
298297
ops_test: OpsTest,
299298
continuous_writes,

0 commit comments

Comments
 (0)