diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcc32fb..5337b23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,9 +34,9 @@ jobs: build: name: Build charms needs: unit-tests - uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23 with: - artifact-name: charm-packed + charmcraft-snap-channel: 3.x/stable channel: @@ -93,7 +93,7 @@ jobs: env: CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} run: | - sudo snap install charmcraft --classic + sudo snap install charmcraft --channel 3.x/stable --classic charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ --name $CHARM_NAME \ --release ${{ needs.channel.outputs.test }} @@ -188,7 +188,7 @@ jobs: steps: - name: Install Charmcraft run: | - sudo snap install charmcraft --classic + sudo snap install charmcraft --channel 3.x/stable --classic - name: Get uploaded revision id: revision diff --git a/charmcraft.yaml b/charmcraft.yaml index a1b57db..8f15b7a 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -2,33 +2,11 @@ type: charm parts: charm: charm-python-packages: [setuptools,markdown] -bases: - - build-on: - - name: ubuntu - channel: "24.04" - architectures: ["amd64"] - run-on: - - name: ubuntu - channel: "24.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el - - riscv64 - - name: ubuntu - channel: "22.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el - - riscv64 - - name: ubuntu - channel: "20.04" - architectures: - - amd64 - - arm64 - - s390x - - ppc64el - - riscv64 + build-packages: + - cargo +base: ubuntu@24.04 +platforms: + amd64: + arm64: + s390x: + ppc64el: 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 5ad3923..d0ccffb 100755 --- a/src/charm.py +++ b/src/charm.py @@ -130,6 +130,8 @@ def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent): api_port = self.api_port() except AgentConfException as e: logger.error('cannot read controller API port from agent configuration: %s', e) + self.unit.status = BlockedStatus( + 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 d39f263..d61566f 100644 --- a/tests/test_charm.py +++ b/tests/test_charm.py @@ -9,7 +9,7 @@ import yaml from charm import JujuControllerCharm, AgentConfException -from ops.model import BlockedStatus, ActiveStatus +from ops import BlockedStatus, ActiveStatus from ops.testing import Harness from unittest.mock import mock_open, patch @@ -139,7 +139,10 @@ def test_apiaddresses_missing_status(self, *_): harness.add_relation('metrics-endpoint', 'prometheus-k8s') harness.evaluate_status() - self.assertIsInstance(harness.charm.unit.status, BlockedStatus) + self.assertEqual(harness.charm.unit.status, BlockedStatus( + "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) def test_apiaddresses_ipv4(self, _):