Esempio n. 1
0
 def _do_test_compute_filter_extra_specs(self, ecaps, especs, passes):
     # In real OpenStack runtime environment,compute capabilities
     # value may be number, so we should use number to do unit test.
     capabilities = {}
     capabilities.update(ecaps)
     filter_properties = {
         'instance_type': {
             'memory_mb': 1024,
             'extra_specs': especs
         }
     }
     host_state = {'free_ram_mb': 1024}
     host_state.update(capabilities)
     host = fakes.FakeHostState('host1', 'node1', host_state)
     assertion = self.assertTrue if passes else self.assertFalse
     assertion(self.filt_cls.host_passes(host, filter_properties))
Esempio n. 2
0
 def test_aggregate_ram_filter_value_error(self, agg_mock):
     filter_properties = {
         'context': mock.sentinel.ctx,
         'instance_type': {
             'memory_mb': 1024
         }
     }
     host = fakes.FakeHostState(
         'host1', 'node1', {
             'free_ram_mb': 1024,
             'total_usable_ram_mb': 1024,
             'ram_allocation_ratio': 1.0
         })
     agg_mock.return_value = set(['XXX'])
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
     self.assertEqual(1024 * 1.0, host.limits['memory_mb'])
 def test_numa_topology_filter_fail_cpu(self):
     instance_topology = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
         objects.InstanceNUMACell(id=1, cpuset=set([3, 4, 5]), memory=512)
     ])
     spec_obj = objects.RequestSpec(numa_topology=instance_topology,
                                    pci_requests=None,
                                    instance_uuid=str(uuid.uuid4()))
     host = fakes.FakeHostState(
         'host1', 'node1', {
             'numa_topology': fakes.NUMA_TOPOLOGY,
             'pci_stats': None,
             'cpu_allocation_ratio': 1,
             'ram_allocation_ratio': 1.5
         })
     self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 4
0
 def _do_test_isolated_hosts(
         self,
         host_in_list,
         image_in_list,
         set_flags=True,
         restrict_isolated_hosts_to_isolated_images=True):
     if set_flags:
         self.flags(isolated_images=['isolated_image'],
                    isolated_hosts=['isolated_host'],
                    restrict_isolated_hosts_to_isolated_images=
                    restrict_isolated_hosts_to_isolated_images)
     host_name = 'isolated_host' if host_in_list else 'free_host'
     image_ref = 'isolated_image' if image_in_list else 'free_image'
     spec_obj = objects.RequestSpec(image=objects.ImageMeta(id=image_ref))
     host = fakes.FakeHostState(host_name, 'node', {})
     return self.filt_cls.host_passes(host, spec_obj)
Esempio n. 5
0
    def test_numa_topology_filter_numa_instance_no_numa_host_fail(self):
        instance_topology = objects.InstanceNUMATopology(cells=[
            objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
            objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = instance_topology

        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {'pci_stats': None})
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_fails_different_inst_props(self):
     img_props = {
         'properties': {
             'architecture': arch.ARMV7,
             'hypervisor_type': hv_type.QEMU,
             'vm_mode': vm_mode.HVM
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_passes_without_hyper_version(self):
     img_props = {
         'properties': {
             'architecture': arch.X86_64,
             'hypervisor_type': hv_type.KVM,
             'vm_mode': vm_mode.HVM,
             'hypervisor_version_requires': '>=6.0'
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     capabilities = {
         'enabled': True,
         'supported_instances': [(arch.X86_64, hv_type.KVM, vm_mode.HVM)]
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
 def test_image_properties_filter_fails_without_host_props(self):
     img_props = {
         'properties': {
             'architecture': arch.X86_64,
             'hypervisor_type': hv_type.KVM,
             'vm_mode': vm_mode.HVM
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {
         'enabled': True,
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Esempio n. 9
0
 def test_aggregate_image_properties_isolation_props_namespace(
         self, agg_mock):
     self.flags(aggregate_image_properties_isolation_namespace='hw',
                group='filter_scheduler')
     self.flags(aggregate_image_properties_isolation_separator='_',
                group='filter_scheduler')
     agg_mock.return_value = {
         'hw_vm_mode': set(['hvm']),
         'img_owner_id': set(['foo'])
     }
     spec_obj = objects.RequestSpec(
         context=mock.sentinel.ctx,
         image=objects.ImageMeta(properties=objects.ImageMetaProps(
             hw_vm_mode='hvm', img_owner_id='wrong')))
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
 def test_image_properties_filter_passes_without_hyper_version(self):
     img_props = objects.ImageMeta(
         properties=objects.ImageMetaProps(
             hw_architecture=obj_fields.Architecture.X86_64,
             img_hv_type=obj_fields.HVType.KVM,
             hw_vm_mode=obj_fields.VMMode.HVM,
             img_hv_requested_version='>=6.0'))
     spec_obj = objects.RequestSpec(image=img_props)
     capabilities = {
         'enabled': True,
         'supported_instances': [(
             obj_fields.Architecture.X86_64,
             obj_fields.HVType.KVM,
             obj_fields.VMMode.HVM)]}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 11
0
 def test_image_properties_filter_passes_same_inst_props_and_version(self):
     img_props = objects.ImageMeta(properties=objects.ImageMetaProps(
         hw_architecture=obj_fields.Architecture.X86_64,
         img_hv_type=hv_type.KVM,
         hw_vm_mode=vm_mode.HVM,
         img_hv_requested_version='>=6.0,<6.2'))
     spec_obj = objects.RequestSpec(image=img_props)
     hypervisor_version = versionutils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances':
         [(obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)],
         'hypervisor_version':
         hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 12
0
 def test_trusted_filter_untrusted_and_untrusted_passes(self, req_mock):
     oat_data = {
         "hosts": [{
             "host_name": "node1",
             "trust_lvl": "untrusted",
             "vtime": utils.isotime()
         }]
     }
     req_mock.return_value = requests.codes.OK, oat_data
     extra_specs = {'trust:trusted_host': 'untrusted'}
     spec_obj = objects.RequestSpec(context=mock.sentinel.ctx,
                                    flavor=objects.Flavor(
                                        memory_mb=1024,
                                        extra_specs=extra_specs))
     host = fakes.FakeHostState('host1', 'node1', {})
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 13
0
 def test_aggregate_ram_filter_conflict_values(self, agg_mock):
     self.flags(ram_allocation_ratio=1.0)
     filter_properties = {
         'context': mock.sentinel.ctx,
         'instance_type': {
             'memory_mb': 1024
         }
     }
     host = fakes.FakeHostState('host1', 'node1', {
         'free_ram_mb': 1023,
         'total_usable_ram_mb': 1024
     })
     agg_mock.return_value = set(['1.5', '2.0'])
     # use the minimum ratio from aggregates
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
     self.assertEqual(1024 * 1.5, host.limits['memory_mb'])
Esempio n. 14
0
 def test_json_filter_fails_on_disk(self):
     filter_properties = {
         'instance_type': {
             'memory_mb': 1024,
             'root_gb': 200,
             'ephemeral_gb': 0
         },
         'scheduler_hints': {
             'query': self.json_query
         }
     }
     host = fakes.FakeHostState('host1', 'node1', {
         'free_ram_mb': 1024,
         'free_disk_mb': (200 * 1024) - 1
     })
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
 def test_numa_topology_filter_fail_mempages(self):
     instance_topology = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(
             id=0, cpuset=set([3]), memory=128, pagesize=8),
         objects.InstanceNUMACell(
             id=1, cpuset=set([1]), memory=128, pagesize=16)
     ])
     spec_obj = self._get_spec_obj(numa_topology=instance_topology)
     host = fakes.FakeHostState(
         'host1', 'node1', {
             'numa_topology': fakes.NUMA_TOPOLOGY,
             'pci_stats': None,
             'cpu_allocation_ratio': 16.0,
             'ram_allocation_ratio': 1.5
         })
     self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 16
0
    def test_aggregate_type_filter_no_metadata(self, agg_mock):
        self.filt_cls = type_filter.AggregateTypeAffinityFilter()

        filter_properties = {
            'context': mock.sentinel.ctx,
            'instance_type': {
                'name': 'fake1'
            }
        }
        host = fakes.FakeHostState('fake_host', 'fake_node', {})

        # tests when no instance_type is defined for aggregate
        agg_mock.return_value = set([])
        # True as no instance_type set for aggregate
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
        agg_mock.assert_called_once_with(host, 'instance_type')
 def test_aggregate_image_properties_isolation_multi_props_passes(
         self, agg_mock):
     agg_mock.return_value = {'foo': 'bar', 'foo2': 'bar2'}
     filter_properties = {
         'context': mock.sentinel.ctx,
         'request_spec': {
             'image': {
                 'properties': {
                     'foo': 'bar',
                     'foo2': 'bar2'
                 }
             }
         }
     }
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Esempio n. 18
0
    def _do_test_numa_topology_filter_cpu_policy(
            self, numa_topology, cpu_policy, cpu_thread_policy, passes,
            mock_pinning_requested):
        instance_topology = objects.InstanceNUMATopology(
            cells=[objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
                   objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512)
               ])
        spec_obj = objects.RequestSpec(numa_topology=instance_topology,
                                       pci_requests=None,
                                       instance_uuid=uuids.fake)

        extra_specs = [
            {},
            {
                'hw:cpu_policy': cpu_policy,
                'hw:cpu_thread_policy': cpu_thread_policy,
            }
        ]
        image_props = [
            {},
            {
                'hw_cpu_policy': cpu_policy,
                'hw_cpu_thread_policy': cpu_thread_policy,
            }
        ]
        host = fakes.FakeHostState('host1', 'node1', {
            'numa_topology': numa_topology,
            'pci_stats': None,
            'cpu_allocation_ratio': 1,
            'ram_allocation_ratio': 1.5})
        assertion = self.assertTrue if passes else self.assertFalse

        # test combinations of image properties and extra specs
        for specs, props in itertools.product(extra_specs, image_props):
            # ...except for the one where no policy is specified
            if specs == props == {}:
                continue

            fake_flavor = objects.Flavor(memory_mb=1024, extra_specs=specs)
            fake_image_props = objects.ImageMetaProps(**props)
            fake_image = objects.ImageMeta(properties=fake_image_props)

            spec_obj.image = fake_image
            spec_obj.flavor = fake_flavor

            assertion(self.filt_cls.host_passes(host, spec_obj))
            self.assertIsNone(spec_obj.numa_topology.cells[0].cpu_pinning)
Esempio n. 19
0
 def test_numa_topology_filter_pass_set_limit(self):
     instance_topology = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
         objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512)
     ])
     spec_obj = self._get_spec_obj(numa_topology=instance_topology)
     host = fakes.FakeHostState(
         'host1', 'node1', {
             'numa_topology': fakes.NUMA_TOPOLOGY,
             'pci_stats': None,
             'cpu_allocation_ratio': 21,
             'ram_allocation_ratio': 1.3
         })
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
     limits = host.limits['numa_topology']
     self.assertEqual(limits.cpu_allocation_ratio, 21)
     self.assertEqual(limits.ram_allocation_ratio, 1.3)
Esempio n. 20
0
    def test_json_filter_empty_filters_pass(self):
        host = fakes.FakeHostState('host1', 'node1', {})

        raw = []
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
        raw = {}
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Esempio n. 21
0
    def test_affinity_different_filter_fails(self, get_all_mock):
        host = fakes.FakeHostState('host1', 'node1', {})
        get_all_mock.return_value = [mock.sentinel.instances]

        filter_properties = {
            'context': mock.sentinel.ctx,
            'scheduler_hints': {
                'different_host': ['fake'],
            }
        }

        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
        get_all_mock.assert_called_once_with(mock.sentinel.ctx, {
            'host': 'host1',
            'uuid': ['fake'],
            'deleted': False
        })
Esempio n. 22
0
 def test_metrics_filter_pass(self):
     _ts_now = datetime.datetime(2015, 11, 11, 11, 0, 0)
     obj1 = objects.MonitorMetric(name='cpu.frequency',
                                  value=1000,
                                  timestamp=_ts_now,
                                  source='nova.virt.libvirt.driver')
     obj2 = objects.MonitorMetric(name='numa.membw.current',
                                  numa_membw_values={"0": 10, "1": 43},
                                  timestamp=_ts_now,
                                  source='nova.virt.libvirt.driver')
     metrics_list = objects.MonitorMetricList(objects=[obj1, obj2])
     self.flags(weight_setting=[
         'cpu.frequency=1', 'numa.membw.current=2'], group='metrics')
     filt_cls = metrics_filter.MetricsFilter()
     host = fakes.FakeHostState('host1', 'node1',
                                attribute_dict={'metrics': metrics_list})
     self.assertTrue(filt_cls.host_passes(host, None))
Esempio n. 23
0
    def test_agg_network_provider_filter_passes(self, agg_mock):
        agg_mock.return_value = {'provider:physical_network': ['physnet0', ]}
        host = fakes.FakeHostState('host1', 'node1', {})

        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet0', ]})
        self.assertTrue(self.filt_cls.host_passes(host, spec_obj))

        agg_mock.return_value = {'provider:physical_network':
                                     ['physnet0_again', ]}
        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet0', ]})
        self.assertFalse(self.filt_cls.host_passes(host, spec_obj))

        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet0_again', ]})
        self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
 def test_aggregate_core_filter_default_value(self, agg_mock):
     self.filt_cls = core_filter.AggregateCoreFilter()
     spec_obj = objects.RequestSpec(context=mock.sentinel.ctx,
                                    flavor=objects.Flavor(vcpus=1))
     host = fakes.FakeHostState('host1', 'node1', {
         'vcpus_total': 4,
         'vcpus_used': 8,
         'cpu_allocation_ratio': 2
     })
     agg_mock.return_value = set([])
     # False: fallback to default flag w/o aggregates
     self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
     agg_mock.assert_called_once_with(host, 'cpu_allocation_ratio')
     # True: use ratio from aggregates
     agg_mock.return_value = set(['3'])
     self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
     self.assertEqual(4 * 3, host.limits['vcpu'])
Esempio n. 25
0
 def test_aggregate_core_filter_conflict_values(self, agg_mock):
     self.filt_cls = core_filter.AggregateCoreFilter()
     filter_properties = {
         'context': mock.sentinel.ctx,
         'instance_type': {
             'vcpus': 1
         }
     }
     self.flags(cpu_allocation_ratio=1)
     host = fakes.FakeHostState('host1', 'node1', {
         'vcpus_total': 4,
         'vcpus_used': 8
     })
     agg_mock.return_value = set(['2', '3'])
     # use the minimum ratio from aggregates
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
     self.assertEqual(4 * 2, host.limits['vcpu'])
Esempio n. 26
0
 def test_aggregate_core_filter_value_error(self, agg_mock):
     self.filt_cls = core_filter.AggregateCoreFilter()
     filter_properties = {
         'context': mock.sentinel.ctx,
         'instance_type': {
             'vcpus': 1
         }
     }
     self.flags(cpu_allocation_ratio=2)
     host = fakes.FakeHostState('host1', 'node1', {
         'vcpus_total': 4,
         'vcpus_used': 7
     })
     agg_mock.return_value = set(['XXX'])
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
     agg_mock.assert_called_once_with(host, 'cpu_allocation_ratio')
     self.assertEqual(4 * 2, host.limits['vcpu'])
 def _do_test_isolated_hosts(self, host_in_list, image_in_list,
                         set_flags=True,
                         restrict_isolated_hosts_to_isolated_images=True):
     if set_flags:
         self.flags(isolated_images=['isolated_image'],
                    isolated_hosts=['isolated_host'],
                    restrict_isolated_hosts_to_isolated_images=
                    restrict_isolated_hosts_to_isolated_images)
     host_name = 'isolated_host' if host_in_list else 'free_host'
     image_ref = 'isolated_image' if image_in_list else 'free_image'
     filter_properties = {
         'request_spec': {
             'instance_properties': {'image_ref': image_ref}
         }
     }
     host = fakes.FakeHostState(host_name, 'node', {})
     return self.filt_cls.host_passes(host, filter_properties)
Esempio n. 28
0
    def test_agg_network_provider_filter_fails_if_mismatched(self, agg_mock):
        agg_mock.return_value = {'provider:physical_network': ['physnet22', ]}
        host = fakes.FakeHostState('host1', 'node1', {})

        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet0', ]})
        self.assertFalse(self.filt_cls.host_passes(host, spec_obj))

        # Almost matches (too short)
        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet2', ]})
        self.assertFalse(self.filt_cls.host_passes(host, spec_obj))

        # Almost matches (too long)
        spec_obj = objects.RequestSpec(self.ctxt, scheduler_hints =
                           {'provider:physical_network': ['physnet222', ]})
        self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
Esempio n. 29
0
 def test_image_properties_filter_passes_same_inst_props_and_version(self):
     img_props = {
         'properties': {
             '_architecture': arch.X86_64,
             'hypervisor_type': hv_type.KVM,
             'vm_mode': vm_mode.HVM,
             'hypervisor_version_requires': '>=6.0,<6.2'
         }
     }
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = versionutils.convert_version_to_int('6.0.0')
     capabilities = {
         'supported_instances': [(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
         'hypervisor_version': hypervisor_version
     }
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
    def test_numa_topology_filter_numa_instance_no_numa_host_fail(self):
        instance_topology = hardware.VirtNUMAInstanceTopology(cells=[
            hardware.VirtNUMATopologyCellInstance(0, set([1]), 512),
            hardware.VirtNUMATopologyCellInstance(1, set([3]), 512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = (
            objects.InstanceNUMATopology.obj_from_topology(instance_topology))

        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {})
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))