~corey.bryant/ubuntu/trusty/neutron/lp1318721

« back to all changes in this revision

Viewing changes to neutron/tests/unit/test_metadata_agent.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Corey Bryant
  • Date: 2014-10-06 09:15:06 UTC
  • mfrom: (28.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20141006091506-cesvev43moce4y74
Tags: 1:2014.1.3-0ubuntu1
[ Corey Bryant ]
* Resynchronize with stable/icehouse (4a0210e) (LP: #1377136):
  - [3a30d19] Deletes floating ip related connection states
  - [dd4b77f] Forbid regular users to reset admin-only attrs to default values
  - [dc2c893] Add delete operations for the ODL MechanismDriver
  - [b51e2c7] Add missing ml2 plugin to migration 1fcfc149aca4
  - [a17a500] Don't convert numeric protocol values to int
  - [3a85946] NSX: Optionally not enforce nat rule match length check
  - [645f984] Don't spawn metadata-proxy for non-isolated nets
  - [b464d89] Big Switch: Check for 'id' in port before lookup
  - [3116ffa] use TRUE in SQL for boolean var
  - [3520e66] call security_groups_member_updated in port_update
  - [50e1534] Don't allow user to set firewall rule with port and no protocol
  - [0061533] BSN: Add context to backend request for debugging
  - [6de6d61] Improve ODL ML2 Exception Handling
  - [2a4153d] Send network name and uuid to subnet create
  - [b5e3c9a] BSN: Allow concurrent reads to consistency DB
  - [b201432] Big Switch: Retry on 503 errors from backend
  - [f6c47ee] NSX: log request body to NSX as debug
  - [97d622a] Fix metadata agent's auth info caching
  - [255df45] NSX: Correct allowed_address_pair return value on create_port
  - [5bea041] Neutron should not use the neutronclient utils module for import_class
  - [d5314e2] Cisco N1kv plugin to send subtype on network profile creation
  - [f32d1ce] Pass object to policy when finding fields to strip
  - [8b5f6be] Call policy.init() once per API request
  - [9a6d811] Perform policy checks only once on list responses
  - [c48db90] Datacenter moid should not be tuple
  - [161d465] Allow unsharing a network used as gateway/floatingip
  - [9574a2f] Add support for router scheduling in Cisco N1kv Plugin
  - [6f54565] Fix func job hook script permission problems
  - [ea43103] Add hook scripts for the functional infra job
  - [8161cb7] Fixes Hyper-V agent issue on Hyper-V 2008 R2
  - [8e99cfd] Fixes Hyper-V issue due to ML2 RPC versioning
  - [69f9121] Ensure ip6tables are used only if ipv6 is enabled in kernel
  - [399b809] Remove explicit dependency on amqplib
  - [a872143] Clear entries in Cisco N1KV specific tables on rollback
  - [ad82fad] Verify ML2 type driver exists before calling del
  - [af2cc98] Big Switch: Only update hash header on success
  - [b1e5eec] Ignore variable column widths in ovsdb functional tests
  - [4a0210e] VMWare: don't notify on disassociate_floatingips()

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
            return {'ports': list_ports_retval.pop(0)}
211
211
 
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,
223
225
            ca_cert=FakeConf.auth_ca_cert,
224
226
            endpoint_url=None,
225
227
            endpoint_type=FakeConf.endpoint_type)
226
 
        expected = [new_qclient_call]
 
228
 
 
229
        expected = []
227
230
 
228
231
        if router_id:
229
232
            expected.extend([
231
234
                mock.call().list_ports(
232
235
                    device_id=router_id,
233
236
                    device_owner=constants.DEVICE_OWNER_ROUTER_INTF
234
 
                )
 
237
                ),
 
238
                mock.call().get_auth_info()
235
239
            ])
236
240
 
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()
242
247
        ])
243
248
 
244
249
        self.qclient.assert_has_calls(expected)
313
318
            (None, None)
314
319
        )
315
320
 
 
321
    def test_auth_info_cache(self):
 
322
        router_id = 'the_id'
 
323
        networks = ('net1',)
 
324
        list_ports = [
 
325
            [{'network_id': 'net1'}],
 
326
            [{'device_id': 'did', 'tenant_id': 'tid', 'network_id': 'net1'}]]
 
327
 
 
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)}
 
332
 
 
333
        self.qclient.return_value.list_ports.side_effect = update_get_auth_info
 
334
 
 
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,
 
342
            token=None,
 
343
            insecure=FakeConf.auth_insecure,
 
344
            ca_cert=FakeConf.auth_ca_cert,
 
345
            endpoint_url=None,
 
346
            endpoint_type=FakeConf.endpoint_type)
 
347
 
 
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,
 
355
            token='token',
 
356
            insecure=FakeConf.auth_insecure,
 
357
            ca_cert=FakeConf.auth_ca_cert,
 
358
            endpoint_url='uri',
 
359
            endpoint_type=FakeConf.endpoint_type)
 
360
 
 
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)
 
365
 
 
366
        expected = [
 
367
            new_qclient_call,
 
368
            mock.call().list_ports(
 
369
                device_id=router_id,
 
370
                device_owner=constants.DEVICE_OWNER_ROUTER_INTF
 
371
            ),
 
372
            mock.call().get_auth_info(),
 
373
            cached_qclient_call,
 
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(),
 
378
        ]
 
379
 
 
380
        self.qclient.assert_has_calls(expected)
 
381
 
316
382
    def _proxy_request_test_helper(self, response_code=200, method='GET'):
317
383
        hdrs = {'X-Forwarded-For': '8.8.8.8'}
318
384
        body = 'body'