def test_type_filter(self): self._stub_service_is_up(True) filt_cls = self.class_map['TypeAffinityFilter']() filter_properties = {'context': self.context, 'instance_type': {'id': 1}} filter2_properties = {'context': self.context, 'instance_type': {'id': 2}} capabilities = {'enabled': True} service = {'disabled': False} host = fakes.FakeHostState('fake_host', 'compute', {'capabilities': capabilities, 'service': service}) #True since empty self.assertTrue(filt_cls.host_passes(host, filter_properties)) fakes.FakeInstance(context=self.context, params={'host': 'fake_host', 'instance_type_id': 1}) #True since same type self.assertTrue(filt_cls.host_passes(host, filter_properties)) #False since different type self.assertFalse(filt_cls.host_passes(host, filter2_properties)) #False since node not homogeneous fakes.FakeInstance(context=self.context, params={'host': 'fake_host', 'instance_type_id': 2}) self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_affinity_same_filter_handles_none(self): filt_cls = self.class_map['SameHostFilter']() host = fakes.FakeHostState('host1', 'compute', {}) instance = fakes.FakeInstance(context=self.context, params={'host': 'host2'}) instance_uuid = instance.uuid filter_properties = {'context': self.context.elevated(), 'scheduler_hints': None} self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_affinity_different_filter_fails(self): filt_cls = self.class_map['DifferentHostFilter']() host = fakes.FakeHostState('host1', 'compute', {}) instance = fakes.FakeInstance(context=self.context, params={'host': 'host1'}) instance_uuid = instance.uuid filter_properties = {'context': self.context.elevated(), 'scheduler_hints': { 'different_host': [instance_uuid], }} self.assertFalse(filt_cls.host_passes(host, filter_properties))
def test_affinity_same_filter_passes(self): filt_cls = filters.SameHostFilter() host = fakes.FakeHostState('host1', 'compute', {}) instance = fakes.FakeInstance(context=self.context, params={'host': 'host1'}) instance_uuid = instance.uuid filter_properties = { 'context': self.context.elevated(), 'scheduler_hints': { 'same_host': [instance_uuid], } } self.assertTrue(filt_cls.host_passes(host, filter_properties))