From b293762ab6a9553edfeff07cfc59c2b37404de13 Mon Sep 17 00:00:00 2001 From: Maximilian Stinsky Date: Tue, 21 Dec 2021 09:38:21 +0100 Subject: [PATCH] fix haproxy_count to display the number of running processes At the moment haproxy_count always returns 0 because the _count_haproxy_processes function checks for listener id's instead of haproxy loadbalancer id's Change-Id: I1d1a9a4f193f3766df12ae43b2c2e54c4adf405f (cherry picked from commit 33a3d4744c5945f1f99615d85ce26fc63257e09c) (cherry picked from commit 24024fb26614415f1028285e6797e14ffc993889) (cherry picked from commit 09fb252910f98c4a68813e78c1f1f38db4a0c391) --- octavia/amphorae/backends/agent/api_server/amphora_info.py | 3 ++- .../backends/agent/api_server/test_amphora_info.py | 7 ++++++- .../notes/fix-amphora-haproxy-count-b1b1df43a7150926.yaml | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/fix-amphora-haproxy-count-b1b1df43a7150926.yaml diff --git a/octavia/amphorae/backends/agent/api_server/amphora_info.py b/octavia/amphorae/backends/agent/api_server/amphora_info.py index d8f5a50556..d7e08444ad 100644 --- a/octavia/amphorae/backends/agent/api_server/amphora_info.py +++ b/octavia/amphorae/backends/agent/api_server/amphora_info.py @@ -45,6 +45,7 @@ class AmphoraInfo(object): return webob.Response(json=body) def compile_amphora_details(self, extend_lvs_driver=None): + haproxy_loadbalancer_list = sorted(util.get_loadbalancers()) haproxy_listener_list = sorted(util.get_listeners()) extend_body = {} lvs_listener_list = [] @@ -67,7 +68,7 @@ class AmphoraInfo(object): 'networks': self._get_networks(), 'active': True, 'haproxy_count': - self._count_haproxy_processes(haproxy_listener_list), + self._count_haproxy_processes(haproxy_loadbalancer_list), 'cpu': { 'total': cpu['total'], 'user': cpu['user'], diff --git a/octavia/tests/unit/amphorae/backends/agent/api_server/test_amphora_info.py b/octavia/tests/unit/amphorae/backends/agent/api_server/test_amphora_info.py index 66eb6d23dc..6985f4087f 100644 --- a/octavia/tests/unit/amphorae/backends/agent/api_server/test_amphora_info.py +++ b/octavia/tests/unit/amphorae/backends/agent/api_server/test_amphora_info.py @@ -38,6 +38,7 @@ class TestAmphoraInfo(base.TestCase): FAKE_LISTENER_ID_3 = uuidutils.generate_uuid() FAKE_LISTENER_ID_4 = uuidutils.generate_uuid() LB_ID_1 = uuidutils.generate_uuid() + LB_ID_2 = uuidutils.generate_uuid() def setUp(self): super().setUp() @@ -112,6 +113,8 @@ class TestAmphoraInfo(base.TestCase): @mock.patch('octavia.amphorae.backends.agent.api_server.util.' 'get_listeners', return_value=[FAKE_LISTENER_ID_1, FAKE_LISTENER_ID_2]) + @mock.patch('octavia.amphorae.backends.agent.api_server.util.' + 'get_loadbalancers', return_value=[LB_ID_1, LB_ID_2]) @mock.patch('octavia.amphorae.backends.agent.api_server.' 'amphora_info.AmphoraInfo._get_meminfo') @mock.patch('octavia.amphorae.backends.agent.api_server.' @@ -128,7 +131,8 @@ class TestAmphoraInfo(base.TestCase): @mock.patch('socket.gethostname', return_value='FAKE_HOST') def test_compile_amphora_details(self, mhostname, m_count, m_pkg_version, m_load, m_get_nets, m_os, m_cpu, - mget_mem, mget_listener): + mget_mem, mget_loadbalancers, + mget_listeners): mget_mem.return_value = {'SwapCached': 0, 'Buffers': 344792, 'MemTotal': 21692784, 'Cached': 4271856, 'Slab': 534384, 'MemFree': 12685624, @@ -180,6 +184,7 @@ class TestAmphoraInfo(base.TestCase): u'topology_status': u'OK'} actual = self.amp_info.compile_amphora_details() self.assertEqual(expected_dict, actual.json) + m_count.assert_called_once_with(sorted(mget_loadbalancers())) api_server.VERSION = original_version @mock.patch('octavia.amphorae.backends.agent.api_server.util.' diff --git a/releasenotes/notes/fix-amphora-haproxy-count-b1b1df43a7150926.yaml b/releasenotes/notes/fix-amphora-haproxy-count-b1b1df43a7150926.yaml new file mode 100644 index 0000000000..568bdac818 --- /dev/null +++ b/releasenotes/notes/fix-amphora-haproxy-count-b1b1df43a7150926.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix amphora haproxy_count to return the number of + haproxy processes that are running.