Skip to content

Commit

Permalink
Set BlockedStatus if @ is not used when running `juju config AM con…
Browse files Browse the repository at this point in the history
…fig_file=@FILE_NAME` (#284)

* set app in BlockedStatus if @ is not used while running juju config

* pin ruff

* update charm_tracing.py lib

* unping ruff

* add example on how to use `config_file` config option
  • Loading branch information
Abuelodelanada authored Aug 22, 2024
1 parent 618fefe commit 4fdf682
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ options:
default: ""
description: >
Alertmanager configuration file (yaml), with the exclusion of the templates section.
Refer to https://www.prometheus.io/docs/alerting/latest/configuration/ for full details.
To send the contents of a file to this configuration option, the symbol `@` must be used.
Usage: `juju config alertmanager [email protected]`
For more information on configuring the Alertmanager, refer to:
https://www.prometheus.io/docs/alerting/latest/configuration/
templates_file:
type: string
default: ""
Expand Down
9 changes: 9 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ def _get_local_config(self) -> Optional[Tuple[Optional[dict], Optional[str]]]:
config = self.config["config_file"]
if config:
local_config = yaml.safe_load(cast(str, config))

# If `juju config` is executed like this `config_file=am.yaml` instead of
# `[email protected]` local_config will be the string `am.yaml` instead
# of its content (dict).
if not isinstance(local_config, dict):
msg = f"Unable to set config from file. Use juju config {self.unit.name} config_file=@FILENAME"
logger.error(msg)
raise ConfigUpdateFailure(msg)

local_templates = cast(str, self.config["templates_file"]) or None
return local_config, local_templates
return None
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/am_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
route:
receiver: test_receiver
group_by:
- alertname
group_wait: 1234s
group_interval: 4321s
repeat_interval: 1111h
receivers:
- name: test_receiver
21 changes: 21 additions & 0 deletions tests/integration/test_remote_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import helpers
import pytest
import sh
import yaml
from deepdiff import DeepDiff # type: ignore[import]
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -105,6 +106,26 @@ async def test_remote_configuration_applied_on_relation_created(ops_test: OpsTes
)


@pytest.mark.abort_on_fail
async def test_remote_configuration_file_wrongly_applied(ops_test: OpsTest, setup):
sh.juju(
[
"config",
f"{APP_NAME}",
"-m",
ops_test.model_name,
"config_file=tests/integration/am_config.yaml",
]
)

await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="blocked",
timeout=1000,
idle_period=5,
)


def _copy_alertmanager_remote_configuration_library_into_tester_charm():
"""Ensure that the tester charm uses the current Alertmanager Remote Configuration library."""
library_path = "lib/charms/alertmanager_k8s/v0/alertmanager_remote_configuration.py"
Expand Down

0 comments on commit 4fdf682

Please sign in to comment.