@@ -169,7 +169,7 @@ def _update_metadata_port_ip(self, metadata_port_name):
169
169
self .nb_api .set_lswitch_port (lport_name = metadata_port_name ,
170
170
external_ids = external_ids ).execute ()
171
171
172
- def _create_logical_switch_port (self , type_ = None ):
172
+ def _create_logical_switch_port (self , type_ = None , addresses = None ):
173
173
lswitch_name = 'ovn-' + uuidutils .generate_uuid ()
174
174
lswitchport_name = 'ovn-port-' + uuidutils .generate_uuid ()
175
175
# 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):
179
179
self .handler .watch_event (pb_event )
180
180
181
181
lswitch_port_columns = {}
182
+ if addresses :
183
+ lswitch_port_columns ['addresses' ] = addresses
182
184
if type_ :
183
185
lswitch_port_columns ['type' ] = type_
184
186
@@ -193,30 +195,33 @@ def _create_logical_switch_port(self, type_=None):
193
195
194
196
return lswitchport_name , lswitch_name
195
197
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 ]
198
202
# The agent has initialized with br-int and above list_br doesn't
199
203
# return it, hence the agent should trigger reconfiguration and store
200
204
# new br-new value to its attribute.
201
205
self .assertEqual (self .OVN_BRIDGE , self .agent .ovn_bridge )
202
206
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
+ )
204
213
205
214
# Trigger PortBindingChassisCreatedEvent
206
215
self .sb_api .lsp_bind (lswitchport_name , self .chassis_name ).execute (
207
216
check_error = True , log_errors = True )
208
- exc = Exception ('PortBindingChassisCreatedEvent was not called' )
209
217
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 )
220
225
221
226
def _test_agent_events (self , delete , type_ = None , update = False ):
222
227
m_pb_created = mock .patch .object (
0 commit comments