diff --git a/.github/workflows/integration_test_juju3.yaml b/.github/workflows/integration_test_juju3.yaml new file mode 100644 index 00000000..3bcfaeb7 --- /dev/null +++ b/.github/workflows/integration_test_juju3.yaml @@ -0,0 +1,28 @@ +name: integration-tests-juju3 + +on: + pull_request: + workflow_call: + +jobs: + integration-test-juju3: + name: Integration Test on Juju3 + uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main + secrets: inherit + with: + extra-arguments: >- + --openstack-rc=${GITHUB_WORKSPACE}/openrc + --kube-config=${GITHUB_WORKSPACE}/kube-config + --screenshot-dir=/tmp + juju-channel: 3.1/stable + channel: 1.27-strict/stable + modules: '["test_addon", "test_core"]' + pre-run-script: | + -c "sudo microk8s enable hostpath-storage + sudo microk8s kubectl -n kube-system rollout status -w deployment/hostpath-provisioner + sudo microk8s config > ${GITHUB_WORKSPACE}/kube-config + chmod +x tests/integration/pre_run_script_juju3.sh + ./tests/integration/pre_run_script_juju3.sh" + test-tox-env: "integration-juju3" + setup-devstack-swift: true + trivy-image-config: ./trivy.yaml diff --git a/src/charm.py b/src/charm.py index 2bc251a8..8dfe1024 100755 --- a/src/charm.py +++ b/src/charm.py @@ -604,13 +604,15 @@ def _current_effective_db_info(self) -> Optional[types_.DatabaseConfig]: relation = self.model.get_relation(self._DATABASE_RELATION_NAME) if not relation or relation.app is None: return None - host, port = self._parse_database_endpoints(relation.data[relation.app].get("endpoints")) + host, port = self._parse_database_endpoints( + self.database.fetch_relation_field(relation.id, "endpoints") + ) return types_.DatabaseConfig( hostname=host, port=port, - database=relation.data[relation.app].get("database"), - username=relation.data[relation.app].get("username"), - password=relation.data[relation.app].get("password"), + database=self.database.fetch_relation_field(relation.id, "database"), + username=self.database.fetch_relation_field(relation.id, "username"), + password=self.database.fetch_relation_field(relation.id, "password"), ) def _test_database_connectivity(self): diff --git a/tests/integration/pre_run_script_juju3.sh b/tests/integration/pre_run_script_juju3.sh new file mode 100644 index 00000000..ef7171c4 --- /dev/null +++ b/tests/integration/pre_run_script_juju3.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. + +# Pre-run script for integration test operator-workflows action. +# https://github.com/canonical/operator-workflows/blob/main/.github/workflows/integration_test.yaml + +# Jenkins machine agent charm is deployed on lxd and Jenkins-k8s server charm is deployed on +# microk8s. + +TESTING_MODEL="$(juju switch)" + +# lxd should be install and init by a previous step in integration test action. +echo "bootstrapping lxd juju controller" +sg snap_microk8s -c "microk8s status --wait-ready" +sg snap_microk8s -c "juju bootstrap localhost localhost" + +echo "Switching to testing model" +sg snap_microk8s -c "juju switch $TESTING_MODEL" diff --git a/tests/integration/requirements_juju3.txt b/tests/integration/requirements_juju3.txt new file mode 100644 index 00000000..423073a8 --- /dev/null +++ b/tests/integration/requirements_juju3.txt @@ -0,0 +1,13 @@ +cosl +juju>=3.2.2 +kubernetes>=25.3,<26 +macaroonbakery==1.3.1 +pillow +pytest +pytest-cov +pytest-operator +python-keystoneclient +python-swiftclient +requests +types-PyYAML +types-requests diff --git a/tox.ini b/tox.ini index ac4adeac..80288491 100644 --- a/tox.ini +++ b/tox.ini @@ -114,3 +114,11 @@ deps = -r{toxinidir}/tests/integration/requirements.txt commands = pytest {[vars]tst_path} -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs} + +[testenv:integration-juju3] +description = Run integration tests using Juju 3 +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/tests/integration/requirements_juju3.txt +commands = + pytest {[vars]tst_path} -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}