From ce0f0213f9cfc25b4a01b3bcc425567318ad3fc1 Mon Sep 17 00:00:00 2001 From: Bartlomiej Gmerek <42570669+Gmerold@users.noreply.github.com> Date: Tue, 31 May 2022 08:40:45 +0200 Subject: [PATCH] Fix: Adding relation between orc8r-orchestrator and orc8r-prometheus-cache (#36) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Adding relation between orc8r-orchestrator and orc8r-prometheus-cache * Fix: Fixing fetching relation name from metadata in orc8r_base_db lib * Fixing static analysis * Fixing static analysis * Addressing review comments * Update orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base.py Co-authored-by: Javier Sánchez Fernández <32944505+sanchezfdezjavier@users.noreply.github.com> * Fixing lint * Fixing application status in case of missing relations * Fixing lint Co-authored-by: Javier Sánchez Fernández <32944505+sanchezfdezjavier@users.noreply.github.com> --- orchestrator-bundle/bundle-local.yaml | 22 ++--- .../nms-magmalte-operator/metadata.yaml | 4 +- .../nms-magmalte-operator/src/charm.py | 33 +++++--- .../tests/unit/test_charm.py | 4 +- .../nms-nginx-proxy-operator/metadata.yaml | 4 +- .../nms-nginx-proxy-operator/src/charm.py | 16 ++-- .../tests/unit/test_charm.py | 14 ++-- .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-accessd-operator/metadata.yaml | 1 + .../orc8r-bootstrapper-operator/metadata.yaml | 4 +- .../orc8r-bootstrapper-operator/src/charm.py | 15 ++-- .../tests/unit/test_charm.py | 6 +- orchestrator-bundle/orc8r-bundle/bundle.yaml | 22 ++--- .../orc8r-certifier-operator/metadata.yaml | 3 +- .../orc8r-certifier-operator/src/charm.py | 84 ++++++++++++++++--- .../src/client_relations.py | 24 ------ .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-configurator-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-ctraced-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-device-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-directoryd-operator/metadata.yaml | 1 + .../orc8r-eventd-operator/src/charm.py | 2 +- .../charms/magma_orc8r_libs/v0/orc8r_base.py | 41 ++++++++- .../magma_orc8r_libs/v0/orc8r_base_db.py | 18 ++-- .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-lte-operator/metadata.yaml | 1 + .../orc8r-nginx-operator/metadata.yaml | 7 +- .../orc8r-nginx-operator/src/charm.py | 29 ++++--- .../tests/unit/test_charm.py | 14 ++-- .../orc8r-orchestrator-operator/metadata.yaml | 10 ++- .../orc8r-orchestrator-operator/src/charm.py | 83 ++++++++++++++---- .../tests/unit/test_charm.py | 22 ++--- .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-policydb-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-smsd-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-state-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-subscriberdb-operator/metadata.yaml | 1 + .../magma_orc8r_libs/v0/orc8r_base_db.py | 2 +- .../orc8r-tenants-operator/metadata.yaml | 1 + 47 files changed, 345 insertions(+), 172 deletions(-) delete mode 100644 orchestrator-bundle/orc8r-certifier-operator/src/client_relations.py diff --git a/orchestrator-bundle/bundle-local.yaml b/orchestrator-bundle/bundle-local.yaml index bbe96ae6..0482cc53 100644 --- a/orchestrator-bundle/bundle-local.yaml +++ b/orchestrator-bundle/bundle-local.yaml @@ -198,18 +198,18 @@ applications: options: metrics_count_limit: 500000 relations: -- - nms-magmalte:certifier - - orc8r-certifier:certifier +- - nms-magmalte:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - nms-magmalte:db - postgresql-k8s:db -- - nms-nginx-proxy:certifier - - orc8r-certifier:certifier +- - nms-nginx-proxy:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - nms-nginx-proxy:magmalte - nms-magmalte:magmalte - - orc8r-accessd:db - postgresql-k8s:db -- - orc8r-bootstrapper:certifier - - orc8r-certifier:certifier +- - orc8r-bootstrapper:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - orc8r-certifier:db - postgresql-k8s:db - - orc8r-configurator:db @@ -224,12 +224,14 @@ relations: - postgresql-k8s:db - - orc8r-nginx:bootstrapper - orc8r-bootstrapper:bootstrapper -- - orc8r-nginx:certifier - - orc8r-certifier:certifier +- - orc8r-nginx:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - orc8r-nginx:obsidian - orc8r-obsidian:obsidian -- - orc8r-orchestrator:certifier - - orc8r-certifier:certifier +- - orc8r-orchestrator:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier +- - orc8r-orchestrator:metrics-endpoint + - orc8r-prometheus-cache:metrics-endpoint - - orc8r-policydb:db - postgresql-k8s:db - - orc8r-prometheus:alertmanager diff --git a/orchestrator-bundle/nms-magmalte-operator/metadata.yaml b/orchestrator-bundle/nms-magmalte-operator/metadata.yaml index 39cc08f4..373fbbb9 100644 --- a/orchestrator-bundle/nms-magmalte-operator/metadata.yaml +++ b/orchestrator-bundle/nms-magmalte-operator/metadata.yaml @@ -28,5 +28,7 @@ provides: requires: db: interface: pgsql - certifier: + limit: 1 + magma-orc8r-certifier: interface: magma-orc8r-certifier + limit: 1 diff --git a/orchestrator-bundle/nms-magmalte-operator/src/charm.py b/orchestrator-bundle/nms-magmalte-operator/src/charm.py index ccae901b..083af06f 100755 --- a/orchestrator-bundle/nms-magmalte-operator/src/charm.py +++ b/orchestrator-bundle/nms-magmalte-operator/src/charm.py @@ -13,7 +13,13 @@ from lightkube import Client from lightkube.models.core_v1 import SecretVolumeSource, Volume, VolumeMount from lightkube.resources.apps_v1 import StatefulSet -from ops.charm import ActionEvent, CharmBase +from ops.charm import ( + ActionEvent, + CharmBase, + PebbleReadyEvent, + RelationChangedEvent, + RelationJoinedEvent, +) from ops.framework import StoredState from ops.main import main from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus @@ -44,7 +50,8 @@ def __init__(self, *args): self._db.on.database_relation_joined, self._on_database_relation_joined ) self.framework.observe( - self.on.certifier_relation_changed, self._on_certifier_relation_changed + self.on.magma_orc8r_certifier_relation_changed, + self._on_magma_orc8r_certifier_relation_changed, ) self.framework.observe( self.on.get_admin_credentials_action, self._on_get_admin_credentials @@ -62,7 +69,7 @@ def __init__(self, *args): }, ) - def _on_magma_nms_magmalte_pebble_ready(self, event): + def _on_magma_nms_magmalte_pebble_ready(self, event: PebbleReadyEvent): if not self._relations_ready: event.defer() return @@ -85,7 +92,7 @@ def _create_master_nms_admin_user(self): logger.info(message) raise TimeoutError(message) - def _on_database_relation_joined(self, event): + def _on_database_relation_joined(self, event: RelationJoinedEvent): """ Event handler for database relation change. - Sets the event.database field on the database joined event. @@ -95,17 +102,17 @@ def _on_database_relation_joined(self, event): in the relation event. """ if self.unit.is_leader(): - event.database = self.DB_NAME + event.database = self.DB_NAME # type: ignore[attr-defined] else: event.defer() - def _on_certifier_relation_changed(self, event): + def _on_magma_orc8r_certifier_relation_changed(self, event: RelationChangedEvent): """Mounts certificates required by the magma-nms-magmalte.""" if not self._nms_certs_mounted: self.unit.status = MaintenanceStatus("Mounting NMS certificates...") self._mount_certifier_certs() - def _configure_pebble(self, event): + def _configure_pebble(self, event: PebbleReadyEvent): """Adds layer to pebble config if the proposed config is different from the current one.""" if self._container.can_connect(): plan = self._container.get_plan() @@ -175,7 +182,7 @@ def _pebble_layer(self) -> Layer: } ) - def _create_nms_admin_user_action(self, event): + def _create_nms_admin_user_action(self, event: ActionEvent): self._create_nms_admin_user( email=event.params["email"], password=event.params["password"], @@ -249,7 +256,7 @@ def _magma_nms_magmalte_volume_mounts(self) -> List[VolumeMount]: @property def _relations_ready(self) -> bool: """Checks whether required relations are ready.""" - required_relations = ["certifier", "db"] + required_relations = ["magma-orc8r-certifier", "db"] if missing_relations := [ relation for relation in required_relations if not self.model.get_relation(relation) ]: @@ -279,9 +286,9 @@ def _nms_certs_mounted(self) -> bool: def _domain_name(self): """Returns domain name provided by the orc8r-certifier relation.""" try: - certifier_relation = self.model.get_relation("certifier") - units = certifier_relation.units - return certifier_relation.data[next(iter(units))]["domain"] + certifier_relation = self.model.get_relation("magma-orc8r-certifier") + units = certifier_relation.units # type: ignore[union-attr] + return certifier_relation.data[next(iter(units))]["domain"] # type: ignore[union-attr] except (KeyError, StopIteration): return None @@ -290,7 +297,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/nms-magmalte-operator/tests/unit/test_charm.py b/orchestrator-bundle/nms-magmalte-operator/tests/unit/test_charm.py index b51e5cc6..ec9d2a5e 100755 --- a/orchestrator-bundle/nms-magmalte-operator/tests/unit/test_charm.py +++ b/orchestrator-bundle/nms-magmalte-operator/tests/unit/test_charm.py @@ -68,14 +68,14 @@ def test_given_charm_when_pebble_ready_event_emitted_and_no_relations_establishe self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for relation(s) to be created: certifier, db"), + BlockedStatus("Waiting for relation(s) to be created: magma-orc8r-certifier, db"), ) def test_given_charm_when_pebble_ready_event_emitted_and_certifier_relation_is_established_but_db_relation_is_missing_then_charm_goes_to_blocked_state( # noqa: E501 self, ): event = Mock() - relation_id = self.harness.add_relation("certifier", "orc8r-certifier") + relation_id = self.harness.add_relation("magma-orc8r-certifier", "orc8r-certifier") self.harness.add_relation_unit(relation_id, "orc8r-certifier/0") self.harness.charm.on.magma_nms_magmalte_pebble_ready.emit(event) diff --git a/orchestrator-bundle/nms-nginx-proxy-operator/metadata.yaml b/orchestrator-bundle/nms-nginx-proxy-operator/metadata.yaml index 8570d41b..77475a6c 100644 --- a/orchestrator-bundle/nms-nginx-proxy-operator/metadata.yaml +++ b/orchestrator-bundle/nms-nginx-proxy-operator/metadata.yaml @@ -17,7 +17,9 @@ resources: upstream-source: nginx:latest requires: - certifier: + magma-orc8r-certifier: interface: magma-orc8r-certifier + limit: 1 magmalte: interface: nms-magmalte + limit: 1 diff --git a/orchestrator-bundle/nms-nginx-proxy-operator/src/charm.py b/orchestrator-bundle/nms-nginx-proxy-operator/src/charm.py index 444effc8..2c10cffd 100755 --- a/orchestrator-bundle/nms-nginx-proxy-operator/src/charm.py +++ b/orchestrator-bundle/nms-nginx-proxy-operator/src/charm.py @@ -17,7 +17,7 @@ ) from lightkube.resources.apps_v1 import StatefulSet from lightkube.resources.core_v1 import ConfigMap -from ops.charm import CharmBase +from ops.charm import CharmBase, PebbleReadyEvent, RelationChangedEvent, RemoveEvent from ops.main import main from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from ops.pebble import Layer @@ -34,7 +34,9 @@ def __init__(self, *args): self.framework.observe( self.on.magma_nms_nginx_proxy_pebble_ready, self._on_magma_nms_nginx_proxy_pebble_ready ) - self.framework.observe(self.on.certifier_relation_changed, self._configure_nginx) + self.framework.observe( + self.on.magma_orc8r_certifier_relation_changed, self._configure_nginx + ) self.framework.observe(self.on.remove, self._on_remove) self.service_patcher = KubernetesServicePatch( charm=self, @@ -44,14 +46,14 @@ def __init__(self, *args): additional_labels={"app.kubernetes.io/part-of": "magma"}, ) - def _on_magma_nms_nginx_proxy_pebble_ready(self, event): + def _on_magma_nms_nginx_proxy_pebble_ready(self, event: PebbleReadyEvent): """Configures magma-nms-nginx-proxy pebble layer.""" if not self._relations_ready: event.defer() return self._configure_pebble(event) - def _configure_pebble(self, event): + def _configure_pebble(self, event: PebbleReadyEvent): if self._container.can_connect(): self.unit.status = MaintenanceStatus( f"Configuring pebble layer for {self._service_name}..." @@ -66,7 +68,7 @@ def _configure_pebble(self, event): self.unit.status = WaitingStatus("Waiting for container to be ready...") event.defer() - def _configure_nginx(self, event): + def _configure_nginx(self, event: RelationChangedEvent): if not self._nms_certs_mounted: self.unit.status = MaintenanceStatus("Mounting NMS certificates...") self._mount_certifier_certs() @@ -112,7 +114,7 @@ def _mount_certifier_certs(self) -> None: @property def _relations_ready(self) -> bool: """Checks whether required relations are ready.""" - required_relations = ["certifier", "magmalte"] + required_relations = ["magma-orc8r-certifier", "magmalte"] missing_relations = [ relation for relation in required_relations if not self.model.get_relation(relation) ] @@ -194,7 +196,7 @@ def _nginx_proxy_etc_configmap_created(self) -> bool: except httpx.HTTPError: return False - def _on_remove(self, event): + def _on_remove(self, event: RemoveEvent): client = Client() client.delete(ConfigMap, name="nginx-proxy-etc", namespace=self._namespace) diff --git a/orchestrator-bundle/nms-nginx-proxy-operator/tests/unit/test_charm.py b/orchestrator-bundle/nms-nginx-proxy-operator/tests/unit/test_charm.py index 6727a571..efe01803 100644 --- a/orchestrator-bundle/nms-nginx-proxy-operator/tests/unit/test_charm.py +++ b/orchestrator-bundle/nms-nginx-proxy-operator/tests/unit/test_charm.py @@ -29,7 +29,7 @@ def test_given_charm_when_pebble_ready_event_emitted_and_no_relations_establishe self.harness.charm.on.magma_nms_nginx_proxy_pebble_ready.emit(event) self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for relations: certifier, magmalte"), + BlockedStatus("Waiting for relations: magma-orc8r-certifier, magmalte"), ) def test_given_charm_when_pebble_ready_event_emitted_and_certifier_relation_is_missing_then_charm_goes_to_blocked_state( # noqa: E501 @@ -41,7 +41,7 @@ def test_given_charm_when_pebble_ready_event_emitted_and_certifier_relation_is_m self.harness.charm.on.magma_nms_nginx_proxy_pebble_ready.emit(event) self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for relations: certifier"), + BlockedStatus("Waiting for relations: magma-orc8r-certifier"), ) def test_given_charm_when_pebble_ready_event_emitted_and_magmalte_relation_is_missing_then_charm_goes_to_blocked_state( # noqa: E501 @@ -49,7 +49,9 @@ def test_given_charm_when_pebble_ready_event_emitted_and_magmalte_relation_is_mi ): self.harness.disable_hooks() event = Mock() - orc8r_relation_id = self.harness.add_relation("certifier", "orc8r-orchestrator") + orc8r_relation_id = self.harness.add_relation( + "magma-orc8r-certifier", "orc8r-orchestrator" + ) self.harness.add_relation_unit(orc8r_relation_id, "orc8r-orchestrator/0") self.harness.enable_hooks() self.harness.charm.on.magma_nms_nginx_proxy_pebble_ready.emit(event) @@ -63,7 +65,9 @@ def test_given_charm_when_pebble_ready_event_emitted_and_required_relations_are_ ): self.harness.disable_hooks() event = Mock() - orc8r_relation_id = self.harness.add_relation("certifier", "orc8r-orchestrator") + orc8r_relation_id = self.harness.add_relation( + "magma-orc8r-certifier", "orc8r-orchestrator" + ) self.harness.add_relation_unit(orc8r_relation_id, "orc8r-orchestrator/0") magmalte_relation_id = self.harness.add_relation("magmalte", "nms-magmalte") self.harness.add_relation_unit(magmalte_relation_id, "nms-magmalte/0") @@ -75,7 +79,7 @@ def test_given_charm_when_pebble_ready_event_emitted_and_required_relations_are_ def test_given_charm_when_certifier_relation_added_then_configure_nginx_action_called(self): event = Mock() with patch.object(MagmaNmsNginxProxyCharm, "_configure_nginx", event) as mock: - relation_id = self.harness.add_relation("certifier", "orc8r-certifier") + relation_id = self.harness.add_relation("magma-orc8r-certifier", "orc8r-certifier") self.harness.add_relation_unit(relation_id, "orc8r-certifier/0") self.harness.update_relation_data(relation_id, "orc8r-certifier/0", {"key": "value"}) mock.assert_called_once() diff --git a/orchestrator-bundle/orc8r-accessd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-accessd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-accessd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-accessd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-accessd-operator/metadata.yaml b/orchestrator-bundle/orc8r-accessd-operator/metadata.yaml index 38538cad..2b2b4450 100644 --- a/orchestrator-bundle/orc8r-accessd-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-accessd-operator/metadata.yaml @@ -21,3 +21,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-bootstrapper-operator/metadata.yaml b/orchestrator-bundle/orc8r-bootstrapper-operator/metadata.yaml index 660697d8..1a91e7c6 100644 --- a/orchestrator-bundle/orc8r-bootstrapper-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-bootstrapper-operator/metadata.yaml @@ -24,7 +24,9 @@ provides: interface: magma-orc8r-bootstrapper requires: - certifier: + magma-orc8r-certifier: interface: magma-orc8r-certifier + limit: 1 db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-bootstrapper-operator/src/charm.py b/orchestrator-bundle/orc8r-bootstrapper-operator/src/charm.py index 29666b3e..d5fa4559 100755 --- a/orchestrator-bundle/orc8r-bootstrapper-operator/src/charm.py +++ b/orchestrator-bundle/orc8r-bootstrapper-operator/src/charm.py @@ -9,7 +9,7 @@ from lightkube.core.exceptions import ApiError from lightkube.models.core_v1 import SecretVolumeSource, Volume, VolumeMount from lightkube.resources.apps_v1 import StatefulSet -from ops.charm import CharmBase +from ops.charm import CharmBase, PebbleReadyEvent, RelationJoinedEvent from ops.main import main from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from ops.pebble import Layer @@ -27,7 +27,8 @@ def __init__(self, *args): self._on_magma_orc8r_bootstrapper_pebble_ready, ) self.framework.observe( - self.on.certifier_relation_joined, self._on_certifier_relation_joined + self.on.magma_orc8r_certifier_relation_joined, + self._on_magma_orc8r_certifier_relation_joined, ) self._service_patcher = KubernetesServicePatch( charm=self, @@ -35,10 +36,10 @@ def __init__(self, *args): additional_labels={"app.kubernetes.io/part-of": "orc8r-app"}, ) - def _on_magma_orc8r_bootstrapper_pebble_ready(self, event): + def _on_magma_orc8r_bootstrapper_pebble_ready(self, event: PebbleReadyEvent): """Triggered when pebble is ready.""" if not self._certifier_relation_ready: - self.unit.status = BlockedStatus("Waiting for orc8r-certifier relation...") + self.unit.status = BlockedStatus("Waiting for magma-orc8r-certifier relation...") event.defer() return if not self._orc8r_certs_mounted: @@ -47,12 +48,12 @@ def _on_magma_orc8r_bootstrapper_pebble_ready(self, event): return self._configure_pebble(event) - def _on_certifier_relation_joined(self, event): + def _on_magma_orc8r_certifier_relation_joined(self, event: RelationJoinedEvent): if not self._orc8r_certs_mounted: self.unit.status = MaintenanceStatus("Mounting certificates from orc8r-certifier...") self._mount_orc8r_certs() - def _configure_pebble(self, event): + def _configure_pebble(self, event: PebbleReadyEvent): """Adds layer to pebble config if the proposed config is different from the current one.""" if self._container.can_connect(): pebble_layer = self._pebble_layer @@ -92,7 +93,7 @@ def _mount_orc8r_certs(self) -> None: @property def _certifier_relation_ready(self) -> bool: """Checks whether certifier relation is ready.""" - certifier_relation = self.model.get_relation("certifier") + certifier_relation = self.model.get_relation("magma-orc8r-certifier") if not certifier_relation or len(certifier_relation.units) == 0: return False return True diff --git a/orchestrator-bundle/orc8r-bootstrapper-operator/tests/unit/test_charm.py b/orchestrator-bundle/orc8r-bootstrapper-operator/tests/unit/test_charm.py index 54eb4517..ba10dba5 100644 --- a/orchestrator-bundle/orc8r-bootstrapper-operator/tests/unit/test_charm.py +++ b/orchestrator-bundle/orc8r-bootstrapper-operator/tests/unit/test_charm.py @@ -27,7 +27,7 @@ def test_given_charm_when_pebble_ready_event_emitted_and_no_relations_establishe self.harness.charm.on.magma_orc8r_bootstrapper_pebble_ready.emit(event) self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for orc8r-certifier relation..."), + BlockedStatus("Waiting for magma-orc8r-certifier relation..."), ) @patch("charm.MagmaOrc8rBootstrapperCharm._namespace", new_callable=PropertyMock) @@ -63,11 +63,11 @@ def test_given_ready_when_get_plan_then_plan_is_filled_with_magma_orc8r_bootstra updated_plan = self.harness.get_container_pebble_plan("magma-orc8r-bootstrapper").to_dict() self.assertEqual(expected_plan, updated_plan) - @patch("charm.MagmaOrc8rBootstrapperCharm._on_certifier_relation_joined") + @patch("charm.MagmaOrc8rBootstrapperCharm._on_magma_orc8r_certifier_relation_joined") def test_given_charm_when_certifier_relation_added_then_on_certifier_relation_joined_action_called( # noqa: E501 self, mock_on_certifier_relation_joined ): - relation_id = self.harness.add_relation("certifier", "orc8r-certifier") + relation_id = self.harness.add_relation("magma-orc8r-certifier", "orc8r-certifier") self.harness.add_relation_unit(relation_id, "orc8r-certifier/0") self.harness.update_relation_data(relation_id, "orc8r-certifier/0", {}) diff --git a/orchestrator-bundle/orc8r-bundle/bundle.yaml b/orchestrator-bundle/orc8r-bundle/bundle.yaml index b01c1355..07e95939 100644 --- a/orchestrator-bundle/orc8r-bundle/bundle.yaml +++ b/orchestrator-bundle/orc8r-bundle/bundle.yaml @@ -172,18 +172,18 @@ applications: scale: 1 trust: true relations: -- - nms-magmalte:certifier - - orc8r-certifier:certifier +- - nms-magmalte:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - nms-magmalte:db - postgresql-k8s:db -- - nms-nginx-proxy:certifier - - orc8r-certifier:certifier +- - nms-nginx-proxy:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - nms-nginx-proxy:magmalte - nms-magmalte:magmalte - - orc8r-accessd:db - postgresql-k8s:db -- - orc8r-bootstrapper:certifier - - orc8r-certifier:certifier +- - orc8r-bootstrapper:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - orc8r-certifier:db - postgresql-k8s:db - - orc8r-configurator:db @@ -198,12 +198,14 @@ relations: - postgresql-k8s:db - - orc8r-nginx:bootstrapper - orc8r-bootstrapper:bootstrapper -- - orc8r-nginx:certifier - - orc8r-certifier:certifier +- - orc8r-nginx:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier - - orc8r-nginx:obsidian - orc8r-obsidian:obsidian -- - orc8r-orchestrator:certifier - - orc8r-certifier:certifier +- - orc8r-orchestrator:magma-orc8r-certifier + - orc8r-certifier:magma-orc8r-certifier +- - orc8r-orchestrator:metrics-endpoint + - orc8r-prometheus-cache:metrics-endpoint - - orc8r-policydb:db - postgresql-k8s:db - - orc8r-prometheus:alertmanager diff --git a/orchestrator-bundle/orc8r-certifier-operator/metadata.yaml b/orchestrator-bundle/orc8r-certifier-operator/metadata.yaml index 5dccd628..4ed243af 100644 --- a/orchestrator-bundle/orc8r-certifier-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-certifier-operator/metadata.yaml @@ -29,9 +29,10 @@ storage: minimum-size: 1M provides: - certifier: + magma-orc8r-certifier: interface: magma-orc8r-certifier requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-certifier-operator/src/charm.py b/orchestrator-bundle/orc8r-certifier-operator/src/charm.py index 6df2b46d..2cbb8b19 100755 --- a/orchestrator-bundle/orc8r-certifier-operator/src/charm.py +++ b/orchestrator-bundle/orc8r-certifier-operator/src/charm.py @@ -14,13 +14,27 @@ from lightkube.resources.apps_v1 import StatefulSet from lightkube.resources.core_v1 import Secret from lightkube.resources.core_v1 import Secret as SecretRes -from ops.charm import CharmBase +from ops.charm import ( + CharmBase, + ConfigChangedEvent, + InstallEvent, + PebbleReadyEvent, + RelationChangedEvent, + RelationJoinedEvent, + RemoveEvent, +) from ops.main import main -from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus +from ops.model import ( + ActiveStatus, + BlockedStatus, + MaintenanceStatus, + ModelError, + Relation, + WaitingStatus, +) from ops.pebble import Layer, PathError from pgconnstr import ConnectionString # type: ignore[import] -from client_relations import ClientRelations from self_signed_certs_creator import ( generate_ca, generate_certificate, @@ -50,7 +64,6 @@ def __init__(self, *args): super().__init__(*args) self._container_name = self._service_name = "magma-orc8r-certifier" self._container = self.unit.get_container(self._container_name) - self.client_relations = ClientRelations(self, "client_relations") self._db = pgsql.PostgreSQLClient(self, "db") self.framework.observe(self.on.install, self._on_install) self.framework.observe( @@ -59,6 +72,14 @@ def __init__(self, *args): self.framework.observe( self._db.on.database_relation_joined, self._on_database_relation_joined ) + self.framework.observe( + self.on.magma_orc8r_certifier_relation_joined, + self._on_magma_orc8r_certifier_relation_joined, + ) + self.framework.observe( + self.on.magma_orc8r_certifier_relation_changed, + self._on_magma_orc8r_certifier_relation_changed, + ) self.framework.observe(self.on.remove, self._on_remove) self.framework.observe(self.on.config_changed, self._on_config_changed) self._nms_certs_secret_name = "nms-certs" @@ -84,14 +105,14 @@ def _write_metricsd_config_file(self): ) self._container.push(f"{self.BASE_CONFIG_PATH}/metricsd.yml", metricsd_config) - def _on_install(self, event): + def _on_install(self, event: InstallEvent): """Runs each time the charm is installed.""" if not self._container.can_connect(): event.defer() return self._write_metricsd_config_file() - def _on_config_changed(self, event): + def _on_config_changed(self, event: ConfigChangedEvent): if not self._domain_config_is_valid: self.unit.status = BlockedStatus("Config 'domain' is not valid") logger.warning("Config 'domain' not valid") @@ -106,7 +127,7 @@ def _on_config_changed(self, event): if not self._certs_are_mounted: self._mount_certifier_certs() - def _on_magma_orc8r_certifier_pebble_ready(self, event): + def _on_magma_orc8r_certifier_pebble_ready(self, event: PebbleReadyEvent): """Triggered when pebble is ready.""" if not self._db_relation_created: self.unit.status = BlockedStatus("Waiting for database relation to be created") @@ -122,7 +143,7 @@ def _on_magma_orc8r_certifier_pebble_ready(self, event): return self._configure_magma_orc8r_certifier(event) - def _on_database_relation_joined(self, event): + def _on_database_relation_joined(self, event: RelationJoinedEvent): """ Event handler for database relation change. - Sets the event.database field on the database joined event. @@ -132,7 +153,7 @@ def _on_database_relation_joined(self, event): in the relation event. """ if self.unit.is_leader(): - event.database = self.DB_NAME + event.database = self.DB_NAME # type: ignore[attr-defined] @property def _db_relation_created(self) -> bool: @@ -167,7 +188,7 @@ def _mount_certifier_certs(self): client.patch(StatefulSet, name=self.app.name, obj=stateful_set, namespace=self._namespace) logger.info("Additional volumes for certificates are mounted") - def _configure_magma_orc8r_certifier(self, event): + def _configure_magma_orc8r_certifier(self, event: PebbleReadyEvent): """Adds layer to pebble config if the proposed config is different from the current one.""" if self._container.can_connect(): self.unit.status = MaintenanceStatus("Configuring pod") @@ -182,7 +203,7 @@ def _configure_magma_orc8r_certifier(self, event): self.unit.status = WaitingStatus("Waiting for container to be ready...") event.defer() - def _on_remove(self, event): + def _on_remove(self, event: RemoveEvent): self.unit.status = MaintenanceStatus("Removing Magma Orc8r secrets...") self._delete_k8s_secret(secret_name=self._nms_certs_secret_name) @@ -401,7 +422,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None @@ -439,6 +460,45 @@ def _encode_in_base64(byte_string: bytes): """Encodes given byte string in Base64""" return base64.b64encode(byte_string).decode("utf-8") + def _on_magma_orc8r_certifier_relation_joined(self, event: RelationJoinedEvent): + if not self.unit.is_leader(): + return + self._update_relation_active_status( + relation=event.relation, is_active=self._service_is_running + ) + if not self._service_is_running: + event.defer() + return + + def _update_relation_active_status(self, relation: Relation, is_active: bool): + relation.data[self.unit].update( + { + "active": str(is_active), + } + ) + + @property + def _service_is_running(self) -> bool: + if self._container.can_connect(): + try: + self._container.get_service(self._service_name) + return True + except ModelError: + pass + return False + + def _on_magma_orc8r_certifier_relation_changed(self, event: RelationChangedEvent): + """Adds the domain field to relation's data bucket so that it can be used by the client. + To access data bucket, client should implement callback for on_relation_changed event. + To learn more about getting relation data, visit + [Juju docs](https://juju.is/docs/sdk/relations#heading--relation-data). + """ + domain = self.model.config["domain"] + + to_publish = [event.relation.data[self.unit]] + for bucket in to_publish: + bucket["domain"] = domain + @property def _namespace(self) -> str: return self.model.name diff --git a/orchestrator-bundle/orc8r-certifier-operator/src/client_relations.py b/orchestrator-bundle/orc8r-certifier-operator/src/client_relations.py deleted file mode 100644 index d8d71b7b..00000000 --- a/orchestrator-bundle/orc8r-certifier-operator/src/client_relations.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2020 Canonical Ltd. -# See LICENSE file for licensing details. - -import ops.framework -import ops.model - - -class ClientRelations(ops.framework.Object): - def __init__(self, charm: ops.charm.CharmBase, key: str): - super().__init__(charm, key) - self.unit = self.model.unit - self.framework.observe(charm.on["certifier"].relation_changed, self._on_relation_changed) - - def _on_relation_changed(self, event: ops.charm.RelationEvent): - """Adds the domain field to relation's data bucket so that it can be used by the client. - To access data bucket, client should implement callback for on_relation_changed event. - To learn more about getting relation data, visit - [Juju docs](https://juju.is/docs/sdk/relations#heading--relation-data). - """ - domain = self.model.config["domain"] - - to_publish = [event.relation.data[self.unit]] - for bucket in to_publish: - bucket["domain"] = domain diff --git a/orchestrator-bundle/orc8r-configurator-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-configurator-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-configurator-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-configurator-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-configurator-operator/metadata.yaml b/orchestrator-bundle/orc8r-configurator-operator/metadata.yaml index b1c85dc2..a3ac7935 100644 --- a/orchestrator-bundle/orc8r-configurator-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-configurator-operator/metadata.yaml @@ -22,3 +22,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-ctraced-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-ctraced-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-ctraced-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-ctraced-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-ctraced-operator/metadata.yaml b/orchestrator-bundle/orc8r-ctraced-operator/metadata.yaml index ea800630..f1d6b8fc 100644 --- a/orchestrator-bundle/orc8r-ctraced-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-ctraced-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-device-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-device-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-device-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-device-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-device-operator/metadata.yaml b/orchestrator-bundle/orc8r-device-operator/metadata.yaml index fa3afb4a..20356ee6 100644 --- a/orchestrator-bundle/orc8r-device-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-device-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-directoryd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-directoryd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-directoryd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-directoryd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-directoryd-operator/metadata.yaml b/orchestrator-bundle/orc8r-directoryd-operator/metadata.yaml index 6417d278..e0026281 100644 --- a/orchestrator-bundle/orc8r-directoryd-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-directoryd-operator/metadata.yaml @@ -21,3 +21,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-eventd-operator/src/charm.py b/orchestrator-bundle/orc8r-eventd-operator/src/charm.py index 7b2830c8..f1ac59a2 100755 --- a/orchestrator-bundle/orc8r-eventd-operator/src/charm.py +++ b/orchestrator-bundle/orc8r-eventd-operator/src/charm.py @@ -72,7 +72,7 @@ def _write_config_file(self): def _get_elasticsearch_config(self) -> tuple: elasticsearch_url = self.model.config.get("elasticsearch-url") - elasticsearch_url_split = elasticsearch_url.split(":") + elasticsearch_url_split = elasticsearch_url.split(":") # type: ignore[union-attr] return elasticsearch_url_split[0], elasticsearch_url_split[1] @property diff --git a/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base.py b/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base.py index f277c5bc..05c90e3b 100644 --- a/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base.py +++ b/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base.py @@ -59,7 +59,13 @@ def __init__(self, *args): from ops.charm import CharmBase from ops.framework import Object -from ops.model import ActiveStatus, MaintenanceStatus, ModelError, WaitingStatus +from ops.model import ( + ActiveStatus, + BlockedStatus, + MaintenanceStatus, + ModelError, + WaitingStatus, +) from ops.pebble import Layer # The unique Charmhub library identifier, never change it @@ -70,7 +76,7 @@ def __init__(self, *args): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 9 +LIBPATCH = 10 logger = logging.getLogger(__name__) @@ -81,18 +87,22 @@ def __init__( self, charm: CharmBase, startup_command: str, + required_relations: list = None, additional_environment_variables: dict = None, ): super().__init__(charm, "orc8r-base") self.charm = charm self.startup_command = startup_command + self.required_relations = required_relations or [] self.container_name = self.service_name = self.charm.meta.name service_name_with_underscores = self.service_name.replace("-", "_") + provided_relation_name = list(self.charm.meta.provides.keys())[0] + provided_relation_name_with_underscores = provided_relation_name.replace("-", "_") pebble_ready_event = getattr( self.charm.on, f"{service_name_with_underscores}_pebble_ready" ) relation_joined_event = getattr( - self.charm.on, f"{service_name_with_underscores}_relation_joined" + self.charm.on, f"{provided_relation_name_with_underscores}_relation_joined" ) self.container = self.charm.unit.get_container(self.container_name) self.framework.observe(pebble_ready_event, self._on_magma_orc8r_pebble_ready) @@ -104,6 +114,9 @@ def __init__( self.additional_environment_variables = {} def _on_magma_orc8r_pebble_ready(self, event): + if not self._relations_ready: + event.defer() + return self._configure_orc8r(event) def _configure_orc8r(self, event): @@ -173,6 +186,9 @@ def _on_relation_joined(self, event): self._update_relation_active_status( relation=event.relation, is_active=self._service_is_running ) + if not self._service_is_running: + event.defer() + return @property def _service_is_running(self) -> bool: @@ -190,3 +206,22 @@ def _update_relation_active_status(self, relation, is_active: bool): "active": str(is_active), } ) + + @property + def _relations_ready(self) -> bool: + """Checks whether required relations are ready.""" + if missing_relations := [ + relation for relation in self.required_relations if not self._relation_active(relation) + ]: + msg = f"Waiting for relations: {', '.join(missing_relations)}" + self.charm.unit.status = BlockedStatus(msg) + return False + return True + + def _relation_active(self, relation) -> bool: + try: + rel = self.model.get_relation(relation) + units = rel.units # type: ignore[union-attr] + return bool(rel.data[next(iter(units))]["active"]) # type: ignore[union-attr] + except (KeyError, StopIteration): + return False diff --git a/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index e236df49..78821197 100644 --- a/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-libs/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -58,13 +58,7 @@ def __init__(self, *args): import ops.lib from ops.charm import CharmBase from ops.framework import Object -from ops.model import ( - ActiveStatus, - BlockedStatus, - MaintenanceStatus, - ModelError, - WaitingStatus, -) +from ops.model import ActiveStatus, MaintenanceStatus, ModelError, WaitingStatus from ops.pebble import Layer from pgconnstr import ConnectionString # type: ignore[import] @@ -76,7 +70,7 @@ def __init__(self, *args): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 9 +LIBPATCH = 10 logger = logging.getLogger(__name__) @@ -98,8 +92,10 @@ def __init__( self.container_name = self.service_name = self.charm.meta.name self.container = self.charm.unit.get_container(self.container_name) service_name_with_underscores = self.service_name.replace("-", "_") + provided_relation_name = list(self.charm.meta.provides.keys())[0] + provided_relation_name_with_underscores = provided_relation_name.replace("-", "_") pebble_ready_event = getattr( - self.charm.on, f"{service_name_with_underscores}_pebble_ready" + self.charm.on, f"{provided_relation_name_with_underscores}_pebble_ready" ) relation_joined_event = getattr( self.charm.on, f"{service_name_with_underscores}_relation_joined" @@ -126,7 +122,7 @@ def _db_relation_created(self) -> bool: def _on_magma_orc8r_pebble_ready(self, event): if not self._db_relation_created: - self.charm.unit.status = BlockedStatus("Waiting for database relation to be created") + self.charm.unit.status = WaitingStatus("Waiting for database relation to be created") event.defer() return if not self._db_relation_established: @@ -199,7 +195,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-lte-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-lte-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-lte-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-lte-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-lte-operator/metadata.yaml b/orchestrator-bundle/orc8r-lte-operator/metadata.yaml index 9750a376..b4e07f1c 100644 --- a/orchestrator-bundle/orc8r-lte-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-lte-operator/metadata.yaml @@ -27,6 +27,7 @@ resources: requires: db: interface: pgsql + limit: 1 storage: config: diff --git a/orchestrator-bundle/orc8r-nginx-operator/metadata.yaml b/orchestrator-bundle/orc8r-nginx-operator/metadata.yaml index 6749d3df..02b7cbfb 100644 --- a/orchestrator-bundle/orc8r-nginx-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-nginx-operator/metadata.yaml @@ -4,7 +4,7 @@ name: magma-orc8r-nginx description: | Proxies traffic between nms and obsidian. - + summary: | Proxies traffic between nms and obsidian. @@ -21,7 +21,10 @@ resources: requires: bootstrapper: interface: magma-orc8r-bootstrapper - certifier: + limit: 1 + magma-orc8r-certifier: interface: magma-orc8r-certifier + limit: 1 obsidian: interface: magma-orc8r-obsidian + limit: 1 diff --git a/orchestrator-bundle/orc8r-nginx-operator/src/charm.py b/orchestrator-bundle/orc8r-nginx-operator/src/charm.py index 375d5792..d1a131be 100755 --- a/orchestrator-bundle/orc8r-nginx-operator/src/charm.py +++ b/orchestrator-bundle/orc8r-nginx-operator/src/charm.py @@ -18,7 +18,7 @@ from lightkube.models.meta_v1 import ObjectMeta from lightkube.resources.apps_v1 import StatefulSet from lightkube.resources.core_v1 import Service -from ops.charm import CharmBase +from ops.charm import CharmBase, PebbleReadyEvent, RelationChangedEvent, RemoveEvent from ops.main import main from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from ops.pebble import Layer @@ -35,7 +35,8 @@ def __init__(self, *args): self.on.magma_orc8r_nginx_pebble_ready, self._on_magma_orc8r_nginx_pebble_ready ) self.framework.observe( - self.on.certifier_relation_changed, self._on_certifier_relation_changed + self.on.magma_orc8r_certifier_relation_changed, + self._on_magma_orc8r_certifier_relation_changed, ) self.framework.observe(self.on.remove, self._on_remove) self.service_patcher = KubernetesServicePatch( @@ -52,14 +53,14 @@ def __init__(self, *args): additional_selectors={"app.kubernetes.io/name": "orc8r-nginx"}, ) - def _on_magma_orc8r_nginx_pebble_ready(self, event): + def _on_magma_orc8r_nginx_pebble_ready(self, event: PebbleReadyEvent): if not self._relations_ready: event.defer() return self._create_additional_orc8r_nginx_services() self._configure_pebble_layer(event) - def _on_certifier_relation_changed(self, event): + def _on_magma_orc8r_certifier_relation_changed(self, event: RelationChangedEvent): """Mounts certificates required by the nms-magmalte.""" if not self._orc8r_certs_mounted: self.unit.status = MaintenanceStatus("Mounting NMS certificates...") @@ -79,7 +80,7 @@ def _mount_certifier_certs(self) -> None: client.patch(StatefulSet, name=self.app.name, obj=stateful_set, namespace=self._namespace) logger.info("Additional K8s resources for magma-orc8r-nginx container applied!") - def _configure_pebble_layer(self, event): + def _configure_pebble_layer(self, event: PebbleReadyEvent): self.unit.status = MaintenanceStatus( f"Configuring pebble layer for {self._service_name}..." ) @@ -123,7 +124,7 @@ def _create_additional_orc8r_nginx_services(self): logger.info(f"Creating {service.metadata.name} service...") client.create(service) - def _on_remove(self, event): + def _on_remove(self, event: RemoveEvent): """Remove additional magma-orc8r-nginx services.""" client = Client() for service in self._magma_orc8r_nginx_additional_services: @@ -248,23 +249,25 @@ def _magma_orc8r_nginx_additional_services(self) -> List[Service]: @property def _relations_ready(self) -> bool: """Checks whether required relations are ready.""" - required_relations = ["bootstrapper", "certifier", "obsidian"] + required_relations = ["bootstrapper", "magma-orc8r-certifier", "obsidian"] missing_relations = [ relation for relation in required_relations if not self.model.get_relation(relation) - or len(self.model.get_relation(relation).units) == 0 # noqa: W503 + or len(self.model.get_relation(relation).units) == 0 # type: ignore[union-attr] # noqa: E501, W503 ] if missing_relations: msg = f"Waiting for relations: {', '.join(missing_relations)}" self.unit.status = BlockedStatus(msg) return False if not self._get_domain_name: - self.unit.status = WaitingStatus("Waiting for certifier relation to be ready...") + self.unit.status = WaitingStatus( + "Waiting for magma-orc8r-certifier relation to be ready..." + ) return False return True - def _orc8r_nginx_service_created(self, service_name) -> bool: + def _orc8r_nginx_service_created(self, service_name: str) -> bool: """Checks whether given K8s service exists or not.""" client = Client() try: @@ -286,10 +289,10 @@ def _orc8r_certs_mounted(self) -> bool: @property def _get_domain_name(self): """Gets domain name for the data bucket sent by certifier relation.""" - certifier_relation = self.model.get_relation("certifier") - units = certifier_relation.units + certifier_relation = self.model.get_relation("magma-orc8r-certifier") + units = certifier_relation.units # type: ignore[union-attr] try: - return certifier_relation.data[next(iter(units))]["domain"] + return certifier_relation.data[next(iter(units))]["domain"] # type: ignore[union-attr] except KeyError: return None diff --git a/orchestrator-bundle/orc8r-nginx-operator/tests/unit/test_charm.py b/orchestrator-bundle/orc8r-nginx-operator/tests/unit/test_charm.py index df8c0d1f..50faa6f5 100644 --- a/orchestrator-bundle/orc8r-nginx-operator/tests/unit/test_charm.py +++ b/orchestrator-bundle/orc8r-nginx-operator/tests/unit/test_charm.py @@ -29,14 +29,14 @@ def test_given_charm_when_pebble_ready_event_emitted_and_no_relations_establishe self.harness.charm.on.magma_orc8r_nginx_pebble_ready.emit(event) self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for relations: bootstrapper, certifier, obsidian"), + BlockedStatus("Waiting for relations: bootstrapper, magma-orc8r-certifier, obsidian"), ) def test_given_charm_when_pebble_ready_event_emitted_and_certifier_relation_is_established_but_bootstrapper_and_obsidian_relations_are_missing_then_charm_goes_to_blocked_state( # noqa: E501 self, ): event = Mock() - relation_id = self.harness.add_relation("certifier", "magma-orc8r-certifier") + relation_id = self.harness.add_relation("magma-orc8r-certifier", "magma-orc8r-certifier") self.harness.add_relation_unit(relation_id, "magma-orc8r-certifier/0") self.harness.charm.on.magma_orc8r_nginx_pebble_ready.emit(event) self.assertEqual( @@ -53,7 +53,7 @@ def test_given_charm_when_pebble_ready_event_emitted_and_bootstrapper_relation_i self.harness.charm.on.magma_orc8r_nginx_pebble_ready.emit(event) self.assertEqual( self.harness.charm.unit.status, - BlockedStatus("Waiting for relations: certifier, obsidian"), + BlockedStatus("Waiting for relations: magma-orc8r-certifier, obsidian"), ) def test_given_charm_when_pebble_ready_event_emitted_and_all_relations_established_then_create_additional_orc8r_nginx_services_is_called( # noqa: E501 @@ -66,7 +66,9 @@ def test_given_charm_when_pebble_ready_event_emitted_and_all_relations_establish ) as mock: relation_id = self.harness.add_relation("bootstrapper", "magma-orc8r-bootstrapper") self.harness.add_relation_unit(relation_id, "magma-orc8r-bootstrapper/0") - relation_id = self.harness.add_relation("certifier", "magma-orc8r-certifier") + relation_id = self.harness.add_relation( + "magma-orc8r-certifier", "magma-orc8r-certifier" + ) self.harness.add_relation_unit(relation_id, "magma-orc8r-certifier/0") relation_id = self.harness.add_relation("obsidian", "magma-orc8r-obsidian") self.harness.add_relation_unit(relation_id, "magma-orc8r-obsidian/0") @@ -87,7 +89,9 @@ def test_given_charm_when_pebble_ready_event_emitted_and_all_relations_establish with patch.object(MagmaOrc8rNginxCharm, "_configure_pebble_layer", event) as mock: relation_id = self.harness.add_relation("bootstrapper", "magma-orc8r-bootstrapper") self.harness.add_relation_unit(relation_id, "magma-orc8r-bootstrapper/0") - relation_id = self.harness.add_relation("certifier", "magma-orc8r-certifier") + relation_id = self.harness.add_relation( + "magma-orc8r-certifier", "magma-orc8r-certifier" + ) self.harness.add_relation_unit(relation_id, "magma-orc8r-certifier/0") relation_id = self.harness.add_relation("obsidian", "magma-orc8r-obsidian") self.harness.add_relation_unit(relation_id, "magma-orc8r-obsidian/0") diff --git a/orchestrator-bundle/orc8r-orchestrator-operator/metadata.yaml b/orchestrator-bundle/orc8r-orchestrator-operator/metadata.yaml index cd7aa11b..6449efbf 100644 --- a/orchestrator-bundle/orc8r-orchestrator-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-orchestrator-operator/metadata.yaml @@ -23,9 +23,17 @@ resources: description: OCI image for magma-orc8r-orchestrator (docker.artifactory.magmacore.org/controller:1.6.0) upstream-source: docker.artifactory.magmacore.org/controller:1.6.0 +provides: + magma-orc8r-orchestrator: + interface: magma-orc8r-orchestrator + requires: - certifier: + magma-orc8r-certifier: interface: magma-orc8r-certifier + limit: 1 + metrics-endpoint: + interface: prometheus_scrape + limit: 1 storage: config: diff --git a/orchestrator-bundle/orc8r-orchestrator-operator/src/charm.py b/orchestrator-bundle/orc8r-orchestrator-operator/src/charm.py index f3ca514a..e1629e01 100755 --- a/orchestrator-bundle/orc8r-orchestrator-operator/src/charm.py +++ b/orchestrator-bundle/orc8r-orchestrator-operator/src/charm.py @@ -10,9 +10,23 @@ from lightkube import Client from lightkube.models.core_v1 import SecretVolumeSource, Volume, VolumeMount from lightkube.resources.apps_v1 import StatefulSet -from ops.charm import CharmBase +from ops.charm import ( + ActionEvent, + CharmBase, + ConfigChangedEvent, + InstallEvent, + PebbleReadyEvent, + RelationChangedEvent, + RelationEvent, +) from ops.main import main -from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus +from ops.model import ( + ActiveStatus, + BlockedStatus, + MaintenanceStatus, + ModelError, + Relation, +) from ops.pebble import APIError, ConnectionError, ExecError, Layer logger = logging.getLogger(__name__) @@ -40,7 +54,12 @@ def __init__(self, *args): self._on_magma_orc8r_orchestrator_pebble_ready, ) self.framework.observe( - self.on.certifier_relation_changed, self._on_certifier_relation_changed + self.on.magma_orc8r_orchestrator_relation_joined, + self._on_magma_orc8r_orchestrator_relation_joined, + ) + self.framework.observe( + self.on.magma_orc8r_certifier_relation_changed, + self._on_magma_orc8r_certifier_relation_changed, ) self.framework.observe( self.on.create_orchestrator_admin_user_action, @@ -73,7 +92,7 @@ def __init__(self, *args): }, ) - def _on_install(self, event): + def _on_install(self, event: InstallEvent): if not self._container.can_connect(): event.defer() return @@ -122,7 +141,7 @@ def _write_elastic_config(self): ) self._container.push(f"{self.BASE_CONFIG_PATH}/elastic.yml", elastic_config) - def _on_elasticsearch_url_config_changed(self, event): + def _on_elasticsearch_url_config_changed(self, event: ConfigChangedEvent): # TODO: Elasticsearch url should be passed through a relationship (not a config) if not self._container.can_connect(): event.defer() @@ -140,7 +159,7 @@ def _on_elasticsearch_url_config_changed(self, event): "Config for elasticsearch is not valid. Format should be :" ) - def _create_orchestrator_admin_user_action(self, event): + def _create_orchestrator_admin_user_action(self, event: ActionEvent): process = self._container.exec( [ "/var/opt/magma/bin/accessc", @@ -162,7 +181,7 @@ def _create_orchestrator_admin_user_action(self, event): for line in e.stderr.splitlines(): logger.error(" %s", line) - def _set_log_verbosity_action(self, event): + def _set_log_verbosity_action(self, event: ActionEvent): process = self._container.exec( [ "/var/opt/magma/bin/service303_cli", @@ -182,7 +201,7 @@ def _set_log_verbosity_action(self, event): for line in e.stderr.splitlines(): logger.error(" %s", line) - def _on_magma_orc8r_orchestrator_pebble_ready(self, event): + def _on_magma_orc8r_orchestrator_pebble_ready(self, event: PebbleReadyEvent): if not self._relations_ready: event.defer() return @@ -191,12 +210,9 @@ def _on_magma_orc8r_orchestrator_pebble_ready(self, event): @property def _relations_ready(self) -> bool: """Checks whether required relations are ready.""" - required_relations = ["certifier"] + required_relations = ["magma-orc8r-certifier", "metrics-endpoint"] missing_relations = [ - relation - for relation in required_relations - if not self.model.get_relation(relation) - or len(self.model.get_relation(relation).units) == 0 # noqa: W503 + relation for relation in required_relations if not self._relation_active(relation) ] if missing_relations: msg = f"Waiting for relations: {', '.join(missing_relations)}" @@ -204,7 +220,15 @@ def _relations_ready(self) -> bool: return False return True - def _on_certifier_relation_changed(self, event): + def _relation_active(self, relation: str) -> bool: + try: + rel = self.model.get_relation(relation) + units = rel.units # type: ignore[union-attr] + return bool(rel.data[next(iter(units))]["active"]) # type: ignore[union-attr] + except (KeyError, StopIteration): + return False + + def _on_magma_orc8r_certifier_relation_changed(self, event: RelationChangedEvent): """Mounts certificates required by orc8r-orchestrator.""" if not self._nms_certs_mounted: self.unit.status = MaintenanceStatus("Mounting NMS certificates...") @@ -255,7 +279,7 @@ def _magma_orc8r_orchestrator_volumes(self) -> List[Volume]: ), ] - def _configure_orc8r(self, event): + def _configure_orc8r(self, event: PebbleReadyEvent): """Adds layer to pebble config if the proposed config is different from the current one.""" try: plan = self._container.get_plan() @@ -300,7 +324,7 @@ def _pebble_layer(self) -> Layer: def _get_elasticsearch_config(self) -> tuple: elasticsearch_url = self.model.config.get("elasticsearch-url") - elasticsearch_url_split = elasticsearch_url.split(":") + elasticsearch_url_split = elasticsearch_url.split(":") # type: ignore[union-attr] return elasticsearch_url_split[0], elasticsearch_url_split[1] @property @@ -313,6 +337,33 @@ def _elasticsearch_config_is_valid(self) -> bool: else: return False + def _on_magma_orc8r_orchestrator_relation_joined(self, event: RelationEvent): + if not self.unit.is_leader(): + return + self._update_relation_active_status( + relation=event.relation, is_active=self._service_is_running + ) + if not self._service_is_running: + event.defer() + return + + def _update_relation_active_status(self, relation: Relation, is_active: bool): + relation.data[self.unit].update( + { + "active": str(is_active), + } + ) + + @property + def _service_is_running(self) -> bool: + if self._container.can_connect(): + try: + self._container.get_service(self._service_name) + return True + except ModelError: + pass + return False + @property def _namespace(self) -> str: return self.model.name diff --git a/orchestrator-bundle/orc8r-orchestrator-operator/tests/unit/test_charm.py b/orchestrator-bundle/orc8r-orchestrator-operator/tests/unit/test_charm.py index 0f84d4af..ce59021b 100644 --- a/orchestrator-bundle/orc8r-orchestrator-operator/tests/unit/test_charm.py +++ b/orchestrator-bundle/orc8r-orchestrator-operator/tests/unit/test_charm.py @@ -2,11 +2,10 @@ # See LICENSE file for licensing details. import unittest -from unittest.mock import PropertyMock, patch +from unittest.mock import Mock, PropertyMock, patch from ops import testing -from ops.model import BlockedStatus -from ops.pebble import APIError +from ops.model import ActiveStatus, BlockedStatus from charm import MagmaOrc8rOrchestratorCharm @@ -54,6 +53,7 @@ def test_given_ready_when_get_plan_then_plan_is_filled_with_magma_nms_magmalte_s self.assertEqual(expected_plan, updated_plan) @patch("ops.model.Container.push") + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_pebble_ready_when_on_install_event_then_orchestrator_config_file_is_created( # noqa: E501 self, patch_push ): @@ -69,6 +69,7 @@ def test_given_pebble_ready_when_on_install_event_then_orchestrator_config_file_ ) @patch("ops.model.Container.push") + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_new_charm_when_on_install_event_then_metricsd_config_file_is_created( self, patch_push ): @@ -85,6 +86,7 @@ def test_given_new_charm_when_on_install_event_then_metricsd_config_file_is_crea ) @patch("ops.model.Container.push") + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_new_charm_when_on_install_event_then_analytics_config_file_is_created( self, patch_push ): @@ -101,6 +103,7 @@ def test_given_new_charm_when_on_install_event_then_analytics_config_file_is_cre '"metricsPrefix": ""\n', ) + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_default_elasticsearch_config_when_on_config_changed_event_then_status_is_blocked( # noqa: E501 self, ): @@ -112,17 +115,12 @@ def test_given_default_elasticsearch_config_when_on_config_changed_event_then_st "Config for elasticsearch is not valid. Format should be :" ) - @patch("ops.model.Container.restart") @patch("ops.model.Container.push") + @patch("ops.model.Container.restart", Mock()) + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_good_elasticsearch_config_when_on_config_changed_event_then_elasticsearch_config_file_is_created( # noqa: E501 - self, patch_push, patch_restart + self, patch_push ): - patch_restart.side_effect = APIError( - body={"bla": "blo"}, - code=400, - status="whatever status", - message="whatever message", - ) hostname = "blablabla" port = 80 config = {"elasticsearch-url": f"{hostname}:{port}"} @@ -134,8 +132,10 @@ def test_given_good_elasticsearch_config_when_on_config_changed_event_then_elast "/var/opt/magma/configs/orc8r/elastic.yml", f'"elasticHost": "{hostname}"\n' f'"elasticPort": {port}\n', ) + assert self.harness.charm.unit.status == ActiveStatus() @patch("ops.model.Container.push") + @patch("charm.MagmaOrc8rOrchestratorCharm._relations_ready", PropertyMock(return_value=True)) def test_given_bad_elasticsearch_config_when_on_config_changed_event_then_status_is_blocked( self, _ ): diff --git a/orchestrator-bundle/orc8r-policydb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-policydb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-policydb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-policydb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-policydb-operator/metadata.yaml b/orchestrator-bundle/orc8r-policydb-operator/metadata.yaml index bae420ef..bd8440ff 100644 --- a/orchestrator-bundle/orc8r-policydb-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-policydb-operator/metadata.yaml @@ -21,3 +21,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-smsd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-smsd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-smsd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-smsd-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-smsd-operator/metadata.yaml b/orchestrator-bundle/orc8r-smsd-operator/metadata.yaml index ce984622..2fd3f194 100644 --- a/orchestrator-bundle/orc8r-smsd-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-smsd-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-state-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-state-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-state-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-state-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-state-operator/metadata.yaml b/orchestrator-bundle/orc8r-state-operator/metadata.yaml index aa2d8417..bfa626ce 100644 --- a/orchestrator-bundle/orc8r-state-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-state-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-subscriberdb-cache-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-subscriberdb-cache-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-subscriberdb-cache-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-subscriberdb-cache-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-subscriberdb-cache-operator/metadata.yaml b/orchestrator-bundle/orc8r-subscriberdb-cache-operator/metadata.yaml index 801c78fb..09d2800c 100644 --- a/orchestrator-bundle/orc8r-subscriberdb-cache-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-subscriberdb-cache-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-subscriberdb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-subscriberdb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-subscriberdb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-subscriberdb-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-subscriberdb-operator/metadata.yaml b/orchestrator-bundle/orc8r-subscriberdb-operator/metadata.yaml index 47343988..f9222323 100644 --- a/orchestrator-bundle/orc8r-subscriberdb-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-subscriberdb-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1 diff --git a/orchestrator-bundle/orc8r-tenants-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py b/orchestrator-bundle/orc8r-tenants-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py index 78d3e088..d53af4d2 100644 --- a/orchestrator-bundle/orc8r-tenants-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py +++ b/orchestrator-bundle/orc8r-tenants-operator/lib/charms/magma_orc8r_libs/v0/orc8r_base_db.py @@ -178,7 +178,7 @@ def _get_db_connection_string(self): """Returns DB connection string provided by the DB relation.""" try: db_relation = self.model.get_relation("db") - return ConnectionString(db_relation.data[db_relation.app]["master"]) + return ConnectionString(db_relation.data[db_relation.app]["master"]) # type: ignore[index, union-attr] # noqa: E501 except (AttributeError, KeyError): return None diff --git a/orchestrator-bundle/orc8r-tenants-operator/metadata.yaml b/orchestrator-bundle/orc8r-tenants-operator/metadata.yaml index f9da1cd7..8ca04e2f 100644 --- a/orchestrator-bundle/orc8r-tenants-operator/metadata.yaml +++ b/orchestrator-bundle/orc8r-tenants-operator/metadata.yaml @@ -20,3 +20,4 @@ resources: requires: db: interface: pgsql + limit: 1