diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index 48ec90c704..3401b21068 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -1309,6 +1309,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 = ( @@ -2315,6 +2321,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}) @@ -2332,6 +2340,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: @@ -4700,6 +4709,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) @@ -4712,6 +4723,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) diff --git a/manila/db/sqlalchemy/models.py b/manila/db/sqlalchemy/models.py index de9b2567a6..0f08cc795b 100644 --- a/manila/db/sqlalchemy/models.py +++ b/manila/db/sqlalchemy/models.py @@ -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)) diff --git a/releasenotes/notes/fix-py3-netapp-a9815186ddc865d4.yaml b/releasenotes/notes/fix-py3-netapp-a9815186ddc865d4.yaml new file mode 100644 index 0000000000..ef0d6c926b --- /dev/null +++ b/releasenotes/notes/fix-py3-netapp-a9815186ddc865d4.yaml @@ -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.