Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use Ops.CollectStatus Event #53

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 100 additions & 58 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@
from lightkube.models.core_v1 import ServicePort, ServiceSpec
from lightkube.models.meta_v1 import ObjectMeta
from lightkube.resources.core_v1 import Service
from ops.charm import CharmBase, EventBase, InstallEvent, RelationJoinedEvent, RemoveEvent
from ops import (
ActiveStatus,
BlockedStatus,
CollectStatusEvent,
MaintenanceStatus,
ModelError,
StatusBase,
WaitingStatus,
)
from ops.charm import (
CharmBase,
EventBase,
InstallEvent,
RelationBrokenEvent,
RelationJoinedEvent,
RemoveEvent,
)
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, ModelError, WaitingStatus
from ops.pebble import Layer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,14 +80,6 @@ class AMFOperatorCharm(CharmBase):

def __init__(self, *args):
super().__init__(*args)
if not self.unit.is_leader():
# NOTE: In cases where leader status is lost before the charm is
# finished processing all teardown events, this prevents teardown
# event code from running. Luckily, for this charm, none of the
# teardown code is necessary to preform if we're removing the
# charm.
self.unit.status = BlockedStatus("Scaling is not implemented for this charm")
return
self._amf_container_name = self._amf_service_name = "amf"
self._amf_container = self.unit.get_container(self._amf_container_name)
self._nrf_requires = NRFRequires(charm=self, relation_name="fiveg-nrf")
Expand All @@ -97,6 +104,12 @@ def __init__(self, *args):
self._database = DatabaseRequires(
self, relation_name="database", database_name=DATABASE_NAME
)
# Setting attributes to detect broken relations until
# https://github.com/canonical/operator/issues/940 is fixed
self._database_relation_breaking = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in no rush to use collect status and I feel like I'd rather wait for the ops fix instead of forcing this change now and reverting some of it when the fix is available. This is quite a large change already right before we want to promote to beta and going ahead with it makes me slightly nervous. I'd at least wait until we have our charms in beta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I will freeze the PR's till the ops issue is fixed. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @benhoyt,

According to Juju documentation https://juju.is/docs/sdk/constructs#heading--framework,
The attributes such as self._database_relation_breaking should be set to their default values upon every hook execution. However, I tested it and those states are kept somehow.
I both modified the integration test and tested manually by adding additional config-changed hook to see the effect.
After relation broken, running a config-changed hook did not reset the init attribute state which conflicts with the documentation. If the documentation was correct, the integration tests should fail in this PR but they are not failing (?).
Please enlighten us.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gatici I am not experiencing this behaviour. I just brutally added some logs in this revision.
What I did:

  1. Deploy all required charms and properly relate everything.
  2. Remove relation between amf and mongodb-k8s (database).
  3. Run juju config amf external-amf-ip=1.1.1.1
unit-amf-0: 16:33:35 CRITICAL unit.amf/0.juju-log database:5: self._database_relation_breaking: False (class init)
unit-amf-0: 16:33:35 CRITICAL unit.amf/0.juju-log database:5: self._database_relation_breaking: True (event: <RelationBrokenEvent via AMFOperatorCharm/on/database_relation_broken[105]>)
unit-amf-0: 16:33:35 INFO juju.worker.uniter.operation ran "database-relation-broken" hook (via hook dispatching script: dispatch)
unit-amf-0: 16:33:52 CRITICAL unit.amf/0.juju-log self._database_relation_breaking: False (class init)
unit-amf-0: 16:33:52 INFO juju.worker.uniter.operation ran "config-changed" hook (via hook dispatching script: dispatch)

First line prints the default value of _database_relation_breaking on class init when the relation broken event is triggered.
Second line is right after we update the attribute in the same hook.
In the third line you see the hook completes.
In the fourth line the class is instatiated again (for the config-changed hook) and the attribute is reset to its default value.
In the fifth line you see the hook completes.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gatici First, there's a discrepancy here between Harness tests (with the same Harness instance) and reality. The charm instance isn't reinitialized between hook executions when the Harness triggers events.

This also applies to deferred, which may be what you're seeing here? Normally the charm is a completely new instance (with attributes reset by __init__) every hook execution, but if an event was deferred, the deferred events are run first against the charm instance, and then the "main" event also executed on that same charm instance (without resetting attributes).

These discrepancies are a problem that we hope to address that this cycle. See canonical/operator#736

So I wonder if the difference @dariofaccin is seeing is because there were no deferred events in that case (for whatever reason).

CC: @tonyandrewmeyer for visibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benhoyt Many thanks for your help and quick response!

self._nrf_relation_breaking = False
self._tls_relation_breaking = False
self.framework.observe(self.on.collect_unit_status, self._on_collect_unit_status)
self.framework.observe(self.on.install, self._on_install)
self.framework.observe(self.on.remove, self._on_remove)
self.framework.observe(self.on.config_changed, self._configure_amf)
Expand Down Expand Up @@ -124,6 +137,73 @@ def __init__(self, *args):
self._certificates.on.certificate_expiring, self._on_certificate_expiring
)

def _is_unit_in_non_active_status(self) -> Optional[StatusBase]: # noqa: C901
"""Evaluate and return the unit's current status, or None if it should be active.

Returns:
StatusBase: MaintenanceStatus/BlockedStatus/WaitingStatus
None: If none of the conditionals match

"""
if not self.unit.is_leader():
# NOTE: In cases where leader status is lost before the charm is
# finished processing all teardown events, this prevents teardown
# event code from running. Luckily, for this charm, none of the
# teardown code is necessary to preform if we're removing the
# charm.
return BlockedStatus("Scaling is not implemented for this charm")

if not self._amf_container.can_connect():
gatici marked this conversation as resolved.
Show resolved Hide resolved
return MaintenanceStatus("Waiting for service to start")

if invalid_configs := self._get_invalid_configs():
return BlockedStatus(f"The following configurations are not valid: {invalid_configs}")

if not self.model.get_relation("fiveg-nrf") or self._nrf_relation_breaking:
return BlockedStatus("Waiting for fiveg-nrf relation")

if not self.model.get_relation("database") or self._database_relation_breaking:
return BlockedStatus("Waiting for database relation")
Comment on lines +165 to +166
Copy link
Contributor

@dariofaccin dariofaccin Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that self.model.get_relation("database") returns False if a relation has not been completely removed by a previous hook?
I am thinking about this case:

  1. amf and mongodb-k8s are properly related
  2. invoke remove-integration and for some reason the hook fails only on mongo side and the relation becomes stale (now amf should be in BlockedStatus)
  3. invoke any other hook

At the moment the modification in integration tests works because the relation is properly removed and get_relation returns False as expected.

Copy link
Contributor Author

@gatici gatici Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact self.model.get_relation("database") is generally returning True because of a known issue (https://bugs.launchpad.net/juju/+bug/1979811). Although the integration is removed, it still appears in the model. As self._database_relation_breaking returns True, then unit status is set to Blocked.
I also deployed the charm including this patch and tested it manually.

$ juju status --relations
Model                  Controller          Cloud/Region        Version  SLA          Timestamp
test-integration-twnt  microk8s-localhost  microk8s/localhost  3.1.6    unsupported  21:49:59+03:00

App                       Version  Status  Scale  Charm                     Channel  Rev  Address         Exposed  Message
mongodb-k8s                        active      1  mongodb-k8s               5/edge    36  10.152.183.198  no       Primary
sdcore-amf                         active      1  sdcore-amf                           0  10.152.183.22   no       
sdcore-nrf                         active      1  sdcore-nrf                edge      58  10.152.183.58   no       
self-signed-certificates           active      1  self-signed-certificates  beta      33  10.152.183.202  no       

Unit                         Workload  Agent  Address      Ports  Message
mongodb-k8s/0*               active    idle   10.1.146.19         Primary
sdcore-amf/0*                active    idle   10.1.146.7          
sdcore-nrf/0*                active    idle   10.1.146.51         
self-signed-certificates/0*  active    idle   10.1.146.15         

Integration provider                   Requirer                    Interface         Type     Message
mongodb-k8s:database                   sdcore-amf:database         mongodb_client    regular  
mongodb-k8s:database                   sdcore-nrf:database         mongodb_client    regular  
mongodb-k8s:database-peers             mongodb-k8s:database-peers  mongodb-peers     peer     
sdcore-nrf:fiveg-nrf                   sdcore-amf:fiveg-nrf        fiveg_nrf         regular  
self-signed-certificates:certificates  sdcore-amf:certificates     tls-certificates  regular  
self-signed-certificates:certificates  sdcore-nrf:certificates     tls-certificates  regular  

$ juju remove-relation mongodb-k8s:database  sdcore-amf:database 
$ juju status --relations
Model                  Controller          Cloud/Region        Version  SLA          Timestamp
test-integration-twnt  microk8s-localhost  microk8s/localhost  3.1.6    unsupported  21:50:38+03:00

App                       Version  Status   Scale  Charm                     Channel  Rev  Address         Exposed  Message
mongodb-k8s                        active       1  mongodb-k8s               5/edge    36  10.152.183.198  no       Primary
sdcore-amf                         waiting      1  sdcore-amf                           0  10.152.183.22   no       installing agent
sdcore-nrf                         active       1  sdcore-nrf                edge      58  10.152.183.58   no       
self-signed-certificates           active       1  self-signed-certificates  beta      33  10.152.183.202  no       

Unit                         Workload  Agent  Address      Ports  Message
mongodb-k8s/0*               active    idle   10.1.146.19         Primary
sdcore-amf/0*                blocked   idle   10.1.146.7          Waiting for database relation
sdcore-nrf/0*                active    idle   10.1.146.51         
self-signed-certificates/0*  active    idle   10.1.146.15         

Integration provider                   Requirer                    Interface         Type     Message
mongodb-k8s:database                   sdcore-nrf:database         mongodb_client    regular  
mongodb-k8s:database-peers             mongodb-k8s:database-peers  mongodb-peers     peer     
sdcore-nrf:fiveg-nrf                   sdcore-amf:fiveg-nrf        fiveg_nrf         regular  
self-signed-certificates:certificates  sdcore-amf:certificates     tls-certificates  regular  
self-signed-certificates:certificates  sdcore-nrf:certificates     tls-certificates  regular 

Juju debug-log:

core-amf-0: 21:49:50 INFO unit.sdcore-amf/0.juju-log HTTP Request: PATCH https://10.152.183.1/api/v1/namespaces/test-integration-twnt/services/sdcore-amf "HTTP/1.1 200 OK"
unit-sdcore-amf-0: 21:49:50 INFO unit.sdcore-amf/0.juju-log Kubernetes service 'sdcore-amf' patched successfully
unit-sdcore-amf-0: 21:49:51 INFO juju.worker.uniter.operation ran "update-status" hook (via hook dispatching script: dispatch)
unit-mongodb-k8s-0: 21:50:36 INFO juju.worker.uniter.operation ran "database-relation-departed" hook (via hook dispatching script: dispatch)
unit-sdcore-amf-0: 21:50:37 INFO juju.worker.uniter.operation ran "database-relation-departed" hook (via hook dispatching script: dispatch)
unit-mongodb-k8s-0: 21:50:37 INFO unit.mongodb-k8s/0.juju-log database:4: Remove relation user: relation-4
unit-mongodb-k8s-0: 21:50:37 INFO unit.mongodb-k8s/0.juju-log database:4: Update relation user: relation-1 on free5gc
unit-mongodb-k8s-0: 21:50:37 INFO unit.mongodb-k8s/0.juju-log database:4: Updating relation data according to diff
unit-sdcore-amf-0: 21:50:37 INFO juju.worker.uniter.operation ran "database-relation-broken" hook (via hook dispatching script: dispatch)
unit-mongodb-k8s-0: 21:50:37 INFO juju.worker.uniter.operation ran "database-relation-broken" hook (via hook dispatching script: dispatch)


if not self.model.get_relation("certificates") or self._tls_relation_breaking:
return BlockedStatus("Waiting for certificates relation")

if not self._database_is_available():
return WaitingStatus("Waiting for the amf database to be available")

if not self._get_database_info():
return WaitingStatus("Waiting for AMF database info to be available")

if not self._nrf_requires.nrf_url:
return WaitingStatus("Waiting for NRF data to be available")

if not self._amf_container.exists(path=CONFIG_DIR_PATH):
return WaitingStatus("Waiting for storage to be attached")

if not _get_pod_ip():
return WaitingStatus("Waiting for pod IP address to be available")

if not self._certificate_is_stored():
return WaitingStatus("Waiting for certificates to be stored")

try:
self._set_n2_information()
except ValueError:
return BlockedStatus("Waiting for MetalLB to be enabled")

return None

def _on_collect_unit_status(self, event: CollectStatusEvent):
"""Check the unit status and set to Unit when CollectStatusEvent is fired.

Args:
event: CollectStatusEvent
"""
if status := self._is_unit_in_non_active_status():
event.add_status(status)
else:
event.add_status(ActiveStatus())

def _on_install(self, event: InstallEvent) -> None:
client = Client()
client.apply(
Expand Down Expand Up @@ -176,51 +256,13 @@ def _configure_amf(self, event: EventBase) -> None: # noqa C901
Args:
event (PebbleReadyEvent, DatabaseCreatedEvent, NRFAvailableEvent): Juju event
"""
if not self._amf_container.can_connect():
self.unit.status = MaintenanceStatus("Waiting for service to start")
event.defer()
return
if invalid_configs := self._get_invalid_configs():
self.unit.status = BlockedStatus(
f"The following configurations are not valid: {invalid_configs}"
)
return
for relation in ["fiveg-nrf", "database", "certificates"]:
if not self._relation_created(relation):
self.unit.status = BlockedStatus(f"Waiting for {relation} relation")
return
if not self._database_is_available():
self.unit.status = WaitingStatus("Waiting for the amf database to be available")
event.defer()
return
if not self._get_database_info():
self.unit.status = WaitingStatus("Waiting for AMF database info to be available")
event.defer()
return
if not self._nrf_requires.nrf_url:
self.unit.status = WaitingStatus("Waiting for NRF data to be available")
event.defer()
return
if not self._amf_container.exists(path=CONFIG_DIR_PATH):
self.unit.status = WaitingStatus("Waiting for storage to be attached")
event.defer()
return
if not _get_pod_ip():
self.unit.status = WaitingStatus("Waiting for pod IP address to be available")
event.defer()
return
if not self._certificate_is_stored():
self.unit.status = WaitingStatus("Waiting for certificates to be stored")
if self._is_unit_in_non_active_status():
# Unit Status is in Maintanence or Blocked or Waiting status
event.defer()
return

self._generate_config_file()
self._configure_amf_workload()
try:
self._set_n2_information()
except ValueError:
self.unit.status = BlockedStatus("Waiting for MetalLB to be enabled")
return
self.unit.status = ActiveStatus()

def _on_certificates_relation_created(self, event: EventBase) -> None:
"""Generates Private key."""
Expand All @@ -229,15 +271,15 @@ def _on_certificates_relation_created(self, event: EventBase) -> None:
return
self._generate_private_key()

def _on_certificates_relation_broken(self, event: EventBase) -> None:
def _on_certificates_relation_broken(self, event: RelationBrokenEvent) -> None:
"""Deletes TLS related artifacts and reconfigures AMF."""
if not self._amf_container.can_connect():
event.defer()
return
self._delete_private_key()
self._delete_csr()
self._delete_certificate()
self.unit.status = BlockedStatus("Waiting for certificates relation")
self._tls_relation_breaking = True

def _on_certificates_relation_joined(self, event: EventBase) -> None:
"""Generates CSR and requests new certificate."""
Expand Down Expand Up @@ -276,21 +318,21 @@ def _on_certificate_expiring(self, event: CertificateExpiringEvent):
return
self._request_new_certificate()

def _on_nrf_broken(self, event: EventBase) -> None:
def _on_nrf_broken(self, event: RelationBrokenEvent) -> None:
"""Event handler for NRF relation broken.

Args:
event (NRFBrokenEvent): Juju event
"""
self.unit.status = BlockedStatus("Waiting for fiveg-nrf relation")
self._nrf_relation_breaking = True

def _on_database_relation_broken(self, event: EventBase) -> None:
def _on_database_relation_broken(self, event: RelationBrokenEvent) -> None:
"""Event handler for database relation broken.

Args:
event: Juju event
"""
self.unit.status = BlockedStatus("Waiting for database relation")
self._database_relation_breaking = True

def _generate_private_key(self) -> None:
"""Generates and stores private key."""
Expand Down Expand Up @@ -402,7 +444,7 @@ def _on_n2_relation_joined(self, event: RelationJoinedEvent) -> None:
try:
self._set_n2_information()
except ValueError:
self.unit.status = BlockedStatus("Waiting for MetalLB to be enabled")
logger.info("Waiting for MetalLB to be enabled")
return

def _get_n2_amf_ip(self) -> Optional[str]:
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async def test_relate_and_wait_for_active_status(ops_test: OpsTest, build_and_de
async def test_remove_nrf_and_wait_for_blocked_status(ops_test: OpsTest, build_and_deploy):
assert ops_test.model
await ops_test.model.remove_application(NRF_CHARM_NAME, block_until_done=True)
# Running config-changed hook with empty config to check whether _nrf_relation_breaking
# attribute will not be set to its default value
await ops_test.model.applications[APP_NAME].set_config({})
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60)


Expand All @@ -106,6 +109,9 @@ async def test_restore_nrf_and_wait_for_active_status(ops_test: OpsTest, build_a
async def test_remove_tls_and_wait_for_blocked_status(ops_test: OpsTest, build_and_deploy):
assert ops_test.model
await ops_test.model.remove_application(TLS_PROVIDER_CHARM_NAME, block_until_done=True)
# Running config-changed hook with empty config to check whether _tls_relation_breaking
# attribute will not be set to its default value
await ops_test.model.applications[APP_NAME].set_config({})
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60)


Expand All @@ -129,6 +135,9 @@ async def test_restore_tls_and_wait_for_active_status(ops_test: OpsTest, build_a
async def test_remove_database_and_wait_for_blocked_status(ops_test: OpsTest, build_and_deploy):
assert ops_test.model
await ops_test.model.remove_application(DB_CHARM_NAME, block_until_done=True)
# Running config-changed hook with empty config to check whether _database_relation_breaking
# attribute will not be set to its default value
await ops_test.model.applications[APP_NAME].set_config({})
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60)


Expand Down
21 changes: 16 additions & 5 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_given_fiveg_nrf_relation_not_created_when_pebble_ready_then_status_is_b
self.harness.set_can_connect(container="amf", val=True)
self.harness.add_relation(relation_name="database", remote_app="mongodb")
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
BlockedStatus("Waiting for fiveg-nrf relation"),
Expand All @@ -73,6 +74,7 @@ def test_given_database_relation_not_created_when_pebble_ready_then_status_is_bl
self.harness.set_can_connect(container="amf", val=True)
self.harness.add_relation(relation_name="fiveg-nrf", remote_app="mongodb")
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
BlockedStatus("Waiting for database relation"),
Expand All @@ -85,6 +87,7 @@ def test_given_certificates_relation_not_created_when_pebble_ready_then_status_i
self.harness.add_relation(relation_name="fiveg-nrf", remote_app="mongodb")
self.harness.add_relation(relation_name="database", remote_app="mongodb")
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
BlockedStatus("Waiting for certificates relation"),
Expand All @@ -108,7 +111,7 @@ def test_given_amf_charm_in_active_state_when_nrf_relation_breaks_then_status_is
self.harness.container_pebble_ready("amf")

self.harness.remove_relation(nrf_relation_id)

self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
BlockedStatus("Waiting for fiveg-nrf relation"),
Expand Down Expand Up @@ -136,7 +139,7 @@ def test_given_amf_charm_in_active_state_when_database_relation_breaks_then_stat
self.harness.container_pebble_ready("amf")

self.harness.remove_relation(database_relation_id)

self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
BlockedStatus("Waiting for database relation"),
Expand All @@ -156,6 +159,7 @@ def test_given_relations_created_and_database_not_available_when_pebble_ready_th
relation_name="certificates", remote_app="tls-certificates-operator"
)
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for the amf database to be available"),
Expand All @@ -177,6 +181,7 @@ def test_given_database_info_not_available_when_pebble_ready_then_status_is_wait
relation_name="certificates", remote_app="tls-certificates-operator"
)
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for AMF database info to be available"),
Expand All @@ -200,6 +205,7 @@ def test_given_nrf_data_not_available_when_pebble_ready_then_status_is_waiting(
)
self._create_database_relation_and_populate_data()
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for NRF data to be available"),
Expand All @@ -223,6 +229,7 @@ def test_given_storage_not_attached_when_pebble_ready_then_status_is_waiting(
)
self._create_database_relation_and_populate_data()
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for storage to be attached"),
Expand Down Expand Up @@ -253,6 +260,7 @@ def test_given_certificates_not_stored_when_pebble_ready_then_status_is_waiting(
)
self._create_database_relation_and_populate_data()
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for certificates to be stored"),
Expand Down Expand Up @@ -445,6 +453,7 @@ def test_relations_available_and_config_pushed_and_pebble_updated_when_pebble_re
)
self._create_database_relation_and_populate_data()
self.harness.container_pebble_ready("amf")
self.harness.evaluate_status()
self.assertEqual(
self.harness.model.unit.status,
ActiveStatus(),
Expand All @@ -468,7 +477,7 @@ def test_given_empty_ip_address_when_pebble_ready_then_status_is_waiting(
self._create_database_relation_and_populate_data()

self.harness.container_pebble_ready(container_name="amf")

self.harness.evaluate_status()
self.assertEqual(
self.harness.charm.unit.status,
WaitingStatus("Waiting for pod IP address to be available"),
Expand Down Expand Up @@ -661,6 +670,7 @@ def test_given_n2_information_and_service_is_running_and_metallb_service_is_not_
self.harness.container_pebble_ready("amf")
relation_id = self.harness.add_relation(relation_name="fiveg-n2", remote_app="n2-requirer")
self.harness.add_relation_unit(relation_id=relation_id, remote_unit_name="n2-requirer/0")
self.harness.evaluate_status()
self.assertEqual(
self.harness.charm.unit.status, BlockedStatus("Waiting for MetalLB to be enabled")
)
Expand Down Expand Up @@ -827,11 +837,12 @@ def test_given_certificates_are_stored_when_on_certificates_relation_broken_then
patch_check_output.return_value = b"1.1.1.1"
self.harness.set_can_connect(container="amf", val=True)
self.harness.add_relation(relation_name="fiveg-nrf", remote_app="mongodb")
self.harness.add_relation(
certificate_relation_id = self.harness.add_relation(
relation_name="certificates", remote_app="tls-certificates-operator"
)
self._create_database_relation_and_populate_data()
self.harness.charm._on_certificates_relation_broken(event=Mock())
self.harness.remove_relation(certificate_relation_id)
self.harness.evaluate_status()
self.assertEqual(
self.harness.charm.unit.status, BlockedStatus("Waiting for certificates relation")
)
Expand Down
Loading