Do not allow min_ram or min_disk properties to be NULL and if they are None, make sure to default to 0. Fixes bug 857711
Change-Id: I0660b39b19a219e7999468839c0672e0c4911d88
This commit is contained in:
parent
8805302edb
commit
c81ebbcc5a
|
@ -332,10 +332,10 @@ def _image_update(context, values, image_id, purge_props=False):
|
|||
values['size'] = int(values['size'])
|
||||
|
||||
if 'min_ram' in values:
|
||||
values['min_ram'] = int(values['min_ram'])
|
||||
values['min_ram'] = int(values['min_ram'] or 0)
|
||||
|
||||
if 'min_disk' in values:
|
||||
values['min_disk'] = int(values['min_disk'])
|
||||
values['min_disk'] = int(values['min_disk'] or 0)
|
||||
|
||||
values['is_public'] = bool(values.get('is_public', False))
|
||||
image_ref = models.Image()
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy
|
||||
|
||||
|
||||
meta = sqlalchemy.MetaData()
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
images = sqlalchemy.Table('images', meta, autoload=True)
|
||||
images.c.min_disk.alter(nullable=False)
|
||||
images.c.min_ram.alter(nullable=False)
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
images = sqlalchemy.Table('images', meta, autoload=True)
|
||||
images.c.min_disk.alter(nullable=True)
|
||||
images.c.min_ram.alter(nullable=True)
|
|
@ -106,8 +106,8 @@ class Image(BASE, ModelBase):
|
|||
is_public = Column(Boolean, nullable=False, default=False)
|
||||
location = Column(Text)
|
||||
checksum = Column(String(32))
|
||||
min_disk = Column(Integer(), default=0)
|
||||
min_ram = Column(Integer(), default=0)
|
||||
min_disk = Column(Integer(), nullable=False, default=0)
|
||||
min_ram = Column(Integer(), nullable=False, default=0)
|
||||
owner = Column(String(255))
|
||||
|
||||
|
||||
|
|
|
@ -119,6 +119,24 @@ class TestRegistryClient(unittest.TestCase):
|
|||
for k, v in fixture.items():
|
||||
self.assertEquals(v, images[0][k])
|
||||
|
||||
def test_create_image_with_null_min_disk_min_ram(self):
|
||||
extra_fixture = {
|
||||
'id': 3,
|
||||
'status': 'active',
|
||||
'is_public': True,
|
||||
'disk_format': 'vhd',
|
||||
'container_format': 'ovf',
|
||||
'name': 'asdf',
|
||||
'size': 19,
|
||||
'checksum': None,
|
||||
'min_disk': None,
|
||||
'min_ram': None,
|
||||
}
|
||||
db_api.image_create(self.context, extra_fixture)
|
||||
image = self.client.get_image(3)
|
||||
self.assertEqual(0, image["min_ram"])
|
||||
self.assertEqual(0, image["min_disk"])
|
||||
|
||||
def test_get_index_sort_id_desc(self):
|
||||
"""
|
||||
Tests that the /images registry API returns list of
|
||||
|
|
Loading…
Reference in New Issue