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

Frontend charm integration tests fix with a self hosted runner #54

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0d44757
Define the dependencies more exactly to get the integration tests run…
mz2 Jun 7, 2023
97e8d4c
juju 3.1/stable -> 3.0/stable
mz2 Jun 7, 2023
a055701
Install strictly confined versions of juju and microk8s.
mz2 Jun 7, 2023
672ea62
Use microk8s 1.27-strict/stable
mz2 Jun 7, 2023
6c11eb5
Adds package repo access to the integration test job
mz2 Jun 7, 2023
5c149e2
Add the containerd template modification
mz2 Jun 7, 2023
11cf30b
Adds some missing sudoing
mz2 Jun 7, 2023
6e8375a
From >> to tee -a
mz2 Jun 7, 2023
97f1531
Drop the docker login
mz2 Jun 7, 2023
1478f45
Oops, escaping quotes did not work quite right there.
mz2 Jun 7, 2023
b03e015
Adjust the integration test scenario, expecting rather than raising o…
mz2 Jun 7, 2023
55b9436
Drops the debugging intended branch from the list of branches to trig…
mz2 Jun 7, 2023
cde6b80
Change to maintenance status instead for clarity, since configuration…
mz2 Jun 7, 2023
1ed9d5f
Adds the "integration-test-fix" branch into the rule still
mz2 Jun 7, 2023
0a30cee
Adds a 503 response / maintenance status to the frontend application …
mz2 Jun 7, 2023
bf2859c
Removs the redundant import StoredState
mz2 Jun 7, 2023
2fc065f
Add a `microk8s status --wait-ready`
mz2 Jun 7, 2023
06a258e
Adds missing sudo
mz2 Jun 7, 2023
4af3b2a
Merge branch 'main' into integration-test-fix
nadzyah Jun 20, 2023
0db5736
Merge branch 'main' into integration-test-fix
nadzyah Jun 22, 2023
8417af7
Merge branch 'main' into integration-test-fix
nadzyah Jun 27, 2023
a3a5404
Let's try with the microk8s version + libpyjuju < 3.1
mz2 Jul 2, 2023
e90849c
Merge branch 'integration-test-fix' of github.com:canonical/test_obse…
mz2 Jul 2, 2023
234b1aa
Back to 5.13/stable for lxd
mz2 Jul 2, 2023
fd3ed35
2.9/stable -> 3.0/stable
mz2 Jul 2, 2023
63f4d6f
Trying with the non-strictly confined microk8s
mz2 Jul 2, 2023
acf47ce
Adds "publish-charm" job
mz2 Jul 2, 2023
b03dddb
Adds promotion action
mz2 Jul 2, 2023
7348559
Swap to self-hosted runners
mz2 Oct 26, 2023
9521314
LXD 5.13 => 5.19
mz2 Oct 26, 2023
6a53221
Run also the integration tests
mz2 Oct 26, 2023
bcd4cf5
Move publishing charm to a separate workflow
mz2 Oct 26, 2023
08d8c5c
juju 3.0 => juju 3.2
mz2 Oct 26, 2023
977550e
juju 3.0 -> 3.2
mz2 Oct 26, 2023
9f8ccec
Adds a now required trailing comma
mz2 Oct 26, 2023
422ee3b
microk8s 1.27 => 1.28
mz2 Oct 26, 2023
4068f04
Use mz2 fork of the action operator
mz2 Oct 26, 2023
1b1e212
Juju classic confinement = off too
mz2 Oct 26, 2023
b0b420d
Pulls in origin/main
mz2 Oct 26, 2023
fb4817a
Introduces a working integration testing workflow for the frontend charm
mz2 Dec 9, 2023
5a75762
Update .github/workflows/publish_charms.yml
mz2 Dec 9, 2023
4f5cc55
Merges in origin/main
mz2 Dec 9, 2023
188f2ba
Merge branch 'integration-test-fix-with-hosted-runners' of github.com…
mz2 Dec 9, 2023
418cdbd
Remove publish_charms.yml that has been long since been separately added
mz2 Dec 9, 2023
ff57b22
Removes release-charms.yml that has long been superseded
mz2 Dec 9, 2023
61e6d4f
Removes also frontend_charm_promote.yml that is not really in scope o…
mz2 Dec 9, 2023
9e0ff27
From 3.2 requirement => 2.9 requirement
mz2 Dec 9, 2023
943e0e6
Removes the stray reformatting of frontend charm.py
mz2 Dec 9, 2023
acb0dd8
Remove another example of accidental reformatting
mz2 Dec 9, 2023
f9528e3
Run the integration test workflow manually, on main branch and when P…
mz2 Dec 9, 2023
3ded998
Run frontend integration tests also on branches where there are chang…
mz2 Dec 9, 2023
5bcbd1c
Removes a stray change to frontend_charm_analysis.yml
mz2 Dec 9, 2023
ad2ae8b
An explanatory comment re: pinning macaroonbakery to 1.3.2
mz2 Dec 11, 2023
09e1425
Adds docker.io mirroring
mz2 Dec 11, 2023
e465185
Fix the trigger so the workflow triggers on approved PRs
mz2 Dec 11, 2023
4814f96
Reference the setup steps from main
mz2 Dec 11, 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
8 changes: 4 additions & 4 deletions .github/workflows/frontend_charm_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
branches:
- main
push:
branches: ["main"]
branches: ["main", "integration-test-fix"]
tags: ["v*.*.*"]

jobs:
lint-report:
name: Lint and format report
runs-on: ubuntu-22.04
runs-on: [self-hosted, linux, large]
steps:
- uses: actions/checkout@v3
- name: Install tox
Expand All @@ -23,7 +23,7 @@ jobs:

static-analysis:
name: Static analysis
runs-on: ubuntu-22.04
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v3
- name: Install tox
Expand All @@ -36,7 +36,7 @@ jobs:

unit-tests-with-coverage:
name: Unit tests
runs-on: ubuntu-22.04
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v3
- name: Install tox
Expand Down
42 changes: 12 additions & 30 deletions .github/workflows/frontend_charm_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
name: Run charm tests
on:
push:
branches: ["main"]
branches: ["main", "integration-test-fix*"]
tags: ["v*.*.*"]

jobs:
integration-test:
permissions:
contents: read
packages: read

name: Integration tests
runs-on: ubuntu-22.04
runs-on: [self-hosted, jammy, xlarge]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup LXD
uses: canonical/setup-lxd@main
with:
channel: 5.13/stable
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
uses: actions/checkout@v4
- name: Set up microk8s
uses: canonical/certification-github-workflows/.github/actions/microk8s-setup@microk8s-setup-action
Copy link
Collaborator Author

@mz2 mz2 Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup steps turned out to be more extensive on self hosted runners, and since this is all repetitive boilerplate that becomes relevant again when we want to integration test any other charmed part of our stack, I moved the whole lot to a reusable composite action. Same story below re: the archive-charm-testing-artifacts

- name: Run integration tests
run: tox -e integration
- name: Archive Tested Charm
uses: actions/upload-artifact@v3
if: ${{ github.ref_name == 'main' }}
with:
name: tested-charm
path: .tox/**/test-observer-frontend_ubuntu-22.04-amd64.charm
retention-days: 5
- name: Archive charmcraft logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: charmcraft-logs
path: /home/runner/.local/state/charmcraft/log/*.log
- name: Archive juju crashdump
if: failure()
uses: actions/upload-artifact@v3
with:
name: juju-crashdump
path: juju-crashdump-*.tar.xz
- name: Archive charm testing outputs
uses: canonical/certification-github-workflows/.github/actions/archive-charm-testing-artifacts@microk8s-setup-action
defaults:
run:
working-directory: ./frontend/charm

43 changes: 43 additions & 0 deletions .github/workflows/frontend_charm_promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Promote Charm

on:
workflow_dispatch:
inputs:
promotion:
type: choice
description: Channel to promote from
options:
- edge -> beta
- beta -> candidate
- candidate -> stable

jobs:
promote:
name: Promote Charm
runs-on: [self-hosted, linux]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set target channel
env:
PROMOTE_FROM: ${{ github.event.inputs.promotion }}
run: |
if [ "${PROMOTE_FROM}" == "edge -> beta" ]; then
echo "promote-from=edge" >> ${GITHUB_ENV}
echo "promote-to=beta" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "beta -> candidate" ]; then
echo "promote-from=beta" >> ${GITHUB_ENV}
echo "promote-to=candidate" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "candidate -> stable" ]; then
echo "promote-from=candidate" >> ${GITHUB_ENV}
echo "promote-to=stable" >> ${GITHUB_ENV}
fi
- name: Promote Charm
uses: canonical/charming-actions/[email protected]
with:
base-channel: 22.04
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
destination-channel: latest/${{ env.promote-to }}
origin-channel: latest/${{ env.promote-from }}
charmcraft-channel: latest/stable
4 changes: 2 additions & 2 deletions .github/workflows/publish_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:

jobs:
build-and-push-image:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux, xlarge]
mz2 marked this conversation as resolved.
Show resolved Hide resolved
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -43,8 +43,8 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

build-and-push-charm:
runs-on: [self-hosted, linux, xlarge]
needs: build-and-push-image
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publish_charms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run charm tests
on:
push:
branches: ["main"]
tags: ["v*.*.*"]

jobs:
publish-charm:
name: Publish Charm
needs: integration-test
runs-on: [self-hosted, linux]
if: ${{ github.ref_name == 'main' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install charmcraft
run: sudo snap install charmcraft --classic
- name: Fetch Tested Charm
mz2 marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/download-artifact@v3
with:
name: tested-charm
- name: Move charm in current directory
run: find ./ -name test-observer-frontend_ubuntu-22.04-amd64.charm -exec mv -t ./ {} \;
- name: Select Charmhub channel
uses: canonical/charming-actions/[email protected]
id: channel
- name: Upload charm to Charmhub
uses: canonical/charming-actions/[email protected]
with:
credentials: "${{ secrets.CHARMHUB_AUTH_API }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "${{ steps.channel.outputs.name }}"
2 changes: 1 addition & 1 deletion .github/workflows/publish_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:

jobs:
build-and-push-frontend-image:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
mz2 marked this conversation as resolved.
Show resolved Hide resolved
permissions:
contents: read
packages: write
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/release_charms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
# pull_request:
# branches:
# - main
push:
branches: ["a-branch-that-definitely-does-not-exist"]
# tags: ["v*.*.*"]

jobs:
build:
name: Release test-observer-api charm to edge
runs-on: [self-hosted, linux]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
#- name: Select charmhub channel
# uses: canonical/charming-actions/[email protected]
# id: channel
- name: Upload charm to charmhub
uses: canonical/charming-actions/[email protected]
with:
charm-path: "backend/charm"
credentials: "${{ secrets.CHARMHUB_AUTH_API }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
upload-image: "true"
channel: edge # "${{ steps.channel.outputs.name }}"
2 changes: 1 addition & 1 deletion .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ concurrency:
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux, large]
defaults:
run:
working-directory: backend
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ concurrency:
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux, large]
defaults:
run:
working-directory: frontend
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Observe the status and state of certification tests for various artefacts
- `juju` 3.1 or later (`sudo snap install juju --channel=3.1/stable`)
- `microk8s` 1.27 or later (`sudo snap install microk8s --channel=1.27-strict/stable`) + [permission setup steps after install](https://juju.is/docs/sdk/set-up-your-development-environment#heading--install-microk8s)
- `terraform` 1.4.6 or later (`sudo snap install terraform --classic`)
- `lxd` 5.13 or later (`sudo snap install lxd --channel=5.13/stable` or `sudo snap refresh lxd --channel=5.13/stable` if already installed) + `lxd init --auto` after install.
- `lxd` 5.19 or later (`sudo snap install lxd --channel=5.19/stable` or `sudo snap refresh lxd --channel=5.19/stable` if already installed) + `lxd init --auto` after install.
- `charmcraft` 2.3.0 or later (`sudo snap install charmcraft --channel=2.x/stable --classic`)
- optional: `jhack` for all kinds of handy Juju and charm SDK development and debugging operations (`sudo snap install jhack`)

Expand Down
2 changes: 1 addition & 1 deletion backend/charm/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |
summary: |
API and dashboard to observe the status of artifact (snaps, debs, etc) test status
assumes:
- juju >= 2.9
- juju >=3.2
- k8s-api
containers:
api:
Expand Down
2 changes: 1 addition & 1 deletion backend/charm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ops >= 1.5.0
ops >= 2.8.0
requests==2.31.0
3 changes: 2 additions & 1 deletion frontend/charm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ops >= 2.2.0
ops >= 2.8.0
macaroonbakery==1.3.2
32 changes: 24 additions & 8 deletions frontend/charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(self, *args):
self.pebble_service_name = "test-observer-frontend"
self.container = self.unit.get_container("frontend")

self.framework.observe(self.on.frontend_pebble_ready, self._update_layer_and_restart)
self.framework.observe(
self.on.frontend_pebble_ready, self._update_layer_and_restart
)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(
self.on.test_observer_rest_api_relation_joined,
Expand Down Expand Up @@ -83,7 +85,9 @@ def _config_is_valid(self, config) -> Tuple[bool, str]:
def _on_rest_api_relation_update(self, event):
api_hostname = event.relation.data[event.app].get("hostname")
api_port = event.relation.data[event.app].get("port")
logger.debug(f"API hostname: {api_hostname}, port: {api_port} (app: {event.app})")
logger.debug(
f"API hostname: {api_hostname}, port: {api_port} (app: {event.app})"
)
self._update_layer_and_restart(event)

def _on_rest_api_relation_broken(self, event):
Expand Down Expand Up @@ -152,7 +156,9 @@ def html_503(self) -> str:
"""

def _update_layer_and_restart(self, event):
self.unit.status = MaintenanceStatus(f"Updating {self.pebble_service_name} layer")
self.unit.status = MaintenanceStatus(
f"Updating {self.pebble_service_name} layer"
)

if self.container.can_connect():
api_url = self._api_url
Expand All @@ -170,7 +176,9 @@ def _update_layer_and_restart(self, event):
else:
self._handle_no_api_relation()
else:
self.unit.status = WaitingStatus("Waiting for Pebble for API to set available state")
self.unit.status = WaitingStatus(
"Waiting for Pebble for API to set available state"
)

@property
def _api_url(self) -> str | None:
Expand All @@ -182,7 +190,9 @@ def _api_url(self) -> str | None:

relation_data = api_relation.data[api_relation.app]
if not relation_data:
self.unit.status = WaitingStatus("Waiting for test observer api relation data")
self.unit.status = WaitingStatus(
"Waiting for test observer api relation data"
)
return

hostname = relation_data["hostname"]
Expand Down Expand Up @@ -211,11 +221,17 @@ def _handle_no_api_relation(self):
self.html_503(),
make_dirs=True,
)
self.container.add_layer(self.pebble_service_name, self._pebble_layer, combine=True)
self.container.add_layer(
self.pebble_service_name, self._pebble_layer, combine=True
)
self.container.restart(self.pebble_service_name)
self.unit.status = MaintenanceStatus("test-observer-rest-api relation not connected.")
self.unit.status = MaintenanceStatus(
"test-observer-rest-api relation not connected."
)
else:
self.unit.status = WaitingStatus("Waiting for Pebble for API to set maintenance state")
self.unit.status = WaitingStatus(
"Waiting for Pebble for API to set maintenance state"
)

@property
def _pebble_layer(self):
Expand Down
9 changes: 4 additions & 5 deletions frontend/charm/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@


@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test: OpsTest):
"""Build the charm-under-test and deploy it together with related charms.
async def test_build_and_deploy_without_backend(ops_test: OpsTest):
"""Build the charm-under-test and deploy it together without related charms.

Assert on the unit status before any relations/configurations take place.
"""
Expand All @@ -29,8 +29,7 @@ async def test_build_and_deploy(ops_test: OpsTest):
ops_test.model.deploy(charm, resources=resources, application_name=APP_NAME),
ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
raise_on_blocked=True,
timeout=1000,
status="maintenance",
timeout=2000,
),
)
4 changes: 3 additions & 1 deletion frontend/charm/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def test_relating(self):
harness.update_config({"test-observer-api-scheme": "https://"})
harness.begin()
rel_id = harness.add_relation("test-observer-rest-api", "backend")
harness.update_relation_data(rel_id, "backend", {"hostname": "teh-backend", "port": "443"})
harness.update_relation_data(
rel_id, "backend", {"hostname": "teh-backend", "port": "443"}
)

service = harness.model.unit.get_container("frontend").get_service(
"test-observer-frontend"
Expand Down
2 changes: 1 addition & 1 deletion frontend/charm/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ commands =
description = Run integration tests
deps =
pytest
juju
juju<=3.2
Copy link
Collaborator Author

@mz2 mz2 Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally <= 3.2 as opposed to for example >= 2.9 as is set in the charm metadata: the integration test environment is set to be 3.x (2.9 was not really behaving in the github runner context, which is possible to go investigate but probably not worth our while unless we get stuck in production 2.9 for a long time unexpectedly).

pytest-operator
-r {tox_root}/requirements.txt
commands =
Expand Down
Loading
Loading