Merge "Fix instance locality scheduler filter"
This commit is contained in:
commit
c190a7cab8
@ -173,13 +173,6 @@ class API(base.Base):
|
||||
return False
|
||||
return True
|
||||
|
||||
def has_extension(self, context, extension, timeout=None):
|
||||
try:
|
||||
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]
|
||||
|
||||
def update_server_volume(self, context, server_id, src_volid,
|
||||
new_volume_id):
|
||||
nova = novaclient(context, privileged_user=True)
|
||||
|
@ -56,19 +56,6 @@ class InstanceLocalityFilter(filters.BaseBackendFilter):
|
||||
self._cache = {}
|
||||
super(InstanceLocalityFilter, self).__init__()
|
||||
|
||||
def _nova_has_extended_server_attributes(self, context):
|
||||
"""Check Extended Server Attributes presence
|
||||
|
||||
Find out whether the Extended Server Attributes extension is activated
|
||||
in Nova or not. Cache the result to query Nova only once.
|
||||
"""
|
||||
|
||||
if not hasattr(self, '_nova_ext_srv_attr'):
|
||||
self._nova_ext_srv_attr = nova.API().has_extension(
|
||||
context, 'ExtendedServerAttributes', timeout=REQUESTS_TIMEOUT)
|
||||
|
||||
return self._nova_ext_srv_attr
|
||||
|
||||
def backend_passes(self, backend_state, filter_properties):
|
||||
context = filter_properties['context']
|
||||
backend = volume_utils.extract_host(backend_state.backend_id, 'host')
|
||||
@ -95,13 +82,6 @@ class InstanceLocalityFilter(filters.BaseBackendFilter):
|
||||
if instance_uuid in self._cache:
|
||||
return self._cache[instance_uuid] == backend
|
||||
|
||||
if not self._nova_has_extended_server_attributes(context):
|
||||
LOG.warning('Hint "%s" dropped because '
|
||||
'ExtendedServerAttributes not active in Nova.',
|
||||
HINT_KEYWORD)
|
||||
raise exception.CinderException(_('Hint "%s" not supported.') %
|
||||
HINT_KEYWORD)
|
||||
|
||||
server = nova.API().get_server(context, instance_uuid,
|
||||
privileged_user=True,
|
||||
timeout=REQUESTS_TIMEOUT)
|
||||
|
@ -1067,20 +1067,6 @@ class InstanceLocalityFilterTestCase(BackendFiltersTestCase):
|
||||
self.assertRaises(exception.InvalidUUID,
|
||||
filt_cls.backend_passes, host, filter_properties)
|
||||
|
||||
@mock.patch('cinder.compute.nova.novaclient')
|
||||
def test_nova_no_extended_server_attributes(self, _mock_novaclient):
|
||||
_mock_novaclient.return_value = fakes.FakeNovaClient(
|
||||
ext_srv_attr=False)
|
||||
filt_cls = self.class_map['InstanceLocalityFilter']()
|
||||
host = fakes.FakeBackendState('host1', {})
|
||||
uuid = nova.novaclient().servers.create('host1')
|
||||
|
||||
filter_properties = {'context': self.context,
|
||||
'scheduler_hints': {'local_to_instance': uuid},
|
||||
'request_spec': {'volume_id': fake.VOLUME_ID}}
|
||||
self.assertRaises(exception.CinderException,
|
||||
filt_cls.backend_passes, host, filter_properties)
|
||||
|
||||
@mock.patch('cinder.compute.nova.novaclient')
|
||||
def test_nova_down_does_not_alter_other_filters(self, _mock_novaclient):
|
||||
# Simulate Nova API is not available
|
||||
@ -1096,8 +1082,8 @@ class InstanceLocalityFilterTestCase(BackendFiltersTestCase):
|
||||
@mock.patch('cinder.compute.nova.novaclient')
|
||||
def test_nova_timeout(self, mock_novaclient):
|
||||
# Simulate a HTTP timeout
|
||||
mock_show_all = mock_novaclient.return_value.list_extensions.show_all
|
||||
mock_show_all.side_effect = request_exceptions.Timeout
|
||||
mock_get = mock_novaclient.return_value.servers.get
|
||||
mock_get.side_effect = request_exceptions.Timeout
|
||||
|
||||
filt_cls = self.class_map['InstanceLocalityFilter']()
|
||||
host = fakes.FakeBackendState('host1', {})
|
||||
|
Loading…
Reference in New Issue
Block a user