~vishvananda/nova/cloudpipe-docs

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/test_servers.py

  • Committer: Tarmac
  • Author(s): Naveed Massjouni
  • Date: 2011-03-01 01:09:43 UTC
  • mfrom: (662.3.9 openstack-api-hostid)
  • Revision ID: tarmac-20110301010943-i6r61r2647n93gyr
This branch implements the openstack-api-hostid blueprint: "Openstack API support for hostId".

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
        i = 0
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)
303
304
            i += 1
304
305
 
 
306
    def test_get_all_server_details_with_host(self):
 
307
        '''
 
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.
 
312
        '''
 
313
 
 
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))
 
317
 
 
318
        def return_servers_with_host(context, user_id=1):
 
319
            return [stub_instance(i) for i in xrange(5)]
 
320
 
 
321
        self.stubs.Set(nova.db.api, 'instance_get_all_by_user',
 
322
            return_servers_with_host)
 
323
 
 
324
        req = webob.Request.blank('/v1.0/servers/detail')
 
325
        res = req.get_response(fakes.wsgi_app())
 
326
        res_dict = json.loads(res.body)
 
327
 
 
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])
 
332
 
 
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)
 
338
 
305
339
    def test_server_pause(self):
306
340
        FLAGS.allow_admin_api = True
307
341
        body = dict(server=dict(