diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7a9e557..253daad 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,7 +18,7 @@ jobs: with: provider: microk8s channel: 1.26-strict/stable - juju-channel: 3.1/stable + juju-channel: 3/stable microk8s-addons: hostpath-storage dns rbac metallb:10.64.140.40-10.64.140.49 - name: Install snaps run: | diff --git a/actions.yaml b/actions.yaml deleted file mode 100644 index 3afb20f..0000000 --- a/actions.yaml +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright 2021 David Ames -# See LICENSE file for licensing details. - -get-operator-info: - description: | - Get information on the operator user for rabbitmq management. - -get-service-account: - description: | - Generate credentials and access for an external service. - params: - username: - type: string - description: The username for the service account. - vhost: - type: string - description: The RabbitMQ virtual host to use for the account. - required: - - username - - vhost - additionalProperties: False - -ensure-queue-ha: - description: | - Check for queues that have insufficent members for high - availability and, if possible, add members to them. - params: - dry-run: - type: boolean - default: false - description: | - Report on what memberships would change if the command was - run and warn about any queues that cannot be fixed. - -rebalance-quorum: - description: | - Rebalance queue leaders to that they are evenly balanced - across the cluster. - -add-member: - description: Add member to queue - params: - queue-name: - type: string - description: | - Name of queue to add the member to. - unit-name: - type: string - description: | - Juju unit name of the node to be added to the queue - vhost: - type: string - description: | - vhost that the queue resides in. - required: [queue-name, unit-name] - -delete-member: - description: Remove member from queue - params: - queue-name: - type: string - description: | - Name of queue to remove the member from. - unit-name: - type: string - description: | - Juju unit name of the node to be removed from the queue - vhost: - type: string - description: | - vhost that the queue resides in. - required: [queue-name, unit-name] - -grow: - description: | - Adds a new replica on the given node for all or a half - of matching quorum queues. - params: - selector: - type: string - description: | - Valid values are "all" or even" - unit-name: - type: string - description: | - Juju unit name of the node to have queues added - vhost-pattern: - type: string - description: | - Match vhosts to be added to the node - queue-pattern: - type: string - description: | - Match queues to be added to the node - required: [unit-name, selector] - -shrink: - description: | - Shrinks quorum queue clusters by removing any members (replicas) - on the given node. - params: - unit-name: - type: string - description: | - Juju unit name of the node to have queues added - error-only: - type: boolean - default: false - description: | - Only list queues which reported an error - required: [unit-name] - diff --git a/charmcraft.yaml b/charmcraft.yaml index e517a7f..e9cbfdc 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -1,11 +1,170 @@ -type: "charm" -bases: - - build-on: - - name: "ubuntu" - channel: "22.04" - run-on: - - name: "ubuntu" - channel: "22.04" +type: charm +name: rabbitmq-k8s +summary: RabbitMQ charmed operator for Kubernetes +description: RabbitMQ +links: + documentation: https://discourse.charmhub.io/t/thedac-rabbitmq-operator-docs-index/4630 + +base: ubuntu@24.04 +platforms: + amd64: + +config: + options: + minimum-replicas: + default: 3 + description: + Minimum number of queues replicas, set to 0 to disable charm automatically + managing queue replicas + type: int + auto-ha-frequency: + default: 30 + description: Frequency in minutes to check for queues that need HA members added + type: int + +actions: + get-operator-info: + description: | + Get information on the operator user for rabbitmq management. + get-service-account: + description: | + Generate credentials and access for an external service. + params: + username: + type: string + description: The username for the service account. + vhost: + type: string + description: The RabbitMQ virtual host to use for the account. + required: + - username + - vhost + additionalProperties: false + ensure-queue-ha: + description: | + Check for queues that have insufficent members for high + availability and, if possible, add members to them. + params: + dry-run: + type: boolean + default: false + description: | + Report on what memberships would change if the command was + run and warn about any queues that cannot be fixed. + rebalance-quorum: + description: | + Rebalance queue leaders to that they are evenly balanced + across the cluster. + add-member: + description: Add member to queue + params: + queue-name: + type: string + description: | + Name of queue to add the member to. + unit-name: + type: string + description: | + Juju unit name of the node to be added to the queue + vhost: + type: string + description: | + vhost that the queue resides in. + required: + - queue-name + - unit-name + delete-member: + description: Remove member from queue + params: + queue-name: + type: string + description: | + Name of queue to remove the member from. + unit-name: + type: string + description: | + Juju unit name of the node to be removed from the queue + vhost: + type: string + description: | + vhost that the queue resides in. + required: + - queue-name + - unit-name + grow: + description: | + Adds a new replica on the given node for all or a half + of matching quorum queues. + params: + selector: + type: string + description: | + Valid values are "all" or even" + unit-name: + type: string + description: | + Juju unit name of the node to have queues added + vhost-pattern: + type: string + description: | + Match vhosts to be added to the node + queue-pattern: + type: string + description: | + Match queues to be added to the node + required: + - unit-name + - selector + shrink: + description: | + Shrinks quorum queue clusters by removing any members (replicas) + on the given node. + params: + unit-name: + type: string + description: | + Juju unit name of the node to have queues added + error-only: + type: boolean + default: false + description: | + Only list queues which reported an error + required: + - unit-name + +containers: + rabbitmq: + resource: rabbitmq-image + mounts: + - storage: rabbitmq-data + location: /var/lib/rabbitmq + +resources: + rabbitmq-image: + type: oci-image + description: OCI image for rabbitmq + upstream-source: ghcr.io/canonical/rabbitmq:3.12.1 + +storage: + rabbitmq-data: + type: filesystem + +requires: + ingress: + interface: ingress + limit: 1 + logging: + interface: loki_push_api + optional: true + +provides: + amqp: + interface: rabbitmq + +peers: + peers: + interface: rabbitmq-peer + parts: update-certificates: plugin: nil @@ -13,9 +172,9 @@ parts: apt update apt install -y ca-certificates update-ca-certificates - charm: - after: [update-certificates] + after: + - update-certificates build-packages: - git - libffi-dev diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 9e68681..0000000 --- a/config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2021 David Ames -# See LICENSE file for licensing details. - -options: - minimum-replicas: - default: 3 - description: Minimum number of queues replicas, set to 0 to disable charm automatically managing queue replicas - type: int - auto-ha-frequency: - default: 30 - description: Frequency in minutes to check for queues that need HA members added - type: int diff --git a/metadata.yaml b/metadata.yaml deleted file mode 100644 index 21539ff..0000000 --- a/metadata.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2021 Canonical Ltd. -# See LICENSE file for licensing details. -name: rabbitmq-k8s -description: RabbitMQ -summary: RabbitMQ charmed operator for Kubernetes - -docs: https://discourse.charmhub.io/t/thedac-rabbitmq-operator-docs-index/4630 - -containers: - rabbitmq: - resource: rabbitmq-image - mounts: - - storage: rabbitmq-data - location: /var/lib/rabbitmq - -resources: - rabbitmq-image: - type: oci-image - description: OCI image for rabbitmq - upstream-source: ghcr.io/canonical/rabbitmq:3.12.1 - -storage: - rabbitmq-data: - type: filesystem - -provides: - amqp: - interface: rabbitmq - -requires: - ingress: - interface: ingress - limit: 1 - logging: - interface: loki_push_api - optional: true - -peers: - peers: - interface: rabbitmq-peer diff --git a/rename.sh b/rename.sh new file mode 100755 index 0000000..ea84bc0 --- /dev/null +++ b/rename.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [[ -f "rabbitmq-k8s.charm" ]]; then + echo "Removing existing rabbitmq-k8s.charm" + rm rabbitmq-k8s.charm +fi + +for f in rabbitmq-k8s*.charm; do + echo "Renaming $f to rabbitmq-k8s.charm" + mv "$f" "rabbitmq-k8s.charm" + break +done diff --git a/src/charm.py b/src/charm.py index 5316965..bd27d9e 100755 --- a/src/charm.py +++ b/src/charm.py @@ -30,6 +30,7 @@ Union, ) +import ops import pwgen import requests import tenacity @@ -57,9 +58,6 @@ EventBase, StoredState, ) -from ops.main import ( - main, -) from ops.model import ( ActiveStatus, BlockedStatus, @@ -878,7 +876,7 @@ def _render_and_push_pebble_notifier(self) -> bool: f"""#!/bin/bash while true; do echo "Next event at $(date -d '+{auto_ha_frequency} minutes')" - sleep {auto_ha_frequency*60} + sleep {auto_ha_frequency * 60} echo "Notifying operator of timer event" /charm/bin/pebble notify {TIMER_NOTICE} done @@ -1228,4 +1226,4 @@ def _ensure_queue_ha_action(self, event: ActionEvent) -> None: if __name__ == "__main__": - main(RabbitMQOperatorCharm) + ops.main(RabbitMQOperatorCharm) diff --git a/test-requirements.txt b/test-requirements.txt index 0ca296a..daa5c82 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ coverage flake8 stestr rabbitmq_admin -git+https://github.com/openstack-charmers/zaza.git@libjuju-3.1#egg=zaza -git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack +zaza @ git+https://github.com/openstack-charmers/zaza.git +zaza.openstack @ git+https://github.com/openstack-charmers/zaza-openstack-tests.git ops cosl diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 203a479..e7fc662 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -15,6 +15,7 @@ """Unit tests for RabbitMQ operator.""" +import os import unittest from unittest.mock import ( MagicMock, @@ -37,6 +38,7 @@ class TestCharm(unittest.TestCase): @patch("charm.KubernetesServicePatch", lambda _, service_type, ports: None) def setUp(self, *unused): """Setup test fixtures for unit tests.""" + os.environ["JUJU_VERSION"] = "3.4.4" self.harness = Harness(charm.RabbitMQOperatorCharm) self.addCleanup(self.harness.cleanup) self.harness.begin() diff --git a/tox.ini b/tox.ini index 3a493e9..2bf2092 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,8 @@ all_path = {[vars]src_path} {[vars]tst_path} [testenv] basepython = python3 setenv = + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 PYTHONPATH = {toxinidir}:{[vars]lib_path}:{[vars]src_path} passenv = PYTHONPATH @@ -76,6 +78,10 @@ deps = {[testenv:py3]deps} basepython = python3.10 deps = {[testenv:py3]deps} +[testenv:py312] +basepython = python3.12 +deps = {[testenv:py3]deps} + [testenv:cover] basepython = python3 deps = {[testenv:py3]deps} @@ -99,7 +105,7 @@ commands = {[testenv:lint]commands} description = Check code against coding style standards deps = black - flake8<6 + flake8 flake8-docstrings flake8-copyright flake8-builtins @@ -108,7 +114,7 @@ deps = isort codespell commands = - codespell {[vars]all_path} + codespell {[vars]all_path} # pflake8 wrapper supports config from pyproject.toml pflake8 --exclude {[vars]lib_path} --config {toxinidir}/pyproject.toml {[vars]all_path} isort --check-only --diff {[vars]all_path} --skip-glob {[vars]lib_path} @@ -116,29 +122,43 @@ commands = [testenv:func-noop] basepython = python3 +setenv = + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 commands = functest-run-suite --help [testenv:func] basepython = python3 +setenv = + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 commands = functest-run-suite --keep-model [testenv:func-smoke] basepython = python3 setenv = - TEST_MODEL_SETTINGS = automatically-retry-hooks=true;update-status-hook-interval=1m - TEST_MAX_RESOLVE_COUNT = 5 + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 + TEST_MODEL_SETTINGS = automatically-retry-hooks=true;update-status-hook-interval=1m + TEST_MAX_RESOLVE_COUNT = 5 commands = functest-run-suite --keep-model --smoke [testenv:func-dev] basepython = python3 +setenv = + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 commands = functest-run-suite --keep-model --dev [testenv:func-target] basepython = python3 +setenv = + # Set TEST_JUJU3 To unpin juju<3 in zaza + TEST_JUJU3 = 1 commands = functest-run-suite --keep-model --bundle {posargs}