Skip to content

Commit ab342fc

Browse files
committed
Retry netlbfo team creation
The WMI implementation for NETLBFO is sometimes flaky and does not fail when a bond cannot be created. Added 5 retries for the team creation, just in case the WMI call to create the bond did not fail, but the bond was not created. In this scenario, the _wait_for_nic method is called and it fails, as it does not find the team nic and the retry is performed. Updated the wait for team nic retry interval to 10 seconds, as the team nic may be retrieved with WMI after a longer time. Change-Id: I7622a4a30b867f335ed8f3288ca2fea830daf94b
1 parent 08641ae commit ab342fc

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

cloudbaseinit/tests/utils/windows/test_netlbfo.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def setUp(self):
4141
def tearDown(self):
4242
self._module_patcher.stop()
4343

44+
@mock.patch('time.sleep')
4445
@mock.patch(MODPATH + '.NetLBFOTeamManager._get_primary_adapter_name')
4546
@mock.patch(MODPATH + '.NetLBFOTeamManager._create_team')
4647
@mock.patch(MODPATH + '.NetLBFOTeamManager._add_team_member')
@@ -49,10 +50,11 @@ def tearDown(self):
4950
@mock.patch(MODPATH + '.NetLBFOTeamManager.delete_team')
5051
def _test_create_team(self, mock_delete_team, mock_wait_for_nic,
5152
mock_set_primary_nic_vlan_id, mock_add_team_member,
52-
mock_create_team, mock_get_primary_adapter_name,
53-
mode_not_found=False, lb_algo_not_found=False,
53+
mock_create_team, mock_primary_adapter_name,
54+
mock_time_sleep, mode_not_found=False,
55+
lb_algo_not_found=False,
5456
add_team_member_fail=False):
55-
mock_get_primary_adapter_name.return_value = mock.sentinel.pri_nic_name
57+
mock_primary_adapter_name.return_value = mock.sentinel.pri_nic_name
5658
mock_create_team.return_value = None
5759

5860
lacp_timer = network_model.BOND_LACP_RATE_FAST
@@ -100,9 +102,6 @@ def _test_create_team(self, mock_delete_team, mock_wait_for_nic,
100102
mock.sentinel.mac, mock.sentinel.pri_nic_name,
101103
mock.sentinel.vlan_id, lacp_timer)
102104

103-
mock_add_team_member.assert_called_once_with(
104-
conn, mock.sentinel.team_name, mock.sentinel.other_member)
105-
106105
if not add_team_member_fail:
107106
mock_set_primary_nic_vlan_id.assert_called_once_with(
108107
conn, mock.sentinel.team_name, mock.sentinel.vlan_id)
@@ -111,8 +110,14 @@ def _test_create_team(self, mock_delete_team, mock_wait_for_nic,
111110
2, 3, mock.sentinel.pri_nic_name, 1)
112111
mock_wait_for_nic.assert_called_once_with(
113112
mock_team_nic.Name)
113+
mock_add_team_member.assert_called_once_with(
114+
conn, mock.sentinel.team_name, mock.sentinel.other_member)
114115
else:
115-
mock_delete_team.assert_called_once_with(mock.sentinel.team_name)
116+
mock_add_team_member.assert_called_with(
117+
conn, mock.sentinel.team_name, mock.sentinel.other_member)
118+
mock_delete_team.assert_called_with(mock.sentinel.team_name)
119+
self.assertEqual(mock_add_team_member.call_count, 6)
120+
self.assertEqual(mock_delete_team.call_count, 6)
116121

117122
def test_create_team(self):
118123
self._test_create_team()

cloudbaseinit/utils/windows/netlbfo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def _create_team(conn, team_name, nic_name, teaming_mode, lb_algo,
132132
operation_options = {u'custom_options': custom_options}
133133
team.put(operation_options=operation_options)
134134

135+
@retry_decorator.retry_decorator(max_retry_count=5)
135136
def create_team(self, team_name, mode, load_balancing_algorithm,
136137
members, mac_address, primary_nic_name=None,
137138
primary_nic_vlan_id=None, lacp_timer=None):
@@ -178,7 +179,8 @@ def create_team(self, team_name, mode, load_balancing_algorithm,
178179
raise ex
179180

180181
@staticmethod
181-
@retry_decorator.retry_decorator(max_retry_count=10)
182+
@retry_decorator.retry_decorator(max_retry_count=10,
183+
max_sleep_time=10)
182184
def _wait_for_nic(nic_name):
183185
conn = wmi.WMI(moniker='//./root/cimv2')
184186
if not conn.Win32_NetworkAdapter(NetConnectionID=nic_name):

0 commit comments

Comments
 (0)