summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-10 22:00:38 +0000
committerGerrit Code Review <review@openstack.org>2012-02-10 22:00:38 +0000
commit4e31ecb49c743090f8dd988e3480ad2f6f4208cf (patch)
treeec73f91fcbd7cc0c1fd32f8d1d6cbacfaf103d04
parent246fbd403395efce01cdd53706921fb235080e42 (diff)
parent6a823d0e1670507a6f4674d5f70e8d9ce0b4c3df (diff)
downloadnova-4e31ecb49c743090f8dd988e3480ad2f6f4208cf.tar.gz
nova-4e31ecb49c743090f8dd988e3480ad2f6f4208cf.tar.xz
nova-4e31ecb49c743090f8dd988e3480ad2f6f4208cf.zip
Merge "Ensures that hostId's are unique"
-rw-r--r--nova/api/openstack/compute/views/servers.py4
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py22
2 files changed, 25 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/views/servers.py b/nova/api/openstack/compute/views/servers.py
index 6a1622a66..e923c8286 100644
--- a/nova/api/openstack/compute/views/servers.py
+++ b/nova/api/openstack/compute/views/servers.py
@@ -146,8 +146,10 @@ class ViewBuilder(common.ViewBuilder):
@staticmethod
def _get_host_id(instance):
host = instance.get("host")
+ project = str(instance.get("project_id"))
if host:
- return hashlib.sha224(host).hexdigest() # pylint: disable=E1101
+ sha_hash = hashlib.sha224(project + host) # pylint: disable=E1101
+ return sha_hash.hexdigest()
def _get_addresses(self, request, instance):
context = request.environ["nova.context"]
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 1bf5f829f..708b81b60 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -19,6 +19,7 @@
import datetime
import json
import urlparse
+import uuid
from lxml import etree
import webob
@@ -217,6 +218,27 @@ class ServersControllerTest(test.TestCase):
res_dict = self.controller.show(req, FAKE_UUID)
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
+ def test_unique_host_id(self):
+ """Create two servers with the same host and different
+ project_ids and check that the hostId's are unique"""
+ def return_instance_with_host(self, *args):
+ project_id = str(uuid.uuid4())
+ return fakes.stub_instance(id=1, uuid=FAKE_UUID,
+ project_id=project_id,
+ host='fake_host')
+
+ self.stubs.Set(nova.db, 'instance_get_by_uuid',
+ return_instance_with_host)
+ self.stubs.Set(nova.db, 'instance_get',
+ return_instance_with_host)
+
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
+ server1 = self.controller.show(req, FAKE_UUID)
+ server2 = self.controller.show(req, FAKE_UUID)
+
+ self.assertNotEqual(server1['server']['hostId'],
+ server2['server']['hostId'])
+
def test_get_server_by_id(self):
self.flags(use_ipv6=True)
image_bookmark = "http://localhost/fake/images/10"