Skip to content

Commit

Permalink
Add workflow for cos integration tests (#189)
Browse files Browse the repository at this point in the history
* Add workflow for cos integration tests

* Use make to run the tests
  • Loading branch information
sudeephb authored Mar 18, 2024
1 parent 25238ca commit dffb9dd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/cos_integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Integration tests with COS

on:
workflow_call:
workflow_dispatch:

jobs:
integration-tests-with-cos:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get IP address of the host
run: |
# Finding preferred source ip address by trying to reach destination 2.2.2.2
# This ip address will be used while enabling metallb
echo "IPADDR=$(ip -4 -j route get 2.2.2.2 | jq -r '.[] | .prefsrc')" >> $GITHUB_ENV
- name: Setup lxd controller
uses: charmed-kubernetes/actions-operator@main
with:
# The juju version can be any stable version, as long as it is the same as libjuju version used.
# Currently, 3.1 is used to keep the version consistent with functional tests (func31)
# If, for example, 3.5/stable is used here in the future, the `update python-libjuju dependancy..`
# step below should also specify `...3.5.x/g'..` so it updates requirements.txt with the correct version.
juju-channel: 3.1/stable
provider: lxd
- name: Save lxd controller name
id: lxd-controller
# The `CONTROLLER_NAME` envvar is set by the actions-operator action
run: echo "name=$CONTROLLER_NAME" >> $GITHUB_OUTPUT
- name: Setup k8s controller
uses: charmed-kubernetes/actions-operator@main
with:
juju-channel: 3.1/stable
provider: microk8s
channel: 1.28-strict/stable
microk8s-addons: "hostpath-storage dns metallb:${{ env.IPADDR }}-${{ env.IPADDR }}"
- name: Save k8s controller name
id: k8s-controller
# The `CONTROLLER_NAME` envvar is set by the actions-operator action
run: echo "name=$CONTROLLER_NAME" >> $GITHUB_OUTPUT
- name: Fix microk8s permissions
run: |
chmod -R ugo+rwX ~/.kube
- name: Update python-libjuju dependency to match juju
# The juju CLI version and libjuju version(specified in requirements.txt) should be compatible.
# This replaces the libjuju version in requirements.txt and
# makes sure the same version is used, even if it has a different/incompatible version.
run: sed -E -i 's/^\s*juju\s*~=.+/ juju~=3.1.0/g' tests/integration/requirements.txt
- name: Run integration tests
run: make integration
env:
K8S_CONTROLLER: ${{ steps.k8s-controller.outputs.name }}
LXD_CONTROLLER: ${{ steps.lxd-controller.outputs.name }}
- name: Dump debug log
if: failure()
run: for ctl in $(juju controllers --format json | jq -r '.controllers | keys[]'); do for mdl in $(juju models --format json | jq -r '.models[].name' | grep -v "admin/controller"); do juju debug-log -m $ctl:$mdl --replay --ms --no-tail; done; done || true
shell: bash
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ functional31:
@echo "Executing functional tests using built charm at ${PROJECTPATH}"
@CHARM_LOCATION=${PROJECTPATH} tox -e func31 -- ${FUNC_ARGS}

integration:
@echo "Executing integration tests with COS"
@tox -e integration -- ${INTEGRATION_ARGS}

test: lint unittests functional
@echo "Tests completed for charm ${CHARM_NAME}."

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jinja2
juju~=3.3.0 # must be compatible with the juju CLI version installed by CI
juju~=3.1.0 # must be compatible with the juju CLI version installed by CI
pytest
pytest-operator
prometheus-client
Expand Down
22 changes: 15 additions & 7 deletions tests/integration/test_cos_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@pytest.mark.skip_if_deployed
async def test_setup_and_deploy(series, channel, lxd_ctl, k8s_ctl, lxd_model, k8s_model):
"""Setup models and then deploy Hardware Observer and COS."""
await _deploy_cos(channel, k8s_model)
await _deploy_cos(channel, k8s_ctl, k8s_model)

await _deploy_hardware_observer(series, channel, lxd_model)

Expand Down Expand Up @@ -122,14 +122,22 @@ async def _export_mock_metrics(lxd_model):
await hardware_observer_unit.run(run_export_mock_metrics_cmd)


async def _deploy_cos(channel, model):
async def _deploy_cos(channel, ctl, model):
"""Deploy COS on the existing k8s cloud."""
await model.deploy(
# Deploying via CLI because of https://github.com/juju/python-libjuju/issues/1032.
cmd = [
"juju",
"deploy",
"cos-lite",
channel=channel,
trust=True,
overlays=[str(Path(__file__).parent.resolve() / "offers-overlay.yaml")],
)
"--channel",
channel,
"--trust",
"-m",
f"{ctl.controller_name}:{model.name}",
"--overlay",
str(Path(__file__).parent.resolve() / "offers-overlay.yaml"),
]
subprocess.run(cmd, check=True)


async def _deploy_hardware_observer(series, channel, model):
Expand Down

0 comments on commit dffb9dd

Please sign in to comment.