Skip to content

Commit

Permalink
Merge branch 'main' into metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Deezzir authored Oct 2, 2024
2 parents ad6dd94 + ca2306f commit 6227f7e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
47 changes: 30 additions & 17 deletions .github/workflows/cos_integration.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,72 @@
name: Integration tests with COS
name: COS Integration tests

on:
workflow_call:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
branches: [main]
paths-ignore:
- "**.md"
- "**.rst"

jobs:
integration-tests-with-cos:
runs-on: ubuntu-latest
integration:
runs-on: ubuntu-22.04
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
# If you update it here, update it also in tests/integration/requirements.txt and 'Setup k8s controller' step below
juju-channel: 3.5/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
# The juju version can be any stable version, as long as it is the same as libjuju version used.
# If you update it here, update it also in tests/integration/requirements.txt and 'Setup lxd controller' step above
juju-channel: 3.5/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
run: chmod -R ugo+rwX ~/.kube

- name: Run integration tests
run: make integration
run: tox -e 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
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: 2 additions & 2 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jinja2
juju~=3.1.0 # must be compatible with the juju CLI version installed by CI
juju~=3.5.0 # must be compatible with the juju CLI version installed by CI - see .github/workflows/cos_integration.yaml
pytest
pytest-operator
prometheus-client
pyinstaller # required to bundle export_mock_metrics script to send it to hw-oberver unit
tenacity
tenacity
24 changes: 12 additions & 12 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def test_validate_exporter_config_super_failed(self, mock_super):
mock_super.return_value.validate_exporter_configs.return_value = (False, "something wrong")
self.assertEqual((False, "something wrong"), self.exporter.validate_exporter_configs())

mock_super.return_value.validate_exporter_configs.accept_called()
mock_super.return_value.validate_exporter_configs.assert_called()
self.exporter.redfish_conn_params_valid.assert_not_called()

@mock.patch("service.HardwareExporter.enabled_tools", new_callable=mock.PropertyMock)
Expand Down Expand Up @@ -771,10 +771,10 @@ def test_install_resource_restart(self, mock_systemd):

self.exporter.install_resources()

self.exporter.strategy.install.accept_called()
self.exporter.check_active.accept_called()
mock_systemd.service_stop.accept_called_with(self.exporter.exporter_name)
mock_systemd.service_restart.accept_called_with(self.exporter.exporter_name)
self.exporter.strategy.install.assert_called()
self.exporter.check_active.assert_called()
mock_systemd.service_stop.assert_called_with(self.exporter.exporter_name)
mock_systemd.service_restart.assert_called_with(self.exporter.exporter_name)

@mock.patch("service.systemd", return_value=mock.MagicMock())
def test_install_resource_no_restart(self, mock_systemd):
Expand All @@ -784,16 +784,16 @@ def test_install_resource_no_restart(self, mock_systemd):

self.exporter.install_resources()

self.exporter.strategy.install.accept_called()
self.exporter.check_active.accept_called()
mock_systemd.service_stop.accept_not_called()
mock_systemd.service_restart.accept_not_called()
self.exporter.strategy.install.assert_called()
self.exporter.check_active.assert_called()
mock_systemd.service_stop.assert_not_called()
mock_systemd.service_restart.assert_not_called()

def test_resource_exists(self):
self.exporter.strategy = mock.MagicMock()

self.exporter.resources_exist()
self.exporter.strategy.check.accept_called()
self.exporter.strategy.check.assert_called()

def test_resources_exist(self):
self.exporter.strategy = mock.MagicMock()
Expand All @@ -802,15 +802,15 @@ def test_resources_exist(self):
result = self.exporter.resources_exist()

self.assertEqual(result, "some result")
self.exporter.strategy.check.accept_called()
self.exporter.strategy.check.assert_called()

def test_resource_remove(self):
self.exporter.strategy = mock.MagicMock()

result = self.exporter.remove_resources()
self.assertEqual(result, True)

self.exporter.strategy.remove.accept_called()
self.exporter.strategy.remove.assert_called()


class TestDCGMSnapExporter(unittest.TestCase):
Expand Down

0 comments on commit 6227f7e

Please sign in to comment.