[OVN] Create a HA_Chassis_Group without raising an exception

Closes-Bug: #2104927
Related-Bug: #2100505
Change-Id: Ia51355a7ba7af17fe2cf4109a1fb7e61973dddff
This commit is contained in:
Rodolfo Alonso Hernandez
2025-03-27 04:34:26 +00:00
parent 196b2c9874
commit 9c46b51c3b
3 changed files with 21 additions and 11 deletions

View File

@@ -37,7 +37,6 @@ from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import netutils
from oslo_utils import strutils
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp import constants as ovsdbapp_const
from pecan import util as pecan_util
import tenacity
@@ -1114,11 +1113,10 @@ def _sync_ha_chassis_group(nb_idl, hcg_info, txn):
candidates = _filter_candidates_for_ha_chassis_group(hcg_info)
# Try to get the HA Chassis Group or create if it doesn't exist
ha_ch_grp = ha_ch_grp_cmd = None
try:
ha_ch_grp = nb_idl.ha_chassis_group_get(
hcg_info.group_name).execute(check_error=True)
except idlutils.RowNotFound:
ha_ch_grp_cmd = None
ha_ch_grp = nb_idl.lookup('HA_Chassis_Group', hcg_info.group_name,
default=None)
if ha_ch_grp is None:
ha_ch_grp_cmd = txn.add(nb_idl.ha_chassis_group_add(
hcg_info.group_name, may_exist=True,
external_ids=hcg_info.external_ids))

View File

@@ -2970,7 +2970,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
@mock.patch.object(ml2_plugin.Ml2Plugin, 'get_network', return_value={})
@mock.patch.object(ovn_utils, '_filter_candidates_for_ha_chassis_group')
def test_sync_ha_chassis_group_network(self, mock_candidates, *args):
self.nb_ovn.ha_chassis_group_get.side_effect = idlutils.RowNotFound
self.nb_ovn.lookup.return_value = None
fake_txn = mock.Mock()
hcg_info = self._build_hcg_info(network_id='fake-net-id')
mock_candidates.return_value = {'ch0', 'ch1', 'ch2', 'ch3'}
@@ -3016,8 +3016,8 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
'ha_chassis': [hc0, hc1, hc2, hc3]}
fake_ha_chassis_group = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs=hcg_attrs)
self.nb_ovn.ha_chassis_group_get().execute.return_value = (
fake_ha_chassis_group)
# HA_Chassis_Group lookup.
self.nb_ovn.lookup.return_value = fake_ha_chassis_group
self.sb_ovn.get_gateway_chassis_from_cms_options.return_value = (
hcg_info.chassis_list)

View File

@@ -2187,8 +2187,6 @@ class OVNL3ExtrarouteTests(test_l3_gw.ExtGwModeIntTestCase,
}
self.l3_inst._nb_ovn.ls_get.return_value.execute.return_value = (
mock.Mock(external_ids=ext_ids))
self.l3_inst._nb_ovn.ha_chassis_group_get.return_value.execute.\
return_value = None
# Note(dongj): According to bug #1657693, status of an unassociated
# floating IP is set to DOWN. Revise expected_status to DOWN for related
@@ -2222,6 +2220,8 @@ class OVNL3ExtrarouteTests(test_l3_gw.ExtGwModeIntTestCase,
'neutron-fake_device', [(constants.IPv4_ANY, '120.0.0.1')])
def test_router_update_gateway_upon_subnet_create_max_ips_ipv6(self):
# HA_Chassis_Group lookup.
self.l3_inst._nb_ovn.lookup.return_value = None
super(). \
test_router_update_gateway_upon_subnet_create_max_ips_ipv6()
expected_ext_ids = {
@@ -2240,3 +2240,15 @@ class OVNL3ExtrarouteTests(test_l3_gw.ExtGwModeIntTestCase,
def test_create_floatingip_with_assoc(self, **kwargs):
self.l3_inst._nb_ovn.lookup.return_value = mock.Mock(load_balancer=[])
super().test_create_floatingip_with_assoc(**kwargs)
def test_route_update_with_external_route(self):
# HA_Chassis_Group lookup.
self.l3_inst._nb_ovn.lookup.return_value = None
super().test_route_update_with_external_route()
def _test_router_create_show_ext_gwinfo(self, snat_input_value,
snat_expected_value):
# HA_Chassis_Group lookup.
self.l3_inst._nb_ovn.lookup.return_value = None
super()._test_router_create_show_ext_gwinfo(snat_input_value,
snat_expected_value)