~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
                    'host2': {'compute': host2_compute_capabs}}
123
123
        self.assertDictMatch(service_states, expected)
124
124
 
125
 
    def test_host_service_caps_stale(self):
126
 
        self.flags(periodic_interval=5)
127
 
 
128
 
        host1_compute_capabs = dict(free_memory=1234, host_memory=5678,
129
 
                timestamp=datetime.datetime.fromtimestamp(3000))
130
 
        host1_volume_capabs = dict(free_disk=4321,
131
 
                timestamp=datetime.datetime.fromtimestamp(3005))
132
 
        host2_compute_capabs = dict(free_memory=8756,
133
 
                timestamp=datetime.datetime.fromtimestamp(3010))
134
 
 
135
 
        service_states = {'host1': {'compute': host1_compute_capabs,
136
 
                                    'volume': host1_volume_capabs},
137
 
                          'host2': {'compute': host2_compute_capabs}}
138
 
 
139
 
        self.host_manager.service_states = service_states
140
 
 
141
 
        self.mox.StubOutWithMock(timeutils, 'utcnow')
142
 
        timeutils.utcnow().AndReturn(datetime.datetime.fromtimestamp(3020))
143
 
        timeutils.utcnow().AndReturn(datetime.datetime.fromtimestamp(3020))
144
 
        timeutils.utcnow().AndReturn(datetime.datetime.fromtimestamp(3020))
145
 
 
146
 
        self.mox.ReplayAll()
147
 
        res1 = self.host_manager.host_service_caps_stale('host1', 'compute')
148
 
        res2 = self.host_manager.host_service_caps_stale('host1', 'volume')
149
 
        res3 = self.host_manager.host_service_caps_stale('host2', 'compute')
150
 
 
151
 
        self.assertEqual(res1, True)
152
 
        self.assertEqual(res2, False)
153
 
        self.assertEqual(res3, False)
154
 
 
155
 
    def test_delete_expired_host_services(self):
156
 
        host1_compute_capabs = dict(free_memory=1234, host_memory=5678,
157
 
                timestamp=datetime.datetime.fromtimestamp(3000))
158
 
        host1_volume_capabs = dict(free_disk=4321,
159
 
                timestamp=datetime.datetime.fromtimestamp(3005))
160
 
        host2_compute_capabs = dict(free_memory=8756,
161
 
                timestamp=datetime.datetime.fromtimestamp(3010))
162
 
 
163
 
        service_states = {'host1': {'compute': host1_compute_capabs,
164
 
                                    'volume': host1_volume_capabs},
165
 
                          'host2': {'compute': host2_compute_capabs}}
166
 
        self.host_manager.service_states = service_states
167
 
 
168
 
        to_delete = {'host1': {'volume': host1_volume_capabs},
169
 
                     'host2': {'compute': host2_compute_capabs}}
170
 
 
171
 
        self.host_manager.delete_expired_host_services(to_delete)
172
 
        # Make sure dictionary isn't re-assigned
173
 
        self.assertEqual(self.host_manager.service_states, service_states)
174
 
 
175
 
        expected = {'host1': {'compute': host1_compute_capabs}}
176
 
        self.assertEqual(service_states, expected)
177
 
 
178
 
    def test_get_service_capabilities(self):
179
 
        host1_compute_capabs = dict(free_memory=1000, host_memory=5678,
180
 
                timestamp=datetime.datetime.fromtimestamp(3000))
181
 
        host1_volume_capabs = dict(free_disk=4321,
182
 
                timestamp=datetime.datetime.fromtimestamp(3005))
183
 
        host2_compute_capabs = dict(free_memory=8756,
184
 
                timestamp=datetime.datetime.fromtimestamp(3010))
185
 
        host2_volume_capabs = dict(free_disk=8756,
186
 
                enabled=False,
187
 
                timestamp=datetime.datetime.fromtimestamp(3010))
188
 
        host3_compute_capabs = dict(free_memory=1234, host_memory=4000,
189
 
                timestamp=datetime.datetime.fromtimestamp(3010))
190
 
        host3_volume_capabs = dict(free_disk=2000,
191
 
                timestamp=datetime.datetime.fromtimestamp(3010))
192
 
 
193
 
        service_states = {'host1': {'compute': host1_compute_capabs,
194
 
                                    'volume': host1_volume_capabs},
195
 
                          'host2': {'compute': host2_compute_capabs,
196
 
                                    'volume': host2_volume_capabs},
197
 
                          'host3': {'compute': host3_compute_capabs,
198
 
                                    'volume': host3_volume_capabs}}
199
 
        self.host_manager.service_states = service_states
200
 
 
201
 
        info = {'called': 0}
202
 
 
203
 
        # This tests with 1 volume disabled (host2), and 1 volume node
204
 
        # as stale (host1)
205
 
        def _fake_host_service_caps_stale(host, service):
206
 
            info['called'] += 1
207
 
            if host == 'host1':
208
 
                if service == 'compute':
209
 
                    return False
210
 
                elif service == 'volume':
211
 
                    return True
212
 
            elif host == 'host2':
213
 
                # Shouldn't get here for 'volume' because the service
214
 
                # is disabled
215
 
                self.assertEqual(service, 'compute')
216
 
                return False
217
 
            self.assertEqual(host, 'host3')
218
 
            return False
219
 
 
220
 
        self.stubs.Set(self.host_manager, 'host_service_caps_stale',
221
 
                _fake_host_service_caps_stale)
222
 
 
223
 
        self.mox.StubOutWithMock(self.host_manager,
224
 
                'delete_expired_host_services')
225
 
        self.host_manager.delete_expired_host_services({'host1': ['volume']})
226
 
 
227
 
        self.mox.ReplayAll()
228
 
        result = self.host_manager.get_service_capabilities()
229
 
 
230
 
        self.assertEqual(info['called'], 5)
231
 
 
232
 
        # only 1 volume node active == 'host3', so min/max is 2000
233
 
        expected = {'volume_free_disk': (2000, 2000),
234
 
                    'compute_host_memory': (4000, 5678),
235
 
                    'compute_free_memory': (1000, 8756)}
236
 
 
237
 
        self.assertDictMatch(result, expected)
238
 
 
239
125
    def test_get_all_host_states(self):
240
126
        self.flags(reserved_host_memory_mb=512,
241
127
                reserved_host_disk_mb=1024)