'Restores the volume_type_id for encryption if needed.
Only allow restoration of an encrypted backup if the destination
volume has the same volume type as the source volume. Otherwise
encryption will not work. If volume types are already the same,
no action is needed.'

def _restore_vol_encryption_meta(self, volume_id, src_volume_type_id):

    dest_vol = self.db.volume_get(self.context, volume_id)
    if (dest_vol['volume_type_id'] != src_volume_type_id):
        LOG.debug("Volume    type    id's    do    not    match.")
        if (dest_vol['volume_type_id'] is None):
            try:
                self.db.volume_type_get(self.context, src_volume_type_id)
            except exception.VolumeTypeNotFound:
                LOG.debug('Volume    type    of    source    volume    has    been    deleted.    Encrypted    backup    restore    has    failed.')
                msg = (_("The    source    volume    type    '%s'    is    not    available.") % src_volume_type_id)
                raise exception.EncryptedBackupOperationFailed(msg)
            LOG.debug('The    volume    type    of    the    destination    volume    will    become    the    volume    type    of    the    source    volume.')
            self.db.volume_update(self.context, volume_id, {'volume_type_id': src_volume_type_id})
        else:
            LOG.warning('Destination    volume    type    is    different    from    source    volume    type    for    an    encrypted    volume.    Encrypted    backup    restore    has    failed.')
            msg = (_("The    source    volume    type    '%(src)s'    is    different    than    the    destination    volume    type    '%(dest)s'.") % {'src': src_volume_type_id, 'dest': dest_vol['volume_type_id']})
            raise exception.EncryptedBackupOperationFailed(msg)
