Permalink
Browse files

Require 'status' in simple db image_create

Since the sqlalchemy driver requires that 'status' be set in an
image_create call, this makes the simple driver follow suit.

Related to bp glance-simple-db-parity.

Change-Id: I0b6809e467fa8aecfefcd7017cd198ca0691a236
  • Loading branch information...
1 parent b7b2a09 commit 1d91a4dc2b74d224ea12947d672aa66a576d9d9a @bcwaldon bcwaldon committed Aug 30, 2012
View
@@ -306,6 +306,9 @@ def image_create(context, image_values):
if image_id in DATA['images']:
raise exception.Duplicate()
+ if 'status' not in image_values:
+ raise exception.Invalid('status is a required attribute')
+
allowed_keys = set(['id', 'name', 'status', 'min_ram', 'min_disk', 'size',
'checksum', 'location', 'owner', 'protected',
'is_public', 'container_format', 'disk_format',
@@ -98,6 +98,13 @@ def create_images(self, images):
def reset(self):
pass
+ def test_image_create_requires_status(self):
+ fixture = {'name': 'mark', 'size': 12}
+ self.assertRaises(exception.Invalid,
+ self.db_api.image_create, self.context, fixture)
+ fixture = {'name': 'mark', 'size': 12, 'status': 'queued'}
+ self.db_api.image_create(self.context, fixture)
+
def test_image_create_defaults(self):
image = self.db_api.image_create(self.context, {'status': 'queued'})
@@ -59,9 +59,9 @@ def __init__(self):
@staticmethod
def init_db():
images = [
- {'id': UUID1, 'owner': TENANT1,
+ {'id': UUID1, 'owner': TENANT1, 'status': 'queued',
'location': '%s/%s' % (BASE_URI, UUID1)},
- {'id': UUID2, 'owner': TENANT1},
+ {'id': UUID2, 'owner': TENANT1, 'status': 'queued'},
]
[simple_db.image_create(None, image) for image in images]
@@ -197,12 +197,7 @@ def test_index_with_nonexistent_name_filter(self):
self.assertEqual(0, len(images))
def test_index_with_non_default_is_public_filter(self):
- image = {
- 'id': utils.generate_uuid(),
- 'owner': TENANT3,
- 'name': '3',
- 'is_public': False
- }
+ image = _fixture(utils.generate_uuid(), is_public=False, owner=TENANT3)
self.db.image_create(None, image)
path = '/images?visibility=private'
request = unit_test_utils.get_fake_request(path)

0 comments on commit 1d91a4d

Please sign in to comment.