def test_schedule_local_zone(self): """Test to make sure _schedule makes no call out to zones if local_zone in the request spec is True.""" self.next_weight = 1.0 def _fake_weighted_sum(functions, hosts, options): self.next_weight += 2.0 host, hostinfo = hosts[0] return least_cost.WeightedHost(self.next_weight, host=host, hostinfo=hostinfo) sched = ds_fakes.FakeDistributedScheduler() fake_context = context.RequestContext('user', 'project') sched.zone_manager = ds_fakes.FakeZoneManager() self.stubs.Set(sched, '_filter_hosts', fake_filter_hosts) self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum) self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all) self.stubs.Set(sched, '_call_zone_method', fake_call_zone_method) instance_type = dict(memory_mb=512, local_gb=512) request_spec = dict(num_instances=10, instance_type=instance_type, local_zone=True) weighted_hosts = sched._schedule(fake_context, 'compute', request_spec) self.assertEquals(len(weighted_hosts), 10) for weighted_host in weighted_hosts: # There should be no remote hosts self.assertTrue(weighted_host.host is not None) self.assertTrue(weighted_host.zone is None)
def test_schedule_happy_day(self): """Make sure there's nothing glaringly wrong with _schedule() by doing a happy day pass through.""" self.next_weight = 1.0 def _fake_weighted_sum(functions, hosts, options): self.next_weight += 2.0 host, hostinfo = hosts[0] return least_cost.WeightedHost(self.next_weight, host=host, hostinfo=hostinfo) sched = ds_fakes.FakeDistributedScheduler() fake_context = context.RequestContext('user', 'project') sched.zone_manager = ds_fakes.FakeZoneManager() self.stubs.Set(sched, '_filter_hosts', fake_filter_hosts) self.stubs.Set(least_cost, 'weighted_sum', _fake_weighted_sum) self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all) self.stubs.Set(sched, '_call_zone_method', fake_call_zone_method) instance_type = dict(memory_mb=512, local_gb=512) request_spec = dict(num_instances=10, instance_type=instance_type) weighted_hosts = sched._schedule(fake_context, 'compute', request_spec) self.assertEquals(len(weighted_hosts), 10) for weighted_host in weighted_hosts: # We set this up so remote hosts have even weights ... if int(weighted_host.weight) % 2 == 0: self.assertTrue(weighted_host.zone is not None) self.assertTrue(weighted_host.host is None) else: self.assertTrue(weighted_host.host is not None) self.assertTrue(weighted_host.zone is None)
def setUp(self): super(HostFilterTestCase, self).setUp() default_host_filters = ['AllHostsFilter'] self.flags(default_host_filters=default_host_filters, reserved_host_disk_mb=0, reserved_host_memory_mb=0) self.instance_type = dict(name='tiny', memory_mb=30, vcpus=10, local_gb=300, flavorid=1, swap=500, rxtx_quota=30000, rxtx_cap=200, extra_specs={}) self.gpu_instance_type = dict(name='tiny.gpu', memory_mb=30, vcpus=10, local_gb=300, flavorid=2, swap=500, rxtx_quota=30000, rxtx_cap=200, extra_specs={ 'xpu_arch': 'fermi', 'xpu_info': 'Tesla 2050' }) self.zone_manager = ds_fakes.FakeZoneManager() states = {} for x in xrange(4): states['host%d' % (x + 1)] = {'compute': self._host_caps(x)} self.zone_manager.service_states = states # Add some extra capabilities to some hosts host4 = self.zone_manager.service_states['host4']['compute'] host4['xpu_arch'] = 'fermi' host4['xpu_info'] = 'Tesla 2050' host2 = self.zone_manager.service_states['host2']['compute'] host2['xpu_arch'] = 'radeon' host3 = self.zone_manager.service_states['host3']['compute'] host3['xpu_arch'] = 'fermi' host3['xpu_info'] = 'Tesla 2150'
def setUp(self): super(LeastCostTestCase, self).setUp() self.flags(reserved_host_disk_mb=0, reserved_host_memory_mb=0) self.zone_manager = fake_zone_manager.FakeZoneManager()