Skip to content

Commit

Permalink
Merge pull request #12 from gnuoy/fix-queue-list
Browse files Browse the repository at this point in the history
Filter queue lists to quorom queues only
  • Loading branch information
hemanthnakkina authored Sep 21, 2023
2 parents 0de4881 + 83c5d9c commit 94ef982
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def grow_queues_onto_unit(self, unit) -> None:
"""Grow any undersized queues onto unit."""
api = self._get_admin_api()
joining_node = self.generate_nodename(unit)
queue_members = [len(q["members"]) for q in api.list_queues()]
queue_members = [len(q["members"]) for q in api.list_quorum_queues()]
if not queue_members:
logging.debug("No queues found, queue growth skipped")
queue_members.sort()
Expand Down Expand Up @@ -808,7 +808,7 @@ def get_undersized_queues(self) -> List[str]:
api = self._get_admin_api()
undersized_queues = [
q
for q in api.list_queues()
for q in api.list_quorum_queues()
if len(q["members"]) < self.min_replicas()
]
return undersized_queues
Expand Down
12 changes: 11 additions & 1 deletion src/rabbit_extended_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import json
import urllib
from typing import (
Dict,
List,
)

import rabbitmq_admin

Expand All @@ -27,9 +31,15 @@ class ExtendedAdminApi(rabbitmq_admin.AdminAPI):
"""Extend rabbitmq_admin.AdminAPI to cover missing endpoints the charm needs."""

def list_queues(self):
"""A list of nodes in the RabbitMQ cluster."""
"""A list of queues."""
return self._api_get("/api/queues")

def list_quorum_queues(self) -> List[Dict]:
"""A list of quorum queues."""
return [
q for q in self._api_get("/api/queues") if q["type"] == "quorum"
]

def get_queue(self, vhost, queue):
"""A list of nodes in the RabbitMQ cluster."""
return self._api_get(
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,16 @@ def test_grow_queues_onto_unit(self):
"vhost": "openstack",
"members": ["node1", "node2", "node3"],
}
self.mock_admin_api.list_queues.return_value = [queue_one_member]
self.mock_admin_api.list_quorum_queues.return_value = [
queue_one_member
]
self.harness.charm.grow_queues_onto_unit("unit/1")
self.mock_admin_api.grow_queue.assert_called_once_with(
"rabbit@unit-1.rabbitmq-k8s-endpoints", "all"
)

self.mock_admin_api.grow_queue.reset_mock()
self.mock_admin_api.list_queues.return_value = [
self.mock_admin_api.list_quorum_queues.return_value = [
queue_two_member,
queue_three_member,
]
Expand All @@ -259,7 +261,7 @@ def test_grow_queues_onto_unit(self):
)

self.mock_admin_api.grow_queue.reset_mock()
self.mock_admin_api.list_queues.return_value = [
self.mock_admin_api.list_quorum_queues.return_value = [
queue_one_member,
queue_two_member,
queue_three_member,
Expand Down

0 comments on commit 94ef982

Please sign in to comment.