Skip to content

Commit

Permalink
Cast is_public, protected, deleted to bool
Browse files Browse the repository at this point in the history
To keep a consistent view of an image, is_public, protected, and
deleted need to be cast to a bool when being parsed from headers.

Fix bug 1036299

Change-Id: I2730a0f2d705d26ebc0ba883e99c1caf44d70b51
  • Loading branch information
bcwaldon committed Aug 13, 2012
1 parent 1e539df commit 8f0d5c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions glanceclient/v1/images.py
Expand Up @@ -57,6 +57,11 @@ def _image_meta_from_headers(self, headers):
elif key.startswith('x-image-meta-'):
_key = key[13:]
meta[_key] = value

for key in ['is_public', 'protected', 'deleted']:
if key in meta:
meta[key] = utils.string_to_bool(meta[key])

return self._format_image_meta_for_user(meta)

def _image_meta_to_headers(self, fields):
Expand Down
14 changes: 14 additions & 0 deletions tests/v1/test_images.py
Expand Up @@ -39,6 +39,9 @@
'min_ram': '512',
'min_disk': '10',
'properties': {'a': 'b', 'c': 'd'},
'is_public': False,
'protected': False,
'deleted': False,
}},
),
),
Expand Down Expand Up @@ -141,6 +144,9 @@
'x-image-meta-id': '1',
'x-image-meta-name': 'image-1',
'x-image-meta-property-arch': 'x86_64',
'x-image-meta-is_public': 'false',
'x-image-meta-protected': 'false',
'x-image-meta-deleted': 'false',
},
None),
'GET': (
Expand All @@ -160,6 +166,8 @@
'min_ram': '512',
'min_disk': '10',
'properties': {'a': 'b', 'c': 'd'},
'is_public': False,
'protected': False,
}},
),
),
Expand Down Expand Up @@ -246,6 +254,9 @@ def test_get(self):
self.assertEqual(self.api.calls, expect)
self.assertEqual(image.id, '1')
self.assertEqual(image.name, 'image-1')
self.assertEqual(image.is_public, False)
self.assertEqual(image.protected, False)
self.assertEqual(image.deleted, False)

def test_data(self):
data = ''.join([b for b in self.mgr.data('1', do_checksum=False)])
Expand Down Expand Up @@ -328,6 +339,9 @@ def test_create_without_data(self):
self.assertEqual(image.size, 1024)
self.assertEqual(image.min_ram, 512)
self.assertEqual(image.min_disk, 10)
self.assertEqual(image.is_public, False)
self.assertEqual(image.protected, False)
self.assertEqual(image.deleted, False)
self.assertEqual(image.properties, {'a': 'b', 'c': 'd'})

def test_create_with_data(self):
Expand Down

0 comments on commit 8f0d5c4

Please sign in to comment.