~blamar/nova/gracefull-shutdown

« back to all changes in this revision

Viewing changes to nova/tests/scheduler/test_zone_aware_scheduler.py

  • Committer: Tarmac
  • Author(s): Sandy Walsh
  • Date: 2011-06-30 18:23:06 UTC
  • mfrom: (1063.9.15 zone_offset)
  • Revision ID: tarmac-20110630182306-xeik58dcp10z39fw
Child Zone Weight adjustment available when adding Child Zones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
Tests For Zone Aware Scheduler.
17
17
"""
18
18
 
 
19
import nova.db
 
20
 
19
21
from nova import exception
20
22
from nova import test
21
23
from nova.scheduler import driver
79
81
        self.service_states = {}
80
82
 
81
83
 
82
 
def fake_empty_call_zone_method(context, method, specs):
 
84
def fake_empty_call_zone_method(context, method, specs, zones):
83
85
    return []
84
86
 
85
87
 
98
100
    was_called = True
99
101
 
100
102
 
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
104
106
 
118
120
            'child_blob': True}  # values aren't important. Keys are.
119
121
 
120
122
 
121
 
def fake_call_zone_method(context, method, specs):
 
123
def fake_call_zone_method(context, method, specs, zones):
122
124
    return [
123
125
        ('zone1', [
124
126
            dict(weight=1, blob='AAAAAAA'),
141
143
    ]
142
144
 
143
145
 
 
146
def fake_zone_get_all(context):
 
147
    return [
 
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),
 
157
    ]
 
158
 
 
159
 
144
160
class ZoneAwareSchedulerTestCase(test.TestCase):
145
161
    """Test case for Zone Aware Scheduler."""
146
162
 
151
167
        """
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)
154
171
 
155
172
        zm = FakeZoneManager()
156
173
        sched.set_zone_manager(zm)
168
185
        # 4 local hosts
169
186
        self.assertEqual(4, len(hostnames))
170
187
 
 
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
 
191
        db entries.
 
192
        """
 
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:
 
199
            for item in results:
 
200
                w = item['weight']
 
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)
 
207
 
171
208
    def test_empty_zone_aware_scheduler(self):
172
209
        """
173
210
        Ensure empty hosts & child_zones result in NoValidHosts exception.
174
211
        """
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)
177
215
 
178
216
        zm = FakeEmptyZoneManager()
179
217
        sched.set_zone_manager(zm)