@require_admin_context
def finish_volume_migration(context, src_vol_id, dest_vol_id):
- """Copy almost all columns from dest to source, then delete dest."""
+ """Copy almost all columns from dest to source."""
session = get_session()
with session.begin():
+ src_volume_ref = _volume_get(context, src_vol_id, session=session)
dest_volume_ref = _volume_get(context, dest_vol_id, session=session)
- updates = {}
- if dest_volume_ref['_name_id']:
- updates['_name_id'] = dest_volume_ref['_name_id']
- else:
- updates['_name_id'] = dest_volume_ref['id']
+
+ # NOTE(rpodolyaka): we should copy only column values, while model
+ # instances also have relationships attributes, which
+ # should be ignored
+ def is_column(inst, attr):
+ return attr in inst.__class__.__table__.columns
+
for key, value in dest_volume_ref.iteritems():
- if key in ['id', '_name_id']:
+ if key == 'id' or not is_column(dest_volume_ref, key):
continue
- if key == 'migration_status':
- updates[key] = None
- continue
- updates[key] = value
- session.query(models.Volume).\
- filter_by(id=src_vol_id).\
- update(updates)
+ elif key == 'migration_status':
+ value = None
+ elif key == '_name_id':
+ value = dest_volume_ref['_name_id'] or dest_volume_ref['id']
+
+ setattr(src_volume_ref, key, value)
@require_admin_context