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
This commit is contained in:
Brian Waldon 2012-08-30 14:38:34 -07:00
parent b7b2a0997b
commit 1d91a4dc2b
4 changed files with 13 additions and 8 deletions

View File

@ -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',

View File

@ -98,6 +98,13 @@ class BaseTestCase(object):
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'})

View File

@ -59,9 +59,9 @@ class FakeDB(object):
@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]

View File

@ -197,12 +197,7 @@ class TestImagesController(test_utils.BaseTestCase):
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)