Fix InstanceLocalityFilter scheduler filter

Commit I51254e20151fe1d6771897e64a8d0bdf2d674d03 introduces new error:
We use novaclient extensions instead of Nova API extensions. In such
case, InstanceLocalityFilter won't find Nova ExtendedServerAttributes
extension and will raise CinderException.

This patch fixes novaclient usage in a right way.

Change-Id: I36fb67d597b7848dd4796ea672bc573a570677e8
Closes-Bug: #1517431
This commit is contained in:
Ivan Kolodyazhny 2015-11-18 15:42:13 +02:00
parent 6f6b0221bd
commit 48ca2ca67c
3 changed files with 7 additions and 6 deletions

View File

@ -62,7 +62,8 @@ LOG = logging.getLogger(__name__)
NOVA_API_VERSION = 2
nova_extensions = [ext for ext in nova_client.discover_extensions(2)
if ext.name == "assisted_volume_snapshots"]
if ext.name in ("assisted_volume_snapshots",
"list_extensions")]
def novaclient(context, admin_endpoint=False, privileged_user=False,
@ -158,7 +159,7 @@ class API(base.Base):
def has_extension(self, context, extension, timeout=None):
try:
nova_exts = nova_client.discover_extensions(NOVA_API_VERSION)
nova_exts = novaclient(context).list_extensions.show_all()
except request_exceptions.Timeout:
raise exception.APITimeout(service='Nova')
return extension in [e.name for e in nova_exts]

View File

@ -139,7 +139,7 @@ class FakeNovaClient(object):
def __init__(self, ext_srv_attr=True):
self.servers = FakeNovaClient.ServerManager()
self.discover_extensions = FakeNovaClient.ListExtManager(
self.list_extensions = FakeNovaClient.ListExtManager(
ext_srv_attr=ext_srv_attr)

View File

@ -907,7 +907,7 @@ class InstanceLocalityFilterTestCase(HostFiltersTestCase):
def test_same_host(self, _mock_novaclient, fake_extensions):
_mock_novaclient.return_value = fakes.FakeNovaClient()
fake_extensions.return_value = (
fakes.FakeNovaClient().discover_extensions.show_all())
fakes.FakeNovaClient().list_extensions.show_all())
filt_cls = self.class_map['InstanceLocalityFilter']()
host = fakes.FakeHostState('host1', {})
uuid = nova.novaclient().servers.create('host1')
@ -921,7 +921,7 @@ class InstanceLocalityFilterTestCase(HostFiltersTestCase):
def test_different_host(self, _mock_novaclient, fake_extensions):
_mock_novaclient.return_value = fakes.FakeNovaClient()
fake_extensions.return_value = (
fakes.FakeNovaClient().discover_extensions.show_all())
fakes.FakeNovaClient().list_extensions.show_all())
filt_cls = self.class_map['InstanceLocalityFilter']()
host = fakes.FakeHostState('host1', {})
uuid = nova.novaclient().servers.create('host2')
@ -978,7 +978,7 @@ class InstanceLocalityFilterTestCase(HostFiltersTestCase):
# Simulate a HTTP timeout
_mock_request.side_effect = request_exceptions.Timeout
fake_extensions.return_value = (
fakes.FakeNovaClient().discover_extensions.show_all())
fakes.FakeNovaClient().list_extensions.show_all())
filt_cls = self.class_map['InstanceLocalityFilter']()
host = fakes.FakeHostState('host1', {})