From 48ca2ca67c63cc57965f339bb45999222b4fc771 Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Wed, 18 Nov 2015 15:42:13 +0200 Subject: [PATCH] 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 --- cinder/compute/nova.py | 5 +++-- cinder/tests/unit/scheduler/fakes.py | 2 +- cinder/tests/unit/scheduler/test_host_filters.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cinder/compute/nova.py b/cinder/compute/nova.py index 600e823d5..1c8aebde4 100644 --- a/cinder/compute/nova.py +++ b/cinder/compute/nova.py @@ -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] diff --git a/cinder/tests/unit/scheduler/fakes.py b/cinder/tests/unit/scheduler/fakes.py index 58b774374..071eb64e6 100644 --- a/cinder/tests/unit/scheduler/fakes.py +++ b/cinder/tests/unit/scheduler/fakes.py @@ -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) diff --git a/cinder/tests/unit/scheduler/test_host_filters.py b/cinder/tests/unit/scheduler/test_host_filters.py index 659119dff..ea1dbac30 100644 --- a/cinder/tests/unit/scheduler/test_host_filters.py +++ b/cinder/tests/unit/scheduler/test_host_filters.py @@ -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', {}) -- 2.45.2