Skip to content

Commit

Permalink
Fixing a unicode related metadata bug.
Browse files Browse the repository at this point in the history
When a server had metadata with unicode characters in the values, doing a GET
on servers details would return a 500 error. This fixes that bug.

bug: 929281
Change-Id: I6162532c9a5a615802eb23e7bf9a80d3faf6e7a0
  • Loading branch information
ironcamel committed Feb 13, 2012
1 parent df687ab commit 2a22d5b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/views/servers.py
Expand Up @@ -136,7 +136,7 @@ def _list_view(self, func, request, servers):
@staticmethod
def _get_metadata(instance):
metadata = instance.get("metadata", [])
return dict((item['key'], str(item['value'])) for item in metadata)
return dict((item['key'], item['value']) for item in metadata)

@staticmethod
def _get_vm_state(instance):
Expand Down
6 changes: 1 addition & 5 deletions nova/tests/api/openstack/compute/test_servers.py
Expand Up @@ -3229,7 +3229,6 @@ def test_build_server_detail_with_metadata(self):

metadata = []
metadata.append(InstanceMetadata(key="Open", value="Stack"))
metadata.append(InstanceMetadata(key="Number", value=1))
self.instance['metadata'] = metadata

image_bookmark = "http://localhost/fake/images/5"
Expand Down Expand Up @@ -3274,10 +3273,7 @@ def test_build_server_detail_with_metadata(self):
{'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
]
},
"metadata": {
"Open": "Stack",
"Number": "1",
},
"metadata": {"Open": "Stack"},
"config_drive": None,
"links": [
{
Expand Down
2 changes: 1 addition & 1 deletion nova/tests/api/openstack/fakes.py
Expand Up @@ -469,7 +469,7 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
include_fake_metadata=True,
power_state=None, nw_cache=None):
if include_fake_metadata:
metadata = [models.InstanceMetadata(key='seq', value=id)]
metadata = [models.InstanceMetadata(key='seq', value=str(id))]
else:
metadata = []

Expand Down

0 comments on commit 2a22d5b

Please sign in to comment.