From ba92aeb946343c045e8363a2aae78e0a17a6cb82 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 17 Mar 2023 22:17:05 +0000 Subject: [PATCH] Fix failover when the last listener is deleted This patch fixes an issue when deleting the last listener from a load balancer may trigger a failover. Story: 2010652 Task: 47683 Change-Id: I02804b7075edac72776b0377b7b283d0c7bfd8a2 --- .../amphorae/backends/health_daemon/health_daemon.py | 12 +++++++++--- .../backends/health_daemon/test_health_daemon.py | 8 ++++++++ ...ner-delete-causing-failover-251efdb79af24c0a.yaml | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/Fix-listener-delete-causing-failover-251efdb79af24c0a.yaml diff --git a/octavia/amphorae/backends/health_daemon/health_daemon.py b/octavia/amphorae/backends/health_daemon/health_daemon.py index ec1ed470cc..f4247682af 100644 --- a/octavia/amphorae/backends/health_daemon/health_daemon.py +++ b/octavia/amphorae/backends/health_daemon/health_daemon.py @@ -157,9 +157,15 @@ def run_sender(cmd_queue): def get_stats(stat_sock_file): - stats_query = haproxy_query.HAProxyQuery(stat_sock_file) - stats = stats_query.show_stat() - pool_status = stats_query.get_pool_status() + try: + stats_query = haproxy_query.HAProxyQuery(stat_sock_file) + stats = stats_query.show_stat() + pool_status = stats_query.get_pool_status() + except Exception as e: + LOG.warning('Unable to query the HAProxy stats (%s) due to: %s', + stat_sock_file, str(e)) + # Return empty lists so that the heartbeat will still be sent + return [], {} return stats, pool_status diff --git a/octavia/tests/unit/amphorae/backends/health_daemon/test_health_daemon.py b/octavia/tests/unit/amphorae/backends/health_daemon/test_health_daemon.py index 6ad8ae0a14..5b81d7716b 100644 --- a/octavia/tests/unit/amphorae/backends/health_daemon/test_health_daemon.py +++ b/octavia/tests/unit/amphorae/backends/health_daemon/test_health_daemon.py @@ -319,6 +319,14 @@ class TestHealthDaemon(base.TestCase): stats_query_mock.show_stat.assert_called_once_with() stats_query_mock.get_pool_status.assert_called_once_with() + @mock.patch('octavia.amphorae.backends.utils.haproxy_query.HAProxyQuery') + def test_get_stats_exception(self, mock_query): + mock_query.side_effect = Exception('Boom') + + stats, pool_status = health_daemon.get_stats('TEST') + self.assertEqual([], stats) + self.assertEqual({}, pool_status) + @mock.patch('octavia.amphorae.backends.agent.api_server.' 'util.is_lb_running') @mock.patch('octavia.amphorae.backends.health_daemon.' diff --git a/releasenotes/notes/Fix-listener-delete-causing-failover-251efdb79af24c0a.yaml b/releasenotes/notes/Fix-listener-delete-causing-failover-251efdb79af24c0a.yaml new file mode 100644 index 0000000000..60c99fae8f --- /dev/null +++ b/releasenotes/notes/Fix-listener-delete-causing-failover-251efdb79af24c0a.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed an issue when deleting the last listener from a load balancer may + trigger a failover.