Skip to content

Commit eea7fe4

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reintroduce agent bridge resync test" into stable/2023.1
2 parents a59dddd + d69d868 commit eea7fe4

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _update_metadata_port_ip(self, metadata_port_name):
169169
self.nb_api.set_lswitch_port(lport_name=metadata_port_name,
170170
external_ids=external_ids).execute()
171171

172-
def _create_logical_switch_port(self, type_=None):
172+
def _create_logical_switch_port(self, type_=None, addresses=None):
173173
lswitch_name = 'ovn-' + uuidutils.generate_uuid()
174174
lswitchport_name = 'ovn-port-' + uuidutils.generate_uuid()
175175
# It may take some time to ovn-northd to translate from OVN NB DB to
@@ -179,6 +179,8 @@ def _create_logical_switch_port(self, type_=None):
179179
self.handler.watch_event(pb_event)
180180

181181
lswitch_port_columns = {}
182+
if addresses:
183+
lswitch_port_columns['addresses'] = addresses
182184
if type_:
183185
lswitch_port_columns['type'] = type_
184186

@@ -193,30 +195,33 @@ def _create_logical_switch_port(self, type_=None):
193195

194196
return lswitchport_name, lswitch_name
195197

196-
@mock.patch.object(agent.PortBindingChassisCreatedEvent, 'run')
197-
def test_agent_resync_on_non_existing_bridge(self, mock_pbinding):
198+
def test_agent_resync_on_non_existing_bridge(self):
199+
BR_NEW = 'br-new'
200+
self._mock_get_ovn_br.return_value = BR_NEW
201+
self.agent.ovs_idl.list_br.return_value.execute.return_value = [BR_NEW]
198202
# The agent has initialized with br-int and above list_br doesn't
199203
# return it, hence the agent should trigger reconfiguration and store
200204
# new br-new value to its attribute.
201205
self.assertEqual(self.OVN_BRIDGE, self.agent.ovn_bridge)
202206

203-
lswitchport_name, _ = self._create_logical_switch_port()
207+
# NOTE: The IP address is specifically picked such that it fits the
208+
# metadata port external_ids: { neutron:cidrs }. This is because agent
209+
# will only trigger if the logical port is part of a neutron subnet
210+
lswitchport_name, _ = self._create_logical_switch_port(
211+
addresses='AA:AA:AA:AA:AA:AB 192.168.122.125'
212+
)
204213

205214
# Trigger PortBindingChassisCreatedEvent
206215
self.sb_api.lsp_bind(lswitchport_name, self.chassis_name).execute(
207216
check_error=True, log_errors=True)
208-
exc = Exception('PortBindingChassisCreatedEvent was not called')
209217

210-
def check_mock_pbinding():
211-
if mock_pbinding.call_count < 1:
212-
return False
213-
args = mock_pbinding.call_args[0]
214-
self.assertEqual('update', args[0])
215-
self.assertEqual(lswitchport_name, args[1].logical_port)
216-
self.assertEqual(self.chassis_name, args[1].chassis[0].name)
217-
return True
218-
219-
n_utils.wait_until_true(check_mock_pbinding, timeout=10, exception=exc)
218+
exc = Exception("Agent bridge hasn't changed from %s to %s "
219+
"in 10 seconds after Port_Binding event" %
220+
(self.agent.ovn_bridge, BR_NEW))
221+
n_utils.wait_until_true(
222+
lambda: BR_NEW == self.agent.ovn_bridge,
223+
timeout=10,
224+
exception=exc)
220225

221226
def _test_agent_events(self, delete, type_=None, update=False):
222227
m_pb_created = mock.patch.object(

0 commit comments

Comments
 (0)