filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': '1 == 1',
}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {'volume_type': {}}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': '1 == 2',
}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {'volume_type': {}}
self.assertFalse(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': None,
}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {'volume_type': {}}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {'volume_type': {}}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': '1 == 1',
}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
- def test_volume_backend_name_different(self):
- filt_cls = self.class_map['DriverFilter']()
- host1 = fakes.FakeHostState(
- 'host1', {
- 'volume_backend_name': 'fake',
- 'capabilities': {
- 'filter_function': '1 == 1',
- }
- })
-
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake2',
- }
- }
- }
-
- self.assertFalse(filt_cls.host_passes(host1, filter_properties))
-
def test_function_extra_spec_replacement(self):
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': 'extra.var == 1',
}
filter_properties = {
'volume_type': {
'extra_specs': {
- 'volume_backend_name': 'fake',
'var': 1,
}
}
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'total_capacity_gb': 100,
'capabilities': {
'filter_function': 'stats.total_capacity_gb < 200',
}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {'volume_type': {}}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': 'volume.size < 5',
}
})
filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- },
'request_spec': {
'volume_properties': {
'size': 1
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': 'qos.var == 1',
}
})
filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- },
'qos_specs': {
'var': 1
}
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': '1 / 0 == 0',
}
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {}
self.assertFalse(filt_cls.host_passes(host1, filter_properties))
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'filter_function': 'qos.maxiops == 1',
}
})
filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- },
'qos_specs': None
}
filt_cls = self.class_map['DriverFilter']()
host1 = fakes.FakeHostState(
'host1', {
- 'volume_backend_name': 'fake',
'capabilities': {
'foo': 10,
'filter_function': 'capabilities.foo == 10',
},
})
- filter_properties = {
- 'volume_type': {
- 'extra_specs': {
- 'volume_backend_name': 'fake',
- }
- }
- }
+ filter_properties = {}
self.assertTrue(filt_cls.host_passes(host1, filter_properties))
+ def test_wrong_capabilities(self):
+ filt_cls = self.class_map['DriverFilter']()
+ host1 = fakes.FakeHostState(
+ 'host1', {
+ 'capabilities': {
+ 'bar': 10,
+ 'filter_function': 'capabilities.foo == 10',
+ },
+ })
+
+ filter_properties = {}
+
+ self.assertFalse(filt_cls.host_passes(host1, filter_properties))
+
class InstanceLocalityFilterTestCase(HostFiltersTestCase):
def setUp(self):