summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorKen Pepple <ken.pepple@gmail.com>2011-03-01 23:10:04 -0800
committerKen Pepple <ken.pepple@gmail.com>2011-03-01 23:10:04 -0800
commit2162bd911ec82471fa24ff4060bfcbab37fd8a3c (patch)
treefb0053a39c02d9f13ca2ec18152e8275a417d163 /nova/tests
parent282a18a4c15f066e371596104f783f522309c5ee (diff)
parentbb7c1b8c63632c789ed0cd3785a22b7baa90fd83 (diff)
downloadnova-2162bd911ec82471fa24ff4060bfcbab37fd8a3c.tar.gz
nova-2162bd911ec82471fa24ff4060bfcbab37fd8a3c.tar.xz
nova-2162bd911ec82471fa24ff4060bfcbab37fd8a3c.zip
merged trunk
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_servers.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 7a25abe9d..78beb7df9 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -297,11 +297,45 @@ class ServersTest(test.TestCase):
i = 0
for s in res_dict['servers']:
self.assertEqual(s['id'], i)
+ self.assertEqual(s['hostId'], '')
self.assertEqual(s['name'], 'server%d' % i)
self.assertEqual(s['imageId'], 10)
self.assertEqual(s['metadata']['seq'], i)
i += 1
+ def test_get_all_server_details_with_host(self):
+ '''
+ We want to make sure that if two instances are on the same host, then
+ they return the same hostId. If two instances are on different hosts,
+ they should return different hostId's. In this test, there are 5
+ instances - 2 on one host and 3 on another.
+ '''
+
+ def stub_instance(id, user_id=1):
+ return Instance(id=id, state=0, image_id=10, user_id=user_id,
+ display_name='server%s' % id, host='host%s' % (id % 2))
+
+ def return_servers_with_host(context, user_id=1):
+ return [stub_instance(i) for i in xrange(5)]
+
+ self.stubs.Set(nova.db.api, 'instance_get_all_by_user',
+ return_servers_with_host)
+
+ req = webob.Request.blank('/v1.0/servers/detail')
+ res = req.get_response(fakes.wsgi_app())
+ res_dict = json.loads(res.body)
+
+ server_list = res_dict['servers']
+ host_ids = [server_list[0]['hostId'], server_list[1]['hostId']]
+ self.assertTrue(host_ids[0] and host_ids[1])
+ self.assertNotEqual(host_ids[0], host_ids[1])
+
+ for i, s in enumerate(res_dict['servers']):
+ self.assertEqual(s['id'], i)
+ self.assertEqual(s['hostId'], host_ids[i % 2])
+ self.assertEqual(s['name'], 'server%d' % i)
+ self.assertEqual(s['imageId'], 10)
+
def test_server_pause(self):
FLAGS.allow_admin_api = True
body = dict(server=dict(