コード例 #1
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'])
コード例 #2
0
 def test_affinity_different_filter_passes(self):
     host = fakes.FakeHostState('host1', 'node1', {})
     inst1 = objects.Instance(uuid='different')
     host.instances = {inst1.uuid: inst1}
     filter_properties = {
         'context': mock.sentinel.ctx,
         'scheduler_hints': {
             'different_host': ['same'],
         }
     }
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #3
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'])
コード例 #4
0
 def _test_group_affinity_filter_passes(self, filt_cls, policy):
     host = fakes.FakeHostState('host1', 'node1', {})
     filter_properties = {}
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
     filter_properties = {'group_policies': ['anti-affinity']}
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
     filter_properties = {
         'group_policies': ['affinity'],
         'group_hosts': ['host1']
     }
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
コード例 #5
0
 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_aggregate_image_properties_isolation_props_namespace(self,
         agg_mock):
     self.flags(aggregate_image_properties_isolation_namespace="np")
     agg_mock.return_value = {'np.foo': 'bar', 'foo2': 'bar2'}
     filter_properties = {'context': mock.sentinel.ctx,
                          'request_spec': {
                              'image': {
                                  'properties': {'np.foo': 'bar',
                                                 'foo2': 'bar3'}}}}
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #7
0
 def test_image_properties_filter_baremetal_vmmode_compat(self):
     # if an old image has 'baremetal' for vmmode it should be
     # treated as hvm
     img_props = {'properties': {'vm_mode': 'baremetal'}}
     filter_properties = {'request_spec': {'image': img_props}}
     hypervisor_version = utils.convert_version_to_int('6.0.0')
     capabilities = {'supported_instances':
                     [(arch.I686, hv_type.BAREMETAL, vm_mode.HVM)],
                     'hypervisor_version': hypervisor_version}
     host = fakes.FakeHostState('host1', 'node1', capabilities)
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #8
0
 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))
コード例 #9
0
 def test_aggregate_multi_tenancy_isolation_no_meta_passes(self, agg_mock):
     agg_mock.return_value = {}
     filter_properties = {
         'context': mock.sentinel.ctx,
         'request_spec': {
             'instance_properties': {
                 'project_id': 'my_tenantid'
             }
         }
     }
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #10
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))
コード例 #11
0
 def test_json_filter_fails_on_service_disabled(self):
     json_query = jsonutils.dumps(
             ['and', ['>=', '$free_ram_mb', 1024],
                     ['>=', '$free_disk_mb', 200 * 1024],
                     ['not', '$service.disabled']])
     filter_properties = {'instance_type': {'memory_mb': 1024,
                                            'local_gb': 200},
                        'scheduler_hints': {'query': json_query}}
     host = fakes.FakeHostState('host1', 'node1',
             {'free_ram_mb': 1024,
              'free_disk_mb': 200 * 1024})
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
コード例 #12
0
 def test_pci_passthrough_no_pci_stats(self):
     request = objects.InstancePCIRequest(count=1,
                                          spec=[{
                                              'vendor_id': '8086'
                                          }])
     requests = objects.InstancePCIRequests(requests=[request])
     filter_properties = {'pci_requests': requests}
     host = fakes.FakeHostState(
         'host1',
         'node1',
         attribute_dict={'pci_stats': stats.PciDeviceStats()})
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
コード例 #13
0
 def test_numa_topology_filter_numa_host_no_numa_instance_pass(self):
     instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
     instance.numa_topology = None
     filter_properties = {
         'request_spec': {
             'instance_properties':
             jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
         }
     }
     host = fakes.FakeHostState('host1', 'node1',
                                {'numa_topology': fakes.NUMA_TOPOLOGY})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #14
0
    def test_affinity_simple_cidr_filter_handles_none(self):
        host = fakes.FakeHostState('host1', 'node1', {})

        affinity_ip = CONF.my_ip.split('.')[0:3]
        affinity_ip.append('100')
        affinity_ip = str.join('.', affinity_ip)

        filter_properties = {
            'context': mock.sentinel.ctx,
            'scheduler_hints': None
        }

        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #15
0
 def test_filter_aggregate_num_instances_value(self, agg_mock):
     self.flags(max_instances_per_host=4)
     self.filt_cls = num_instances_filter.AggregateNumInstancesFilter()
     host = fakes.FakeHostState('host1', 'node1',
                                {'num_instances': 5})
     filter_properties = {'context': mock.sentinel.ctx}
     agg_mock.return_value = set([])
     # No aggregate defined for that host.
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
     agg_mock.assert_called_once_with(host, 'max_instances_per_host')
     agg_mock.return_value = set(['6'])
     # Aggregate defined for that host.
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #16
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 = 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.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #17
0
 def test_aggregate_ram_filter_default_value(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})
     # False: fallback to default flag w/o aggregates
     agg_mock.return_value = set()
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
     agg_mock.return_value = set(['2.0'])
     # True: use ratio from aggregates
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
     self.assertEqual(1024 * 2.0, host.limits['memory_mb'])
コード例 #18
0
    def _get_all_hosts(self):
        def fake_metric(value):
            return host_manager.MetricItem(value=value,
                                           timestamp='fake-time',
                                           source='fake-source')

        host_values = [
            ('host1', 'node1', {
                'metrics': {
                    'foo': fake_metric(512),
                    'bar': fake_metric(1)
                }
            }),
            ('host2', 'node2', {
                'metrics': {
                    'foo': fake_metric(1024),
                    'bar': fake_metric(2)
                }
            }),
            ('host3', 'node3', {
                'metrics': {
                    'foo': fake_metric(3072),
                    'bar': fake_metric(1)
                }
            }),
            ('host4', 'node4', {
                'metrics': {
                    'foo': fake_metric(8192),
                    'bar': fake_metric(0)
                }
            }),
            ('host5', 'node5', {
                'metrics': {
                    'foo': fake_metric(768),
                    'bar': fake_metric(0),
                    'zot': fake_metric(1)
                }
            }),
            ('host6', 'node6', {
                'metrics': {
                    'foo': fake_metric(2048),
                    'bar': fake_metric(0),
                    'zot': fake_metric(2)
                }
            }),
        ]
        return [
            fakes.FakeHostState(host, node, values)
            for host, node, values in host_values
        ]
コード例 #19
0
 def test_aggregate_multi_tenancy_isolation_fails_comma(self, agg_mock):
     agg_mock.return_value = {
         'filter_tenant_id': set(['other_tenantid', 'other_tenantid2'])
     }
     filter_properties = {
         'context': mock.sentinel.ctx,
         'request_spec': {
             'instance_properties': {
                 'project_id': 'my_tenantid'
             }
         }
     }
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
コード例 #20
0
 def test_pci_passthrough_fail(self):
     pci_stats_mock = mock.MagicMock()
     pci_stats_mock.support_requests.return_value = False
     request = objects.InstancePCIRequest(count=1,
                                          spec=[{
                                              'vendor_id': '8086'
                                          }])
     requests = objects.InstancePCIRequests(requests=[request])
     filter_properties = {'pci_requests': requests}
     host = fakes.FakeHostState(
         'host1', 'node1', attribute_dict={'pci_stats': pci_stats_mock})
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
     pci_stats_mock.support_requests.assert_called_once_with(
         requests.requests)
コード例 #21
0
ファイル: test_weights_ram.py プロジェクト: 2Exception/patron
 def _get_all_hosts(self):
     host_values = [('host1', 'node1', {
         'free_ram_mb': 512
     }), ('host2', 'node2', {
         'free_ram_mb': 1024
     }), ('host3', 'node3', {
         'free_ram_mb': 3072
     }), ('host4', 'node4', {
         'free_ram_mb': 8192
     })]
     return [
         fakes.FakeHostState(host, node, values)
         for host, node, values in host_values
     ]
コード例 #22
0
 def test_disk_filter_fails(self):
     self.flags(disk_allocation_ratio=1.0)
     filt_cls = disk_filter.DiskFilter()
     filter_properties = {
         'instance_type': {
             'root_gb': 10,
             'ephemeral_gb': 1,
             'swap': 1024
         }
     }
     host = fakes.FakeHostState('host1', 'node1', {
         'free_disk_mb': 11 * 1024,
         'total_usable_disk_gb': 13
     })
     self.assertFalse(filt_cls.host_passes(host, filter_properties))
コード例 #23
0
    def test_affinity_simple_cidr_filter_fails(self):
        host = fakes.FakeHostState('host1', 'node1', {})
        host.host_ip = '10.8.1.1'

        affinity_ip = "10.8.1.100"

        filter_properties = {
            'context': mock.sentinel.ctx,
            'scheduler_hints': {
                'cidr': '/32',
                'build_near_host_ip': affinity_ip
            }
        }

        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
コード例 #24
0
 def test_aggregate_core_filter_default_value(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': 8})
     agg_mock.return_value = set([])
     # False: fallback to default flag w/o aggregates
     self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
     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, filter_properties))
     self.assertEqual(4 * 3, host.limits['vcpu'])
コード例 #25
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))
コード例 #26
0
 def test_disk_filter_oversubscribe_fail(self):
     self.flags(disk_allocation_ratio=10.0)
     filt_cls = disk_filter.DiskFilter()
     filter_properties = {
         'instance_type': {
             'root_gb': 100,
             'ephemeral_gb': 19,
             'swap': 1024
         }
     }
     # 1GB used... so 119GB allowed...
     host = fakes.FakeHostState('host1', 'node1', {
         'free_disk_mb': 11 * 1024,
         'total_usable_disk_gb': 12
     })
     self.assertFalse(filt_cls.host_passes(host, filter_properties))
コード例 #27
0
 def test_aggregate_disk_filter_value_error(self, agg_mock):
     filt_cls = disk_filter.AggregateDiskFilter()
     self.flags(disk_allocation_ratio=1.0)
     filter_properties = {
         'context': mock.sentinel.ctx,
         'instance_type': {
             'root_gb': 1,
             'ephemeral_gb': 1,
             'swap': 1024
         }
     }
     host = fakes.FakeHostState('host1', 'node1', {
         'free_disk_mb': 3 * 1024,
         'total_usable_disk_gb': 1
     })
     agg_mock.return_value = set(['XXX'])
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
     agg_mock.assert_called_once_with(host, 'disk_allocation_ratio')
コード例 #28
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))
コード例 #29
0
    def test_json_filter_unknown_variable_ignored(self):
        host = fakes.FakeHostState('host1', 'node1',
                {})

        raw = ['=', '$........', 1, 1]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))

        raw = ['=', '$foo', 2, 2]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
コード例 #30
0
    def test_json_filter_invalid_num_arguments_fails(self):
        host = fakes.FakeHostState('host1', 'node1',
                {})

        raw = ['>', ['and', ['or', ['not', ['<', ['>=', ['<=', ['in', ]]]]]]]]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))

        raw = ['>', 1]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))