From e5204f924646f3098ca4c91e38a8b08a333437ab Mon Sep 17 00:00:00 2001 From: Harry Pidcock Date: Fri, 22 Nov 2024 09:12:44 +1000 Subject: [PATCH] test: fix blocked status and blocked status tests --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 37 +++++++++++++++++++++++++++++++++++++ src/charm.py | 2 +- tests/test_charm.py | 3 ++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4583957 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1731797254, + "narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7d72a07 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "juju controller charm shell"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + }; + + outputs = { self, nixpkgs, ... } @ inputs: + let + forAllSystems = inputs.nixpkgs.lib.genAttrs [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + ]; + in + { + devShells = forAllSystems (system: { + default = + let + pkgs = nixpkgs.legacyPackages.${system}; + in + pkgs.mkShell { + name = "juju-controller-charm"; + # Enable experimental features without having to specify the argument + NIX_CONFIG = "experimental-features = nix-command flakes"; + nativeBuildInputs = with pkgs; [ + coreutils + findutils + zsh + python312 + ]; + shellHook = '' + exec zsh + ''; + }; + }); + }; +} \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index f04a999..d0ccffb 100755 --- a/src/charm.py +++ b/src/charm.py @@ -131,7 +131,7 @@ def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent): except AgentConfException as e: logger.error('cannot read controller API port from agent configuration: %s', e) self.unit.status = BlockedStatus( - f"can't read controller API port from agent.conf: {e}") + f"cannot read controller API port from agent configuration: {e}") return metrics_endpoint = MetricsEndpointProvider( diff --git a/tests/test_charm.py b/tests/test_charm.py index 003d6a3..d61566f 100644 --- a/tests/test_charm.py +++ b/tests/test_charm.py @@ -140,7 +140,8 @@ def test_apiaddresses_missing_status(self, *_): harness.add_relation('metrics-endpoint', 'prometheus-k8s') harness.evaluate_status() self.assertEqual(harness.charm.unit.status, BlockedStatus( - "can't read controller API port from agent.conf: agent.conf key 'apiaddresses' missing" + "cannot read controller API port from agent configuration: " + "agent.conf key 'apiaddresses' missing" )) @patch("builtins.open", new_callable=mock_open, read_data=agent_conf_ipv4)