298
298
for s in res_dict['servers']:
299
299
self.assertEqual(s['id'], i)
300
self.assertEqual(s['hostId'], '')
300
301
self.assertEqual(s['name'], 'server%d' % i)
301
302
self.assertEqual(s['imageId'], 10)
302
303
self.assertEqual(s['metadata']['seq'], i)
306
def test_get_all_server_details_with_host(self):
308
We want to make sure that if two instances are on the same host, then
309
they return the same hostId. If two instances are on different hosts,
310
they should return different hostId's. In this test, there are 5
311
instances - 2 on one host and 3 on another.
314
def stub_instance(id, user_id=1):
315
return Instance(id=id, state=0, image_id=10, user_id=user_id,
316
display_name='server%s' % id, host='host%s' % (id % 2))
318
def return_servers_with_host(context, user_id=1):
319
return [stub_instance(i) for i in xrange(5)]
321
self.stubs.Set(nova.db.api, 'instance_get_all_by_user',
322
return_servers_with_host)
324
req = webob.Request.blank('/v1.0/servers/detail')
325
res = req.get_response(fakes.wsgi_app())
326
res_dict = json.loads(res.body)
328
server_list = res_dict['servers']
329
host_ids = [server_list[0]['hostId'], server_list[1]['hostId']]
330
self.assertTrue(host_ids[0] and host_ids[1])
331
self.assertNotEqual(host_ids[0], host_ids[1])
333
for i, s in enumerate(res_dict['servers']):
334
self.assertEqual(s['id'], i)
335
self.assertEqual(s['hostId'], host_ids[i % 2])
336
self.assertEqual(s['name'], 'server%d' % i)
337
self.assertEqual(s['imageId'], 10)
305
339
def test_server_pause(self):
306
340
FLAGS.allow_admin_api = True
307
341
body = dict(server=dict(