diff options
| author | Gary Kotton <gkotton@redhat.com> | 2012-12-09 15:57:05 +0000 |
|---|---|---|
| committer | Gary Kotton <gkotton@redhat.com> | 2012-12-09 19:35:17 +0000 |
| commit | 02797aab3c78961c0cf100df4367df61654bedc1 (patch) | |
| tree | cb956d28b256f9b71e614c6cd38fd591a81f2eb5 /nova | |
| parent | 85f857e62a5edacbf467c19add6e51565ae3669f (diff) | |
| download | nova-02797aab3c78961c0cf100df4367df61654bedc1.tar.gz nova-02797aab3c78961c0cf100df4367df61654bedc1.tar.xz nova-02797aab3c78961c0cf100df4367df61654bedc1.zip | |
Use admin user to read Quantum port.
This is part of blueprint vif-plugging-improvements.
The port vif_type is only returned from Quantum when the user
is an admin user.
This patch ensures that when Nova reads the ports the user is an
admin user.
Change-Id: I4d1a2bfc6e3ae4ad63fe5c72eda32137713b31c6
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/network/quantumv2/__init__.py | 11 | ||||
| -rw-r--r-- | nova/network/quantumv2/api.py | 3 | ||||
| -rw-r--r-- | nova/tests/network/test_quantumv2.py | 12 |
3 files changed, 23 insertions, 3 deletions
diff --git a/nova/network/quantumv2/__init__.py b/nova/network/quantumv2/__init__.py index 151bd6afa..ff96edf30 100644 --- a/nova/network/quantumv2/__init__.py +++ b/nova/network/quantumv2/__init__.py @@ -42,8 +42,7 @@ def _get_auth_token(): return httpclient.auth_token -def get_client(context): - token = context.auth_token +def _get_client(token=None): if not token and CONF.quantum_auth_strategy: token = _get_auth_token() params = { @@ -55,3 +54,11 @@ def get_client(context): else: params['auth_strategy'] = None return clientv20.Client(**params) + + +def get_client(context, admin=False): + if admin: + token = None + else: + token = context.auth_token + return _get_client(token=token) diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 180d14c0f..b381df47a 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -533,7 +533,8 @@ class API(base.Base): def _build_network_info_model(self, context, instance, networks=None): search_opts = {'tenant_id': instance['project_id'], 'device_id': instance['uuid'], } - data = quantumv2.get_client(context).list_ports(**search_opts) + data = quantumv2.get_client(context, + admin=True).list_ports(**search_opts) ports = data.get('ports', []) if not networks: networks = self._get_available_networks(context, diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index 8ceaa4c99..6cb0728a2 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -270,10 +270,16 @@ class TestQuantumv2(test.TestCase): def test_get_instance_nw_info_1(self): """Test to get one port in one network and subnet.""" + quantumv2.get_client(mox.IgnoreArg(), + admin=True).MultipleTimes().AndReturn( + self.moxed_client) self._get_instance_nw_info(1) def test_get_instance_nw_info_2(self): """Test to get one port in each of two networks and subnets.""" + quantumv2.get_client(mox.IgnoreArg(), + admin=True).MultipleTimes().AndReturn( + self.moxed_client) self._get_instance_nw_info(2) def test_get_instance_nw_info_with_nets(self): @@ -294,6 +300,9 @@ class TestQuantumv2(test.TestCase): network_id='my_netid1', device_owner='network:dhcp').AndReturn( {'ports': self.dhcp_port_data1}) + quantumv2.get_client(mox.IgnoreArg(), + admin=True).MultipleTimes().AndReturn( + self.moxed_client) self.mox.ReplayAll() nw_inf = api.get_instance_nw_info(self.context, self.instance, @@ -317,6 +326,9 @@ class TestQuantumv2(test.TestCase): {'networks': self.nets1}) self.moxed_client.list_networks( shared=True).AndReturn({'networks': []}) + quantumv2.get_client(mox.IgnoreArg(), + admin=True).MultipleTimes().AndReturn( + self.moxed_client) self.mox.ReplayAll() nw_inf = api.get_instance_nw_info(self.context, |
