From 4ccc5970da34d6e50704affd71306b8991b05aa0 Mon Sep 17 00:00:00 2001 From: Luis Tomas Bolivar Date: Tue, 22 Nov 2022 12:33:14 +0100 Subject: [PATCH] Ensure HM updates work as expected This patch ensures if only one parameter is provided the rest are not modified (set to undefined) Closes-Bug: #1997416 Change-Id: Ie47f19afdd041843fe47da739b09ee03a88c7b02 --- ovn_octavia_provider/helper.py | 14 +++++++++----- ovn_octavia_provider/tests/unit/test_helper.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ovn_octavia_provider/helper.py b/ovn_octavia_provider/helper.py index adbbfc35..a25f709f 100644 --- a/ovn_octavia_provider/helper.py +++ b/ovn_octavia_provider/helper.py @@ -2472,11 +2472,15 @@ class OvnProviderHelper(): LOG.debug("Could not find LB with pool id %s", pool_id) return status - options = { - 'interval': str(info['interval']), - 'timeout': str(info['timeout']), - 'success_count': str(info['success_count']), - 'failure_count': str(info['failure_count'])} + options = {} + if info['interval']: + options['interval'] = str(info['interval']) + if info['timeout']: + options['timeout'] = str(info['timeout']) + if info['success_count']: + options['success_count'] = str(info['success_count']) + if info['failure_count']: + options['failure_count'] = str(info['failure_count']) commands = [] commands.append( diff --git a/ovn_octavia_provider/tests/unit/test_helper.py b/ovn_octavia_provider/tests/unit/test_helper.py index 8ee5efae..6afab779 100644 --- a/ovn_octavia_provider/tests/unit/test_helper.py +++ b/ovn_octavia_provider/tests/unit/test_helper.py @@ -3675,6 +3675,21 @@ class TestOvnProviderHelper(ovn_base.TestOvnOctaviaBase): self.assertEqual(status['healthmonitors'][0]['operating_status'], constants.ERROR) + @mock.patch.object(ovn_helper.OvnProviderHelper, '_find_ovn_lb_from_hm_id') + def test_hm_update_just_interval(self, folbfhi): + folbfhi.return_value = (self.ovn_hm, self.ovn_hm_lb) + self.health_monitor['interval'] = 3 + self.helper.hm_update(self.health_monitor) + options = { + 'interval': str(self.health_monitor['interval']), + 'timeout': str(self.health_monitor['timeout']), + 'success_count': str(self.health_monitor['success_count']), + 'failure_count': str(self.health_monitor['failure_count'])} + self.helper.ovn_nbdb_api.db_set.assert_called_once_with( + 'Load_Balancer_Health_Check', + self.ovn_hm.uuid, + ('options', options)) + def test_hm_delete(self): self.helper.ovn_nbdb_api.db_list_rows.return_value.\ execute.return_value = [self.ovn_hm]