210
210
return {'ports': list_ports_retval.pop(0)}
212
212
self.qclient.return_value.list_ports.side_effect = mock_list_ports
213
self.qclient.return_value.get_auth_info.return_value = {
214
'auth_token': None, 'endpoint_url': None}
213
215
instance_id, tenant_id = self.handler._get_instance_and_tenant_id(req)
214
216
new_qclient_call = mock.call(
215
217
username=FakeConf.admin_user,
231
234
mock.call().list_ports(
232
235
device_id=router_id,
233
236
device_owner=constants.DEVICE_OWNER_ROUTER_INTF
238
mock.call().get_auth_info()
237
241
expected.extend([
238
242
new_qclient_call,
239
243
mock.call().list_ports(
240
244
network_id=networks or tuple(),
241
fixed_ips=['ip_address=192.168.1.1'])
245
fixed_ips=['ip_address=192.168.1.1']),
246
mock.call().get_auth_info()
244
249
self.qclient.assert_has_calls(expected)
321
def test_auth_info_cache(self):
325
[{'network_id': 'net1'}],
326
[{'device_id': 'did', 'tenant_id': 'tid', 'network_id': 'net1'}]]
328
def update_get_auth_info(*args, **kwargs):
329
self.qclient.return_value.get_auth_info.return_value = {
330
'auth_token': 'token', 'endpoint_url': 'uri'}
331
return {'ports': list_ports.pop(0)}
333
self.qclient.return_value.list_ports.side_effect = update_get_auth_info
335
new_qclient_call = mock.call(
336
username=FakeConf.admin_user,
337
tenant_name=FakeConf.admin_tenant_name,
338
region_name=FakeConf.auth_region,
339
auth_url=FakeConf.auth_url,
340
password=FakeConf.admin_password,
341
auth_strategy=FakeConf.auth_strategy,
343
insecure=FakeConf.auth_insecure,
344
ca_cert=FakeConf.auth_ca_cert,
346
endpoint_type=FakeConf.endpoint_type)
348
cached_qclient_call = mock.call(
349
username=FakeConf.admin_user,
350
tenant_name=FakeConf.admin_tenant_name,
351
region_name=FakeConf.auth_region,
352
auth_url=FakeConf.auth_url,
353
password=FakeConf.admin_password,
354
auth_strategy=FakeConf.auth_strategy,
356
insecure=FakeConf.auth_insecure,
357
ca_cert=FakeConf.auth_ca_cert,
359
endpoint_type=FakeConf.endpoint_type)
361
headers = {'X-Forwarded-For': '192.168.1.10',
362
'X-Neutron-Router-ID': router_id}
363
req = mock.Mock(headers=headers)
364
self.handler._get_instance_and_tenant_id(req)
368
mock.call().list_ports(
370
device_owner=constants.DEVICE_OWNER_ROUTER_INTF
372
mock.call().get_auth_info(),
374
mock.call().list_ports(
375
network_id=networks or tuple(),
376
fixed_ips=['ip_address=192.168.1.10']),
377
mock.call().get_auth_info(),
380
self.qclient.assert_has_calls(expected)
316
382
def _proxy_request_test_helper(self, response_code=200, method='GET'):
317
383
hdrs = {'X-Forwarded-For': '8.8.8.8'}