Skip to content

Commit b1da5a1

Browse files
committed
Reintroduce agent bridge resync test
It appears we have changed the test_agent_resync_on_non_existing_bridgetest main purpose in change 709544[1]. The test is no longer testing on what is describing it will test, i.e. resync on bridge change. Testing resync on a bridge change is still important. I feel like what the test is testing is already covered in _test_agent_events set of tests. [1] https://review.opendev.org/c/openstack/neutron/+/709544 Change-Id: I8f164c12db7c4c1aa54ba07feede3586e6a19381 (cherry picked from commit 75e8360)
1 parent f5815bc commit b1da5a1

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
@@ -143,7 +143,7 @@ def _create_metadata_port(self, txn, lswitch_name):
143143
external_ids={
144144
ovn_const.OVN_CIDRS_EXT_ID_KEY: '192.168.122.123/24'}))
145145

146-
def _create_logical_switch_port(self, type_=None):
146+
def _create_logical_switch_port(self, type_=None, addresses=None):
147147
lswitch_name = 'ovn-' + uuidutils.generate_uuid()
148148
lswitchport_name = 'ovn-port-' + uuidutils.generate_uuid()
149149
# It may take some time to ovn-northd to translate from OVN NB DB to
@@ -153,6 +153,8 @@ def _create_logical_switch_port(self, type_=None):
153153
self.handler.watch_event(pb_event)
154154

155155
lswitch_port_columns = {}
156+
if addresses:
157+
lswitch_port_columns['addresses'] = addresses
156158
if type_:
157159
lswitch_port_columns['type'] = type_
158160

@@ -167,30 +169,33 @@ def _create_logical_switch_port(self, type_=None):
167169

168170
return lswitchport_name, lswitch_name
169171

170-
@mock.patch.object(agent.PortBindingChassisCreatedEvent, 'run')
171-
def test_agent_resync_on_non_existing_bridge(self, mock_pbinding):
172+
def test_agent_resync_on_non_existing_bridge(self):
173+
BR_NEW = 'br-new'
174+
self._mock_get_ovn_br.return_value = BR_NEW
175+
self.agent.ovs_idl.list_br.return_value.execute.return_value = [BR_NEW]
172176
# The agent has initialized with br-int and above list_br doesn't
173177
# return it, hence the agent should trigger reconfiguration and store
174178
# new br-new value to its attribute.
175179
self.assertEqual(self.OVN_BRIDGE, self.agent.ovn_bridge)
176180

177-
lswitchport_name, _ = self._create_logical_switch_port()
181+
# NOTE: The IP address is specifically picked such that it fits the
182+
# metadata port external_ids: { neutron:cidrs }. This is because agent
183+
# will only trigger if the logical port is part of a neutron subnet
184+
lswitchport_name, _ = self._create_logical_switch_port(
185+
addresses='AA:AA:AA:AA:AA:AB 192.168.122.125'
186+
)
178187

179188
# Trigger PortBindingChassisCreatedEvent
180189
self.sb_api.lsp_bind(lswitchport_name, self.chassis_name).execute(
181190
check_error=True, log_errors=True)
182-
exc = Exception('PortBindingChassisCreatedEvent was not called')
183191

184-
def check_mock_pbinding():
185-
if mock_pbinding.call_count < 1:
186-
return False
187-
args = mock_pbinding.call_args[0]
188-
self.assertEqual('update', args[0])
189-
self.assertEqual(lswitchport_name, args[1].logical_port)
190-
self.assertEqual(self.chassis_name, args[1].chassis[0].name)
191-
return True
192-
193-
n_utils.wait_until_true(check_mock_pbinding, timeout=10, exception=exc)
192+
exc = Exception("Agent bridge hasn't changed from %s to %s "
193+
"in 10 seconds after Port_Binding event" %
194+
(self.agent.ovn_bridge, BR_NEW))
195+
n_utils.wait_until_true(
196+
lambda: BR_NEW == self.agent.ovn_bridge,
197+
timeout=10,
198+
exception=exc)
194199

195200
def _test_agent_events(self, delete, type_=None):
196201
m_pb_created = mock.patch.object(

0 commit comments

Comments
 (0)