From a4fd1a9689461587bb5d72862e6598aa8d78fd12 Mon Sep 17 00:00:00 2001 From: houming-wang Date: Wed, 13 Jan 2016 15:11:05 +0800 Subject: [PATCH] Do not use inner class of novaclient Currently in Magnum, novaclient is initiated by directly call inner class of novaclient: novaclient.v2.client.Client. But it's not designed to be initialized directly. We should use 'novaclient.client.Client'. Reference links: [1] http://docs.openstack.org/developer/python-novaclient/api.html#usage [2] https://launchpad.net/bugs/1493576 Change-Id: I85c37e7934962c9f01a4be1131808222c315ba45 Closes-Bug: #1533510 --- etc/magnum/magnum.conf.sample | 3 +++ magnum/common/clients.py | 11 ++++++++--- magnum/tests/unit/common/test_clients.py | 8 +++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/etc/magnum/magnum.conf.sample b/etc/magnum/magnum.conf.sample index c913618db4..f1b0a2e25a 100644 --- a/etc/magnum/magnum.conf.sample +++ b/etc/magnum/magnum.conf.sample @@ -931,6 +931,9 @@ # communication with the OpenStack service. (string value) #endpoint_type = publicURL +# Version of Nova API to use in novaclient. (string value) +#api_version = 2 + [oslo_concurrency] diff --git a/magnum/common/clients.py b/magnum/common/clients.py index 4b0c43f23c..48343685de 100644 --- a/magnum/common/clients.py +++ b/magnum/common/clients.py @@ -16,7 +16,7 @@ from barbicanclient import client as barbicanclient from glanceclient.v2 import client as glanceclient from heatclient.v1 import client as heatclient from neutronclient.v2_0 import client as neutronclient -from novaclient.v2 import client as novaclient +from novaclient import client as novaclient from oslo_config import cfg from magnum.common import exception @@ -83,7 +83,10 @@ nova_client_opts = [ default='publicURL', help=_( 'Type of endpoint in Identity service catalog to use ' - 'for communication with the OpenStack service.'))] + 'for communication with the OpenStack service.')), + cfg.StrOpt('api_version', + default='2', + help=_('Version of Nova API to use in novaclient.'))] neutron_client_opts = [ cfg.StrOpt('region_name', @@ -212,10 +215,12 @@ class OpenStackClients(object): return self._nova endpoint_type = self._get_client_option('nova', 'endpoint_type') region_name = self._get_client_option('nova', 'region_name') + novaclient_version = self._get_client_option('nova', 'api_version') endpoint = self.url_for(service_type='compute', endpoint_type=endpoint_type, region_name=region_name) - self._nova = novaclient.Client(auth_token=self.auth_token) + self._nova = novaclient.Client(novaclient_version, + auth_token=self.auth_token) self._nova.client.management_url = endpoint return self._nova diff --git a/magnum/tests/unit/common/test_clients.py b/magnum/tests/unit/common/test_clients.py index 71c408ebc8..da706280ac 100644 --- a/magnum/tests/unit/common/test_clients.py +++ b/magnum/tests/unit/common/test_clients.py @@ -15,7 +15,7 @@ from glanceclient.v2 import client as glanceclient from heatclient.v1 import client as heatclient import mock from neutronclient.v2_0 import client as neutronclient -from novaclient.v2 import client as novaclient +from novaclient import client as novaclient from oslo_config import cfg from magnum.common import clients @@ -30,6 +30,8 @@ class ClientsTest(base.BaseTestCase): cfg.CONF.set_override('auth_uri', 'http://server.test:5000/v2.0', group='keystone_authtoken') + cfg.CONF.import_opt('api_version', 'magnum.common.clients', + group='nova_client') @mock.patch.object(clients.OpenStackClients, 'keystone') def test_url_for(self, mock_keystone): @@ -240,8 +242,8 @@ class ClientsTest(base.BaseTestCase): obj = clients.OpenStackClients(con) obj._nova = None obj.nova() - mock_call.assert_called_once_with( - auth_token='3bcc3d3a03f44e3d8377f9247b0ad155') + mock_call.assert_called_once_with(cfg.CONF.nova_client.api_version, + auth_token=con.auth_token) mock_url.assert_called_once_with(service_type='compute', endpoint_type='publicURL', region_name=expected_region_name)