Skip to content

Commit

Permalink
Ensure minRam and minDisk are always integers
Browse files Browse the repository at this point in the history
Fixing bug 859149

Change-Id: I52bcb442225e8e3cb4aecc6d993e1c3a774cdf84
  • Loading branch information
Brian Waldon committed Sep 26, 2011
1 parent 0acc924 commit 3981a21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
17 changes: 13 additions & 4 deletions nova/api/openstack/views/images.py
Expand Up @@ -197,11 +197,20 @@ def build(self, image_obj, detail=False):

if detail:
image["metadata"] = image_obj.get("properties", {})
if 'min_ram' in image_obj:
image["minRam"] = image_obj.get("min_ram") or 0

if 'min_disk' in image_obj:
image["minDisk"] = image_obj.get("min_disk") or 0
min_ram = image_obj.get('min_ram') or 0
try:
min_ram = int(min_ram)
except ValueError:
min_ram = 0
image['minRam'] = min_ram

min_disk = image_obj.get('min_disk') or 0
try:
min_disk = int(min_disk)
except ValueError:
min_disk = 0
image['minDisk'] = min_disk

return image

Expand Down
3 changes: 2 additions & 1 deletion nova/tests/api/openstack/fakes.py
Expand Up @@ -219,7 +219,8 @@ def add_fixture(**kwargs):

# Public image
add_fixture(id=image_id, name='public image', is_public=True,
status='active', properties={'key1': 'value1'})
status='active', properties={'key1': 'value1'},
min_ram="128", min_disk="10")
image_id += 1

# Snapshot for User 1
Expand Down
10 changes: 6 additions & 4 deletions nova/tests/api/openstack/test_images.py
Expand Up @@ -659,8 +659,8 @@ def test_get_image_details_v1_1(self):
'created': NOW_API_FORMAT,
'status': 'ACTIVE',
'progress': 100,
'minDisk': 0,
'minRam': 0,
'minDisk': 10,
'minRam': 128,
"links": [{
"rel": "self",
"href": "http://localhost/v1.1/fake/images/123",
Expand Down Expand Up @@ -950,9 +950,9 @@ def test_get_image_details_with_limit_v1_1(self):
'updated': NOW_API_FORMAT,
'created': NOW_API_FORMAT,
'status': 'ACTIVE',
'minDisk': 0,
'minDisk': 10,
'progress': 100,
'minRam': 0,
'minRam': 128,
"links": [{
"rel": "self",
"href": "http://localhost/v1.1/fake/images/123",
Expand Down Expand Up @@ -1371,6 +1371,8 @@ def test_show(self):
'updated': self.TIMESTAMP,
'status': 'ACTIVE',
'progress': 80,
'minRam': 10,
'minDisk': 100,
'server': {
'id': '1',
'links': [
Expand Down

0 comments on commit 3981a21

Please sign in to comment.