Skip to content

Commit 406665b

Browse files
Fix OVN DB sync when syncing an OVN LB from scratch
When running octavia-ovn-db-sync-tool over a OVN LB that doesn't exist on OVN NB DB the tool is reporting error status to Octavia API on the last step. This patch is fixing the dict reported to Octavia API that was nested by error. Closes-Bug: #2103518 Change-Id: Iac6ce4ed93e2c080050df87f81777bacb6b507c6
1 parent 9bbc7d3 commit 406665b

File tree

2 files changed

+147
-4
lines changed

2 files changed

+147
-4
lines changed

ovn_octavia_provider/driver.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,20 +692,23 @@ def _ensure_loadbalancer(self, loadbalancer):
692692
for listener in loadbalancer.listeners:
693693
status_listener = self._ovn_helper.listener_create(
694694
self._get_listener_request_info(listener))
695-
status[constants.LISTENERS].append(status_listener)
695+
status[constants.LISTENERS].append(
696+
status_listener[constants.LISTENERS][0])
696697
if not isinstance(loadbalancer.pools, o_datamodels.UnsetType):
697698
status[constants.POOLS] = []
698699
for pool in loadbalancer.pools:
699700
status_pool = self._ovn_helper.pool_create(
700701
self._get_pool_request_info(pool))
701-
status[constants.POOLS].append(status_pool)
702+
status[constants.POOLS].append(
703+
status_pool[constants.POOLS][0])
702704
for member in pool.members:
703705
status[constants.MEMBERS] = []
704706
if not member.subnet_id:
705707
member.subnet_id = loadbalancer.vip_subnet_id
706708
status_member = self._ovn_helper.member_create(
707709
self._get_member_request_info(member))
708-
status[constants.MEMBERS].append(status_member)
710+
status[constants.MEMBERS].append(
711+
status_member[constants.MEMBERS][0])
709712
if pool.healthmonitor is not None and not isinstance(
710713
pool.healthmonitor, o_datamodels.UnsetType):
711714
status[constants.HEALTHMONITORS] = []
@@ -717,7 +720,8 @@ def _ensure_loadbalancer(self, loadbalancer):
717720
status_hm = self._ovn_helper.hm_create(
718721
self._get_healthmonitor_request_info(
719722
pool.healthmonitor))
720-
status[constants.HEALTHMONITORS].append(status_hm)
723+
status[constants.HEALTHMONITORS].append(
724+
status_hm[constants.HEALTHMONITORS][0])
721725
self._ovn_helper._update_status_to_octavia(status)
722726
else:
723727
# Load Balancer found, check LB and listener/pool/member/hms

ovn_octavia_provider/tests/unit/test_driver.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,14 @@ def test_ensure_loadbalancer_lb_not_found(
16231623
mock_member_create, mock_update_status):
16241624
self.mock_find_ovn_lbs_with_retry.side_effect = [
16251625
idlutils.RowNotFound]
1626+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1627+
{'id': self.loadbalancer_id}]}
1628+
mock_listener_create.return_value = {constants.LISTENERS: [
1629+
{'id': self.listener_id}]}
1630+
mock_pool_create.return_value = {constants.POOLS: [
1631+
{'id': self.pool_id}]}
1632+
mock_member_create.return_value = {constants.MEMBERS: [
1633+
{'id': self.member_id}]}
16261634
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
16271635
mock_lb_create.assert_called_once_with(
16281636
self.driver._get_loadbalancer_request_info(
@@ -1640,6 +1648,13 @@ def test_ensure_loadbalancer_lb_not_found(
16401648
self.driver._get_member_request_info(
16411649
self.ref_lb_fully_populated.pools[0].members[0]),
16421650
)
1651+
expected_status = {
1652+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1653+
constants.LISTENERS: [{'id': self.listener_id}],
1654+
constants.POOLS: [{'id': self.pool_id}],
1655+
constants.MEMBERS: [{'id': self.member_id}]
1656+
}
1657+
mock_update_status.assert_called_once_with(expected_status)
16431658

16441659
@mock.patch.object(ovn_helper.OvnProviderHelper,
16451660
'_update_status_to_octavia')
@@ -1653,13 +1668,23 @@ def test_ensure_loadbalancer_lb_not_found_without_listeners_or_pools(
16531668
idlutils.RowNotFound]
16541669
self.ref_lb_fully_populated.listeners = data_models.UnsetType()
16551670
self.ref_lb_fully_populated.pools = data_models.UnsetType()
1671+
1672+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1673+
{'id': self.loadbalancer_id}]}
1674+
mock_listener_create.return_value = {}
1675+
mock_pool_create.return_value = {}
1676+
16561677
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
16571678
mock_lb_create.assert_called_once_with(
16581679
self.driver._get_loadbalancer_request_info(
16591680
self.ref_lb_fully_populated),
16601681
)
16611682
mock_listener_create.assert_not_called()
16621683
mock_pool_create.assert_not_called()
1684+
expected_status = {
1685+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}]
1686+
}
1687+
mock_update_status.assert_called_once_with(expected_status)
16631688

16641689
@mock.patch.object(ovn_helper.OvnProviderHelper,
16651690
'_update_status_to_octavia')
@@ -1672,13 +1697,28 @@ def test_ensure_loadbalancer_lb_not_found_member_without_subnet(
16721697
mock_member_create, mock_update_status):
16731698
self.mock_find_ovn_lbs_with_retry.side_effect = [
16741699
idlutils.RowNotFound]
1700+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1701+
{'id': self.loadbalancer_id}]}
1702+
mock_listener_create.return_value = {constants.LISTENERS: [
1703+
{'id': self.listener_id}]}
1704+
mock_pool_create.return_value = {constants.POOLS: [
1705+
{'id': self.pool_id}]}
1706+
mock_member_create.return_value = {constants.MEMBERS: [
1707+
{'id': self.member_id}]}
16751708
self.ref_lb_fully_populated.listeners = []
16761709
self.ref_lb_fully_populated.pools[0].members[0].subnet_id = None
16771710
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
16781711
mock_member_create.assert_called_once_with(
16791712
self.driver._get_member_request_info(
16801713
self.ref_lb_fully_populated.pools[0].members[0]),
16811714
)
1715+
expected_status = {
1716+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1717+
constants.LISTENERS: [],
1718+
constants.POOLS: [{'id': self.pool_id}],
1719+
constants.MEMBERS: [{'id': self.member_id}]
1720+
}
1721+
mock_update_status.assert_called_once_with(expected_status)
16821722

16831723
@mock.patch.object(ovn_helper.OvnProviderHelper,
16841724
'_update_status_to_octavia')
@@ -1692,6 +1732,16 @@ def test_ensure_loadbalancer_lb_not_found_hm_found(
16921732
mock_member_create, mock_hm_create, mock_update_status):
16931733
self.mock_find_ovn_lbs_with_retry.side_effect = [
16941734
idlutils.RowNotFound]
1735+
1736+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1737+
{'id': self.loadbalancer_id}]}
1738+
mock_listener_create.return_value = {constants.LISTENERS: [
1739+
{'id': self.listener_id}]}
1740+
mock_pool_create.return_value = {constants.POOLS: [
1741+
{'id': self.pool_id}]}
1742+
mock_member_create.return_value = {constants.MEMBERS: [
1743+
{'id': self.member_id}]}
1744+
16951745
with mock.patch.object(
16961746
ovn_helper.OvnProviderHelper, '_find_ovn_lb_from_hm_id') \
16971747
as mock_find_ovn_lb_from_hm_id:
@@ -1700,6 +1750,15 @@ def test_ensure_loadbalancer_lb_not_found_hm_found(
17001750
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
17011751
mock_hm_create.assert_not_called()
17021752

1753+
expected_status = {
1754+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1755+
constants.LISTENERS: [{'id': self.listener_id}],
1756+
constants.POOLS: [{'id': self.pool_id}],
1757+
constants.MEMBERS: [{'id': self.member_id}],
1758+
constants.HEALTHMONITORS: []
1759+
}
1760+
mock_update_status.assert_called_once_with(expected_status)
1761+
17031762
@mock.patch.object(ovn_helper.OvnProviderHelper,
17041763
'_update_status_to_octavia')
17051764
@mock.patch.object(ovn_helper.OvnProviderHelper, 'hm_create')
@@ -1712,6 +1771,16 @@ def test_ensure_loadbalancer_lb_not_found_hm_lbhc_not_found(
17121771
mock_member_create, mock_hm_create, mock_update_status):
17131772
self.mock_find_ovn_lbs_with_retry.side_effect = [
17141773
idlutils.RowNotFound]
1774+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1775+
{'id': self.loadbalancer_id}]}
1776+
mock_listener_create.return_value = {constants.LISTENERS: [
1777+
{'id': self.listener_id}]}
1778+
mock_pool_create.return_value = {constants.POOLS: [
1779+
{'id': self.pool_id}]}
1780+
mock_member_create.return_value = {constants.MEMBERS: [
1781+
{'id': self.member_id}]}
1782+
mock_hm_create.return_value = {constants.HEALTHMONITORS: [
1783+
{'id': self.healthmonitor_id}]}
17151784
with mock.patch.object(
17161785
ovn_helper.OvnProviderHelper, '_find_ovn_lb_from_hm_id') \
17171786
as mock_find_ovn_lb_from_hm_id:
@@ -1722,6 +1791,14 @@ def test_ensure_loadbalancer_lb_not_found_hm_lbhc_not_found(
17221791
self.driver._get_healthmonitor_request_info(
17231792
self.ref_lb_fully_populated.pools[0].healthmonitor),
17241793
)
1794+
expected_status = {
1795+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1796+
constants.LISTENERS: [{'id': self.listener_id}],
1797+
constants.POOLS: [{'id': self.pool_id}],
1798+
constants.MEMBERS: [{'id': self.member_id}],
1799+
constants.HEALTHMONITORS: [{'id': self.healthmonitor_id}]
1800+
}
1801+
mock_update_status.assert_called_once_with(expected_status)
17251802

17261803
@mock.patch.object(ovn_helper.OvnProviderHelper,
17271804
'_update_status_to_octavia')
@@ -1735,6 +1812,10 @@ def test_ensure_loadbalancer_lb_not_found_without_pools(
17351812
self.mock_find_ovn_lbs_with_retry.side_effect = [
17361813
idlutils.RowNotFound]
17371814
self.ref_lb_fully_populated.pools = data_models.Unset
1815+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1816+
{'id': self.loadbalancer_id}]}
1817+
mock_listener_create.return_value = {constants.LISTENERS: [
1818+
{'id': self.listener_id}]}
17381819
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
17391820
mock_lb_create.assert_called_once_with(
17401821
self.driver._get_loadbalancer_request_info(
@@ -1745,6 +1826,11 @@ def test_ensure_loadbalancer_lb_not_found_without_pools(
17451826
self.ref_lb_fully_populated.listeners[0]),
17461827
)
17471828
mock_pool_create.assert_not_called()
1829+
expected_status = {
1830+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1831+
constants.LISTENERS: [{'id': self.listener_id}]
1832+
}
1833+
mock_update_status.assert_called_once_with(expected_status)
17481834

17491835
@mock.patch.object(ovn_helper.OvnProviderHelper,
17501836
'_update_status_to_octavia')
@@ -1758,6 +1844,13 @@ def test_ensure_loadbalancer_lb_not_found_without_members(
17581844
self.mock_find_ovn_lbs_with_retry.side_effect = [
17591845
idlutils.RowNotFound]
17601846
self.ref_lb_fully_populated.pools[0].members = []
1847+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1848+
{'id': self.loadbalancer_id}]}
1849+
mock_listener_create.return_value = {constants.LISTENERS: [
1850+
{'id': self.listener_id}]}
1851+
mock_pool_create.return_value = {constants.POOLS: [
1852+
{'id': self.pool_id}]}
1853+
17611854
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
17621855
mock_lb_create.assert_called_once_with(
17631856
self.driver._get_loadbalancer_request_info(
@@ -1772,6 +1865,12 @@ def test_ensure_loadbalancer_lb_not_found_without_members(
17721865
self.ref_lb_fully_populated.pools[0]),
17731866
)
17741867
mock_member_create.assert_not_called()
1868+
expected_status = {
1869+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1870+
constants.LISTENERS: [{'id': self.listener_id}],
1871+
constants.POOLS: [{'id': self.pool_id}]
1872+
}
1873+
mock_update_status.assert_called_once_with(expected_status)
17751874

17761875
@mock.patch.object(ovn_helper.OvnProviderHelper,
17771876
'_update_status_to_octavia')
@@ -1787,6 +1886,16 @@ def test_ensure_loadbalancer_lb_not_found_with_hm(
17871886
idlutils.RowNotFound]
17881887
self.ref_lb_fully_populated.pools[0].members = []
17891888
self.ref_pool.healthmonitor = self.ref_health_monitor
1889+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1890+
{'id': self.loadbalancer_id}]}
1891+
mock_listener_create.return_value = {constants.LISTENERS: [
1892+
{'id': self.listener_id}]}
1893+
mock_pool_create.return_value = {constants.POOLS: [
1894+
{'id': self.pool_id}]}
1895+
mock_member_create.return_value = {constants.MEMBERS: [
1896+
{'id': self.member_id}]}
1897+
mock_hm_create.return_value = {constants.HEALTHMONITORS: [
1898+
{'id': self.healthmonitor_id}]}
17901899
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
17911900
mock_lb_create.assert_called_once_with(
17921901
self.driver._get_loadbalancer_request_info(
@@ -1805,6 +1914,13 @@ def test_ensure_loadbalancer_lb_not_found_with_hm(
18051914
self.driver._get_healthmonitor_request_info(
18061915
self.ref_lb_fully_populated.pools[0].healthmonitor),
18071916
)
1917+
expected_status = {
1918+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1919+
constants.LISTENERS: [{'id': self.listener_id}],
1920+
constants.POOLS: [{'id': self.pool_id}],
1921+
constants.HEALTHMONITORS: [{'id': self.healthmonitor_id}]
1922+
}
1923+
mock_update_status.assert_called_once_with(expected_status)
18081924

18091925
@mock.patch.object(ovn_helper.OvnProviderHelper,
18101926
'_update_status_to_octavia')
@@ -1818,6 +1934,12 @@ def test_ensure_loadbalancer_lb_not_found_no_listeners(
18181934
self.mock_find_ovn_lbs_with_retry.side_effect = [
18191935
idlutils.RowNotFound]
18201936
self.ref_lb_fully_populated.listeners = []
1937+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1938+
{'id': self.loadbalancer_id}]}
1939+
mock_pool_create.return_value = {constants.POOLS: [
1940+
{'id': self.pool_id}]}
1941+
mock_member_create.return_value = {constants.MEMBERS: [
1942+
{'id': self.member_id}]}
18211943
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
18221944
mock_lb_create.assert_called_once_with(
18231945
self.driver._get_loadbalancer_request_info(
@@ -1832,6 +1954,13 @@ def test_ensure_loadbalancer_lb_not_found_no_listeners(
18321954
self.driver._get_member_request_info(
18331955
self.ref_lb_fully_populated.pools[0].members[0]),
18341956
)
1957+
expected_status = {
1958+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1959+
constants.LISTENERS: [],
1960+
constants.POOLS: [{'id': self.pool_id}],
1961+
constants.MEMBERS: [{'id': self.member_id}],
1962+
}
1963+
mock_update_status.assert_called_once_with(expected_status)
18351964

18361965
@mock.patch.object(ovn_helper.OvnProviderHelper,
18371966
'_update_status_to_octavia')
@@ -1845,6 +1974,10 @@ def test_ensure_loadbalancer_lb_not_found_no_pools(
18451974
self.mock_find_ovn_lbs_with_retry.side_effect = [
18461975
idlutils.RowNotFound]
18471976
self.ref_lb_fully_populated.pools = []
1977+
mock_lb_create.return_value = {constants.LOADBALANCERS: [
1978+
{'id': self.loadbalancer_id}]}
1979+
mock_listener_create.return_value = {constants.LISTENERS: [
1980+
{'id': self.listener_id}]}
18481981
self.driver._ensure_loadbalancer(self.ref_lb_fully_populated)
18491982
mock_lb_create.assert_called_once_with(
18501983
self.driver._get_loadbalancer_request_info(
@@ -1856,6 +1989,12 @@ def test_ensure_loadbalancer_lb_not_found_no_pools(
18561989
)
18571990
mock_pool_create.assert_not_called()
18581991
mock_member_create.assert_not_called()
1992+
expected_status = {
1993+
constants.LOADBALANCERS: [{'id': self.loadbalancer_id}],
1994+
constants.LISTENERS: [{'id': self.listener_id}],
1995+
constants.POOLS: []
1996+
}
1997+
mock_update_status.assert_called_once_with(expected_status)
18591998

18601999
@mock.patch.object(ovn_helper.OvnProviderHelper,
18612000
'_update_status_to_octavia')

0 commit comments

Comments
 (0)