Add a virtual_size attribute to the Image model

In order to distinguish file size from the virtual image size, we need
to add a new field to the Image model to represent that. This patch adds
a new field called `virtual_size` to the Image model and the migration
for it.

The existing size attribute is kept as is in order to keep backwards
compatibility. Most of the users consider that attribute to be the
physical image size, which is what we're trying to achieve here.

The API implementation will be done in a follow-up patch.

Partially-Implements bp: split-image-size

Change-Id: Ie968e8bcfaeda79de003fe8fd7a3b58c3e45f592
This commit is contained in:
Flavio Percoco 2014-01-08 17:22:00 +01:00
parent 31253812f5
commit 1679422e0a
4 changed files with 68 additions and 4 deletions

View File

@ -174,6 +174,7 @@ def _image_format(image_id, **values):
'min_ram': 0,
'min_disk': 0,
'size': None,
'virtual_size': None,
'checksum': None,
'tags': [],
'created_at': dt,
@ -510,10 +511,10 @@ def image_create(context, image_values):
raise exception.Invalid('status is a required attribute')
allowed_keys = set(['id', 'name', 'status', 'min_ram', 'min_disk', 'size',
'checksum', 'locations', 'owner', 'protected',
'is_public', 'container_format', 'disk_format',
'created_at', 'updated_at', 'deleted_at', 'deleted',
'properties', 'tags'])
'virtual_size', 'checksum', 'locations', 'owner',
'protected', 'is_public', 'container_format',
'disk_format', 'created_at', 'updated_at', 'deleted',
'deleted_at', 'properties', 'tags'])
incorrect_keys = set(image_values.keys()) - allowed_keys
if incorrect_keys:

View File

@ -0,0 +1,34 @@
# Copyright 2014 Red Hat, Inc.
# 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
def upgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
images = sqlalchemy.Table('images', meta, autoload=True)
virtual_size = sqlalchemy.Column('virtual_size',
sqlalchemy.BigInteger)
images.create_column(virtual_size)
def downgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
images = sqlalchemy.Table('images', meta, autoload=True)
images.columns['virtual_size'].drop()

View File

@ -125,6 +125,7 @@ class Image(BASE, GlanceBase):
disk_format = Column(String(20))
container_format = Column(String(20))
size = Column(BigInteger)
virtual_size = Column(BigInteger)
status = Column(String(30), nullable=False)
is_public = Column(Boolean, nullable=False, default=False)
checksum = Column(String(32))

View File

@ -1225,3 +1225,31 @@ class TestMigrations(test_utils.BaseTestCase):
def _post_downgrade_033(self, engine):
image_locations = get_table(engine, 'image_locations')
self.assertNotIn('status', image_locations.c)
def _pre_upgrade_034(self, engine):
images = get_table(engine, 'images')
now = datetime.datetime.now()
image_id = 'fake_id_034'
temp = dict(deleted=False,
created_at=now,
updated_at=now,
status='active',
is_public=True,
min_disk=0,
min_ram=0,
id=image_id)
images.insert().values(temp).execute()
def _check_034(self, engine, data):
images = get_table(engine, 'images')
self.assertIn('virtual_size', images.c)
result = (images.select()
.where(images.c.id == 'fake_id_034')
.execute().fetchone())
self.assertIsNone(result.virtual_size)
def _post_downgrade_034(self, engine):
images = get_table(engine, 'images')
self.assertNotIn('virtual_size', images.c)