122
122
'host2': {'compute': host2_compute_capabs}}
123
123
self.assertDictMatch(service_states, expected)
125
def test_host_service_caps_stale(self):
126
self.flags(periodic_interval=5)
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))
135
service_states = {'host1': {'compute': host1_compute_capabs,
136
'volume': host1_volume_capabs},
137
'host2': {'compute': host2_compute_capabs}}
139
self.host_manager.service_states = service_states
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))
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')
151
self.assertEqual(res1, True)
152
self.assertEqual(res2, False)
153
self.assertEqual(res3, False)
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))
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
168
to_delete = {'host1': {'volume': host1_volume_capabs},
169
'host2': {'compute': host2_compute_capabs}}
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)
175
expected = {'host1': {'compute': host1_compute_capabs}}
176
self.assertEqual(service_states, expected)
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,
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))
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
203
# This tests with 1 volume disabled (host2), and 1 volume node
205
def _fake_host_service_caps_stale(host, service):
208
if service == 'compute':
210
elif service == 'volume':
212
elif host == 'host2':
213
# Shouldn't get here for 'volume' because the service
215
self.assertEqual(service, 'compute')
217
self.assertEqual(host, 'host3')
220
self.stubs.Set(self.host_manager, 'host_service_caps_stale',
221
_fake_host_service_caps_stale)
223
self.mox.StubOutWithMock(self.host_manager,
224
'delete_expired_host_services')
225
self.host_manager.delete_expired_host_services({'host1': ['volume']})
228
result = self.host_manager.get_service_capabilities()
230
self.assertEqual(info['called'], 5)
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)}
237
self.assertDictMatch(result, expected)
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)