Skip to content

Commit

Permalink
[DPE-2994] No more relational databag usage (#166)
Browse files Browse the repository at this point in the history
* Removing databag usage from the charm
  • Loading branch information
juditnovak committed Nov 17, 2023
1 parent 800974d commit 8eab4c4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/integration_test_juju3.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/pre_run_script_juju3.sh
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions tests/integration/requirements_juju3.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 8eab4c4

Please sign in to comment.