Fix missing size value in snapshot instance

This patch fixes the size value not being present in share
snapshot instances, which causes drivers to not being able to access
this property unless they read the size from the snapshot model.

Closes-bug: #1815587
Change-Id: I730629ea460c316a02f8dffb4a55eea04ad619c9
This commit is contained in:
silvacarloss 2019-02-11 15:27:06 -02:00
parent eb31a858da
commit 785aa8369c
3 changed files with 27 additions and 1 deletions

View File

@ -1308,6 +1308,12 @@ def _extract_share_instance_values(values):
return share_instance_values, share_values
def _change_size_to_instance_size(snap_instance_values):
if 'size' in snap_instance_values:
snap_instance_values['instance_size'] = snap_instance_values['size']
snap_instance_values.pop('size')
def _extract_snapshot_instance_values(values):
fields = ['status', 'progress', 'provider_location']
snapshot_instance_values, snapshot_values = (
@ -2313,6 +2319,8 @@ def share_snapshot_instance_create(context, snapshot_id, values, session=None):
session = session or get_session()
values = copy.deepcopy(values)
_change_size_to_instance_size(values)
if not values.get('id'):
values['id'] = uuidutils.generate_uuid()
values.update({'snapshot_id': snapshot_id})
@ -2330,6 +2338,7 @@ def share_snapshot_instance_update(context, instance_id, values):
session = get_session()
instance_ref = share_snapshot_instance_get(context, instance_id,
session=session)
_change_size_to_instance_size(values)
# NOTE(u_glide): Ignore updates to custom properties
for extra_key in models.ShareSnapshotInstance._extra_keys:
@ -4651,6 +4660,8 @@ def share_group_snapshot_member_create(context, values):
if not values.get('id'):
values['id'] = six.text_type(uuidutils.generate_uuid())
_change_size_to_instance_size(values)
session = get_session()
with session.begin():
member.update(values)
@ -4663,6 +4674,7 @@ def share_group_snapshot_member_create(context, values):
@require_context
def share_group_snapshot_member_update(context, member_id, values):
session = get_session()
_change_size_to_instance_size(values)
with session.begin():
member = share_group_snapshot_member_get(
context, member_id, session=session)

View File

@ -751,6 +751,14 @@ class ShareSnapshotInstance(BASE, ManilaBase):
# with share drivers
return self.share_instance_id
@property
def size(self):
# NOTE(silvacarlose) for backwards compatibility
if self.instance_size is None:
return self.snapshot.size
else:
return self.instance_size
id = Column(String(36), primary_key=True)
deleted = Column(String(36), default='False')
snapshot_id = Column(String(36), nullable=True)
@ -760,7 +768,7 @@ class ShareSnapshotInstance(BASE, ManilaBase):
progress = Column(String(255))
provider_location = Column(String(255))
share_proto = Column(String(255))
size = Column(Integer)
instance_size = Column('size', Integer)
share_group_snapshot_id = Column(String(36), nullable=True)
user_id = Column(String(255))
project_id = Column(String(255))

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed the size value not being present in share snapshot
instances, which caused the NetApp driver to crash when
creating a share from a snapshot using python3.