79
81
self.service_states = {}
82
def fake_empty_call_zone_method(context, method, specs):
84
def fake_empty_call_zone_method(context, method, specs, zones):
101
def fake_provision_resource_locally(context, item, instance_id, kwargs):
103
def fake_provision_resource_locally(context, build_plan, request_spec, kwargs):
102
104
global was_called
103
105
was_called = True
118
120
'child_blob': True} # values aren't important. Keys are.
121
def fake_call_zone_method(context, method, specs):
123
def fake_call_zone_method(context, method, specs, zones):
124
126
dict(weight=1, blob='AAAAAAA'),
146
def fake_zone_get_all(context):
148
dict(id=1, api_url='zone1',
149
username='admin', password='password',
150
weight_offset=0.0, weight_scale=1.0),
151
dict(id=2, api_url='zone2',
152
username='admin', password='password',
153
weight_offset=1000.0, weight_scale=1.0),
154
dict(id=3, api_url='zone3',
155
username='admin', password='password',
156
weight_offset=0.0, weight_scale=1000.0),
144
160
class ZoneAwareSchedulerTestCase(test.TestCase):
145
161
"""Test case for Zone Aware Scheduler."""
152
168
sched = FakeZoneAwareScheduler()
153
169
self.stubs.Set(sched, '_call_zone_method', fake_call_zone_method)
170
self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all)
155
172
zm = FakeZoneManager()
156
173
sched.set_zone_manager(zm)
169
186
self.assertEqual(4, len(hostnames))
188
def test_adjust_child_weights(self):
189
"""Make sure the weights returned by child zones are
190
properly adjusted based on the scale/offset in the zone
193
sched = FakeZoneAwareScheduler()
194
child_results = fake_call_zone_method(None, None, None, None)
195
zones = fake_zone_get_all(None)
196
sched._adjust_child_weights(child_results, zones)
197
scaled = [130000, 131000, 132000, 3000]
198
for zone, results in child_results:
201
if zone == 'zone1': # No change
202
self.assertTrue(w < 1000.0)
203
if zone == 'zone2': # Offset +1000
204
self.assertTrue(w >= 1000.0 and w < 2000)
205
if zone == 'zone3': # Scale x1000
206
self.assertEqual(scaled.pop(0), w)
171
208
def test_empty_zone_aware_scheduler(self):
173
210
Ensure empty hosts & child_zones result in NoValidHosts exception.
175
212
sched = FakeZoneAwareScheduler()
176
213
self.stubs.Set(sched, '_call_zone_method', fake_empty_call_zone_method)
214
self.stubs.Set(nova.db, 'zone_get_all', fake_zone_get_all)
178
216
zm = FakeEmptyZoneManager()
179
217
sched.set_zone_manager(zm)