From 5997304d878d63adf495b470993674f0e0fbcc9a Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Tue, 21 Dec 2021 18:02:15 +0100 Subject: [PATCH] Fix compile_amphora_details when using UDP listeners When requesting the amphora details of a LB that has a UDP listener, it fails with an exception: AttributeError: 'KeepalivedLvs' object has no attribute 'is_listener_running' There's a typo in the _count_lvs_listener_processes function which calls an inexisting method. Change-Id: Id81ac8dfdd969c7b250d231123d392eff4a86269 (cherry picked from commit 655fdf8c1b5786c3aa24c926dd95537a51a7c0cc) (cherry picked from commit c44c831649f970d3259bad95d2d2213f9b8167f6) --- .../backends/agent/api_server/amphora_info.py | 2 +- .../backends/agent/api_server/test_amphora_info.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/octavia/amphorae/backends/agent/api_server/amphora_info.py b/octavia/amphorae/backends/agent/api_server/amphora_info.py index 0ea37ad272..c1100f2060 100644 --- a/octavia/amphorae/backends/agent/api_server/amphora_info.py +++ b/octavia/amphorae/backends/agent/api_server/amphora_info.py @@ -112,7 +112,7 @@ class AmphoraInfo(object): def _count_lvs_listener_processes(self, lvs_driver, listener_list): num = 0 for listener_id in listener_list: - if lvs_driver.is_listener_running(listener_id): + if util.is_lvs_listener_running(listener_id): # optional check if it's still running num += 1 return num 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 1655febd27..66eb6d23dc 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 @@ -182,6 +182,8 @@ class TestAmphoraInfo(base.TestCase): self.assertEqual(expected_dict, actual.json) api_server.VERSION = original_version + @mock.patch('octavia.amphorae.backends.agent.api_server.util.' + 'is_lvs_listener_running') @mock.patch('octavia.amphorae.backends.agent.api_server.util.' 'get_lvs_listeners', return_value=[FAKE_LISTENER_ID_3, FAKE_LISTENER_ID_4]) @@ -205,7 +207,8 @@ class TestAmphoraInfo(base.TestCase): m_pkg_version, m_load, m_get_nets, m_os, m_cpu, mget_mem, - mock_get_lb, mget_lvs_listener): + mock_get_lb, mget_lvs_listener, + mock_is_lvs_listener_running): mget_mem.return_value = {'SwapCached': 0, 'Buffers': 344792, 'MemTotal': 21692784, 'Cached': 4271856, 'Slab': 534384, 'MemFree': 12685624, @@ -227,7 +230,7 @@ class TestAmphoraInfo(base.TestCase): m_count.return_value = 5 self.lvs_driver.get_subscribed_amp_compile_info.return_value = [ 'keepalived', 'ipvsadm'] - self.lvs_driver.is_listener_running.side_effect = [True, False] + mock_is_lvs_listener_running.side_effect = [True, False] mock_get_lb.return_value = [self.LB_ID_1] original_version = api_server.VERSION api_server.VERSION = self.API_VERSION @@ -282,8 +285,10 @@ class TestAmphoraInfo(base.TestCase): [uuidutils.generate_uuid(), uuidutils.generate_uuid()]) self.assertEqual(1, result) - def test__count_lvs_listener_processes(self): - self.lvs_driver.is_listener_running.side_effect = [True, False, True] + @mock.patch('octavia.amphorae.backends.agent.api_server.util.' + 'is_lvs_listener_running') + def test__count_lvs_listener_processes(self, mock_is_lvs_listener_running): + mock_is_lvs_listener_running.side_effect = [True, False, True] expected = 2 actual = self.amp_info._count_lvs_listener_processes( self.lvs_driver, [self.FAKE_LISTENER_ID_1,