diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 2a041e6ab..7fd12b960 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -22,7 +22,6 @@ import string from novaclient import client as nc from novaclient import exceptions -from novaclient import shell as novashell from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import uuidutils @@ -65,8 +64,16 @@ class NovaClientPlugin(client_plugin.ClientPlugin): management_url = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) - computeshell = novashell.OpenStackComputeShell() - extensions = computeshell._discover_extensions(NOVACLIENT_VERSION) + if hasattr(nc, 'discover_extensions'): + extensions = nc.discover_extensions(NOVACLIENT_VERSION) + else: + # TODO(lyj): The else condition is for backward compatibility, + # once novaclient bump to a newer version with + # discover_extensions exists, this should be safely + # removed. + from novaclient import shell as novashell + computeshell = novashell.OpenStackComputeShell() + extensions = computeshell._discover_extensions(NOVACLIENT_VERSION) args = { 'project_id': self.context.tenant, diff --git a/heat/tests/test_nova_client.py b/heat/tests/test_nova_client.py index 3322830bd..7e10cb56c 100644 --- a/heat/tests/test_nova_client.py +++ b/heat/tests/test_nova_client.py @@ -16,6 +16,7 @@ import collections import uuid import mock +from novaclient import client as nc from novaclient import exceptions as nova_exceptions from oslo_config import cfg import six @@ -44,6 +45,13 @@ class NovaClientPluginTests(NovaClientPluginTestCase): :module:'heat.engine.clients.os.nova'. """ + def test_create(self): + self.nova_plugin._get_client_option = mock.MagicMock() + self.nova_plugin.url_for = mock.MagicMock() + nc.discover_extensions = mock.MagicMock() + self.nova_plugin._create() + nc.discover_extensions.assert_called_once_with('2') + def test_get_ip(self): my_image = mock.MagicMock() my_image.addresses = {