Skip to content

Commit

Permalink
Merge "Ensures that hostId's are unique"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 10, 2012
2 parents 246fbd4 + 6a823d0 commit 4e31ecb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nova/api/openstack/compute/views/servers.py
Expand Up @@ -146,8 +146,10 @@ def _get_vm_state(instance):
@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"]
Expand Down
22 changes: 22 additions & 0 deletions nova/tests/api/openstack/compute/test_servers.py
Expand Up @@ -19,6 +19,7 @@
import datetime
import json
import urlparse
import uuid

from lxml import etree
import webob
Expand Down Expand Up @@ -217,6 +218,27 @@ def test_get_server_by_uuid(self):
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"
Expand Down

0 comments on commit 4e31ecb

Please sign in to comment.