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
This commit is contained in:
houming-wang 2016-01-13 15:11:05 +08:00
parent 8c07e2c5c2
commit a4fd1a9689
3 changed files with 16 additions and 6 deletions

View File

@ -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]

View File

@ -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

View File

@ -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)