50
51
'ephemeral_gb': 0},
51
52
'instance_properties': {'project_id': 1}}
52
53
self.assertRaises(exception.NoValidHost, sched.schedule_run_instance,
53
fake_context, request_spec, None)
54
fake_context, request_spec, None, None, None,
55
57
def test_run_instance_non_admin(self):
56
58
"""Test creating an instance locally using run_instance, passing
71
73
request_spec = {'instance_type': {'memory_mb': 1, 'local_gb': 1},
72
74
'instance_properties': {'project_id': 1}}
73
75
self.assertRaises(exception.NoValidHost, sched.schedule_run_instance,
74
fake_context, request_spec, None)
76
fake_context, request_spec, None, None, None,
75
78
self.assertTrue(self.was_admin)
77
80
def test_schedule_bad_topic(self):
111
114
self.mox.StubOutWithMock(self.driver, '_provision_resource')
113
116
self.driver._schedule(context_fake, 'compute',
114
request_spec, **fake_kwargs
115
118
).AndReturn(['host1', 'host2'])
117
120
self.driver._provision_resource(
119
122
mox.Func(_has_launch_index(0)), None,
120
fake_kwargs).AndReturn(instance1)
123
{}, None, None, None, None).AndReturn(instance1)
122
125
self.driver._provision_resource(
124
127
mox.Func(_has_launch_index(1)), None,
125
fake_kwargs).AndReturn(instance2)
128
{}, None, None, None, None).AndReturn(instance2)
126
129
self.mox.ReplayAll()
128
self.driver.schedule_run_instance(context_fake, request_spec, None,
131
self.driver.schedule_run_instance(context_fake, request_spec,
132
None, None, None, None, {}, None)
131
134
def test_schedule_happy_day(self):
132
135
"""Make sure there's nothing glaringly wrong with _schedule()
161
164
self.mox.ReplayAll()
162
165
weighted_hosts = sched._schedule(fake_context, 'compute',
164
167
self.assertEquals(len(weighted_hosts), 10)
165
168
for weighted_host in weighted_hosts:
166
169
self.assertTrue(weighted_host.host_state is not None)
171
def test_schedule_prep_resize_doesnt_update_host(self):
172
fake_context = context.RequestContext('user', 'project',
175
sched = fakes.FakeFilterScheduler()
177
def _return_hosts(*args, **kwargs):
178
host_state = host_manager.HostState('host2', 'compute')
179
return [least_cost.WeightedHost(1.0, host_state=host_state)]
181
self.stubs.Set(sched, '_schedule', _return_hosts)
185
def _fake_instance_update_db(*args, **kwargs):
186
# This should not be called
189
self.stubs.Set(driver, 'instance_update_db',
190
_fake_instance_update_db)
192
instance = {'uuid': 'fake-uuid', 'host': 'host1'}
194
sched.schedule_prep_resize(fake_context, {}, {}, {}, instance, {})
195
self.assertEqual(info['called'], 0)
168
197
def test_get_cost_functions(self):
169
198
self.flags(reserved_host_memory_mb=128)
170
199
fixture = fakes.FakeFilterScheduler()
176
205
hostinfo.update_from_compute_node(dict(memory_mb=1000,
177
206
local_gb=0, vcpus=1))
178
207
self.assertEquals(1000 - 128, fn(hostinfo, {}))
209
def test_max_attempts(self):
210
self.flags(scheduler_max_attempts=4)
212
sched = fakes.FakeFilterScheduler()
213
self.assertEqual(4, sched._max_attempts())
215
def test_invalid_max_attempts(self):
216
self.flags(scheduler_max_attempts=0)
218
sched = fakes.FakeFilterScheduler()
219
self.assertRaises(exception.NovaException, sched._max_attempts)
221
def test_retry_disabled(self):
222
"""Retry info should not get populated when re-scheduling is off"""
223
self.flags(scheduler_max_attempts=1)
224
sched = fakes.FakeFilterScheduler()
226
instance_properties = {}
227
request_spec = dict(instance_properties=instance_properties)
228
filter_properties = {}
230
sched._schedule(self.context, 'compute', request_spec,
231
filter_properties=filter_properties)
233
# should not have retry info in the populated filter properties:
234
self.assertFalse("retry" in filter_properties)
236
def test_retry_attempt_one(self):
237
"""Test retry logic on initial scheduling attempt"""
238
self.flags(scheduler_max_attempts=2)
239
sched = fakes.FakeFilterScheduler()
241
instance_properties = {}
242
request_spec = dict(instance_properties=instance_properties)
243
filter_properties = {}
245
sched._schedule(self.context, 'compute', request_spec,
246
filter_properties=filter_properties)
248
num_attempts = filter_properties['retry']['num_attempts']
249
self.assertEqual(1, num_attempts)
251
def test_retry_attempt_two(self):
252
"""Test retry logic when re-scheduling"""
253
self.flags(scheduler_max_attempts=2)
254
sched = fakes.FakeFilterScheduler()
256
instance_properties = {}
257
request_spec = dict(instance_properties=instance_properties)
259
retry = dict(num_attempts=1)
260
filter_properties = dict(retry=retry)
262
sched._schedule(self.context, 'compute', request_spec,
263
filter_properties=filter_properties)
265
num_attempts = filter_properties['retry']['num_attempts']
266
self.assertEqual(2, num_attempts)
268
def test_retry_exceeded_max_attempts(self):
269
"""Test for necessary explosion when max retries is exceeded"""
270
self.flags(scheduler_max_attempts=2)
271
sched = fakes.FakeFilterScheduler()
273
instance_properties = {}
274
request_spec = dict(instance_properties=instance_properties)
276
retry = dict(num_attempts=2)
277
filter_properties = dict(retry=retry)
279
self.assertRaises(exception.NoValidHost, sched._schedule, self.context,
280
'compute', request_spec, filter_properties=filter_properties)
282
def test_add_retry_host(self):
283
retry = dict(num_attempts=1, hosts=[])
284
filter_properties = dict(retry=retry)
287
sched = fakes.FakeFilterScheduler()
288
sched._add_retry_host(filter_properties, host)
290
hosts = filter_properties['retry']['hosts']
291
self.assertEqual(1, len(hosts))
292
self.assertEqual(host, hosts[0])