Skip to content

Commit

Permalink
Pedro's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Dec 2, 2023
1 parent a22a820 commit cbcde7e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/charms/opensearch/v0/opensearch_cos.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _on_cos_agent_relation_created(self, event: RelationCreatedEvent):

def _on_cos_agent_relation_broken(self, event: RelationBrokenEvent):
"""Re-run plugin configuration is the cos relation is not present anymore."""
# The only reliable way to pass the information to Plugin Manager
# that the relation is not there anymore
self._charm.plugin_manager.set_event_scope(event)
if self._charm.model.get_relation("cos-agent"):
event.defer()
return
self._run_plugin_manager(event)
12 changes: 2 additions & 10 deletions lib/charms/opensearch/v0/opensearch_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
OpenSearchPrometheusExporter,
PluginState,
)
from ops import RelationBrokenEvent

# The unique Charmhub library identifier, never change it
LIBID = "da838485175f47dbbbb83d76c07cab4c"
Expand Down Expand Up @@ -84,10 +83,6 @@ def plugins(self) -> List[OpenSearchPlugin]:
plugins_list.append(new_plugin)
return plugins_list

def set_event_scope(self, event):
"""Optional: define an event scope for the execution."""
self._event = event

def _extra_conf(self, plugin_data: Dict[str, Any]) -> Optional[Dict[str, Any]]:
"""Returns the config from the relation data of the target plugin if applies."""
relation_name = plugin_data.get("relation")
Expand Down Expand Up @@ -255,11 +250,8 @@ def _is_plugin_relation_set(self, relation_name: str) -> bool:
"""Returns True if a relation is expected and it is set."""
if not relation_name:
return False
# relation = self._charm.model.get_relation(relation_name)
cos_relation = self._charm.meta.relations.get(relation_name)
return cos_relation is not None and (
not self._event or not isinstance(self._event, RelationBrokenEvent)
)
relation = self._charm.model.get_relation(relation_name)
return relation is not None

def _remove_if_needed(self, plugin: OpenSearchPlugin) -> bool:
"""If disabled, removes plugin configuration or sets it to other values."""
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/helpers_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,9 @@ async def wait_until( # noqa: C901
"""
if not apps:
raise ValueError("apps must be specified.")

if not (apps_statuses or apps_full_statuses or units_statuses or units_full_statuses):
apps_statuses = ["active"]
units_statuses = ["active"]

if isinstance(wait_for_exact_units, int):
wait_for_exact_units = {app: wait_for_exact_units for app in apps}
elif not wait_for_exact_units:
Expand All @@ -321,15 +319,13 @@ async def wait_until( # noqa: C901
for app in apps:
if app not in wait_for_exact_units:
wait_for_exact_units[app] = 1

try:
logger.info("\n\n\n")
logger.info(
subprocess.check_output(
f"juju status --model {ops_test.model.info.name}", shell=True
).decode("utf-8")
)

for attempt in Retrying(stop=stop_after_delay(timeout), wait=wait_fixed(10)):
with attempt:
logger.info(f"\n\n\n{now()} -- Waiting for model...")
Expand All @@ -345,7 +341,6 @@ async def wait_until( # noqa: C901
):
logger.info(f"{now()} -- Waiting for model: complete.\n\n\n")
return

raise Exception
except RetryError:
logger.error("wait_until -- Timed out!\n\n\n")
Expand Down
13 changes: 12 additions & 1 deletion tests/integration/plugins/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
return

my_charm = await ops_test.build_charm(".")
await ops_test.model.set_config(MODEL_CONFIG)

model_conf = MODEL_CONFIG.copy()
# Make it more regular as COS relation-broken really happens on the
# next hook call in each opensearch unit.
# If this value is changed, then update the sleep accordingly at:
# test_prometheus_exporter_disabled_by_cos_relation_gone
model_conf["update-status-hook-interval"] = "1m"
await ops_test.model.set_config(model_conf)

# Deploy TLS Certificates operator.
config = {"generate-self-signed-certificates": "true", "ca-common-name": "CN_CA"}
Expand Down Expand Up @@ -98,6 +105,10 @@ async def test_prometheus_exporter_enabled_by_cos_relation(ops_test):

async def test_prometheus_exporter_disabled_by_cos_relation_gone(ops_test):
await ops_test.juju("remove-relation", APP_NAME, COS_APP_NAME)

# Wait 90s as the update-status is supposed to happen every 1m
# If model config is updated, update this routine as well.
await asyncio.sleep(150)
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
Expand Down

0 comments on commit cbcde7e

Please sign in to comment.