def test_backup_reset_status_to_available_invalid_backup(self): volume = db.volume_create( self.ctxt, { 'status': 'available', 'host': 'test', 'provider_location': '', 'size': 1 }) backup = self._create_backup_db_entry(status='error', volume_id=volume['id']) backup_driver = self.backup_mgr.service.get_backup_driver(self.ctxt) _mock_backup_verify_class = ( '%s.%s.%s' % (backup_driver.__module__, backup_driver.__class__.__name__, 'verify')) with mock.patch(_mock_backup_verify_class) as \ _mock_record_verify: _mock_record_verify.side_effect = \ exception.BackupVerifyUnsupportedDriver(reason='fake') self.assertRaises(exception.BackupVerifyUnsupportedDriver, self.backup_mgr.reset_status, self.ctxt, backup, 'available') backup = db.backup_get(self.ctxt, backup.id) self.assertEqual('error', backup['status'])
def reset_status(self, context, backup, status): """Reset volume backup status. :param context: running context :param backup: The backup object for reset status operation :param status: The status to be set :raises: InvalidBackup :raises: BackupVerifyUnsupportedDriver :raises: AttributeError """ LOG.info( _LI('Reset backup status started, backup_id: ' '%(backup_id)s, status: %(status)s.'), { 'backup_id': backup.id, 'status': status }) try: # NOTE(flaper87): Verify the driver is enabled # before going forward. The exception will be caught # and the backup status updated. Fail early since there # are no other status to change but backup's utils.require_driver_initialized(self.driver) except exception.DriverNotInitialized: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Backup driver has not been initialized")) backup_service = self._map_service_to_driver(backup.service) LOG.info(_LI('Backup service: %s.'), backup_service) if backup_service is not None: configured_service = self.driver_name if backup_service != configured_service: err = _('Reset backup status aborted, the backup service' ' currently configured [%(configured_service)s] ' 'is not the backup service that was used to create' ' this backup [%(backup_service)s].') % \ {'configured_service': configured_service, 'backup_service': backup_service} raise exception.InvalidBackup(reason=err) # Verify backup try: # check whether the backup is ok or not if (status == fields.BackupStatus.AVAILABLE and backup['status'] != fields.BackupStatus.RESTORING): # check whether we could verify the backup is ok or not if isinstance(backup_service, driver.BackupDriverWithVerify): backup_service.verify(backup.id) backup.status = status backup.save() # driver does not support verify function else: msg = (_('Backup service %(configured_service)s ' 'does not support verify. Backup id' ' %(id)s is not verified. ' 'Skipping verify.') % { 'configured_service': self.driver_name, 'id': backup.id }) raise exception.BackupVerifyUnsupportedDriver( reason=msg) # reset status to error or from restoring to available else: if (status == fields.BackupStatus.ERROR or (status == fields.BackupStatus.AVAILABLE and backup.status == fields.BackupStatus.RESTORING)): backup.status = status backup.save() except exception.InvalidBackup: with excutils.save_and_reraise_exception(): LOG.error( _LE("Backup id %s is not invalid. " "Skipping reset."), backup.id) except exception.BackupVerifyUnsupportedDriver: with excutils.save_and_reraise_exception(): LOG.error( _LE('Backup service %(configured_service)s ' 'does not support verify. Backup id ' '%(id)s is not verified. ' 'Skipping verify.'), { 'configured_service': self.driver_name, 'id': backup.id }) except AttributeError: msg = (_('Backup service %(service)s does not support ' 'verify. Backup id %(id)s is not verified. ' 'Skipping reset.') % { 'service': self.driver_name, 'id': backup.id }) LOG.error(msg) raise exception.BackupVerifyUnsupportedDriver(reason=msg) # Needs to clean temporary volumes and snapshots. try: self._cleanup_temp_volumes_snapshots_for_one_backup( context, backup) except Exception: LOG.exception( _LE("Problem cleaning temp volumes and " "snapshots for backup %(bkup)s."), {'bkup': backup.id}) # send notification to ceilometer notifier_info = {'id': backup.id, 'update': {'status': status}} notifier = rpc.get_notifier('backupStatusUpdate') notifier.info(context, "backups.reset_status.end", notifier_info)
def reset_status(self, context, backup, status): """Reset volume backup status. :param context: running context :param backup: The backup object for reset status operation :param status: The status to be set :raises InvalidBackup: :raises BackupVerifyUnsupportedDriver: :raises AttributeError: """ LOG.info('Reset backup status started, backup_id: ' '%(backup_id)s, status: %(status)s.', {'backup_id': backup.id, 'status': status}) backup_service_name = backup.service LOG.info('Backup service: %s.', backup_service_name) if backup_service_name is not None: configured_service = self.driver_name # TODO(tommylikehu): We upgraded the 'driver_name' from module # to class name, so we use 'in' here to match two namings, # this can be replaced with equal sign during next # release (Rocky). if backup_service_name not in configured_service: err = _('Reset backup status aborted, the backup service' ' currently configured [%(configured_service)s] ' 'is not the backup service that was used to create' ' this backup [%(backup_service)s].') % \ {'configured_service': configured_service, 'backup_service': backup_service_name} raise exception.InvalidBackup(reason=err) # Verify backup try: # check whether the backup is ok or not if (status == fields.BackupStatus.AVAILABLE and backup['status'] != fields.BackupStatus.RESTORING): # check whether we could verify the backup is ok or not backup_service = self.get_backup_driver(context) if isinstance(backup_service, driver.BackupDriverWithVerify): backup_service.verify(backup.id) backup.status = status backup.save() # driver does not support verify function else: msg = (_('Backup service %(configured_service)s ' 'does not support verify. Backup id' ' %(id)s is not verified. ' 'Skipping verify.') % {'configured_service': self.driver_name, 'id': backup.id}) raise exception.BackupVerifyUnsupportedDriver( reason=msg) # reset status to error or from restoring to available else: if (status == fields.BackupStatus.ERROR or (status == fields.BackupStatus.AVAILABLE and backup.status == fields.BackupStatus.RESTORING)): backup.status = status backup.save() except exception.InvalidBackup: with excutils.save_and_reraise_exception(): LOG.error("Backup id %s is not invalid. Skipping reset.", backup.id) except exception.BackupVerifyUnsupportedDriver: with excutils.save_and_reraise_exception(): LOG.error('Backup service %(configured_service)s ' 'does not support verify. Backup id ' '%(id)s is not verified. ' 'Skipping verify.', {'configured_service': self.driver_name, 'id': backup.id}) except AttributeError: msg = (_('Backup service %(service)s does not support ' 'verify. Backup id %(id)s is not verified. ' 'Skipping reset.') % {'service': self.driver_name, 'id': backup.id}) LOG.error(msg) raise exception.BackupVerifyUnsupportedDriver( reason=msg) # Needs to clean temporary volumes and snapshots. try: self._cleanup_temp_volumes_snapshots_for_one_backup( context, backup) except Exception: LOG.exception("Problem cleaning temp volumes and " "snapshots for backup %(bkup)s.", {'bkup': backup.id}) # send notification to ceilometer notifier_info = {'id': backup.id, 'update': {'status': status}} notifier = rpc.get_notifier('backupStatusUpdate') notifier.info(context, "backups.reset_status.end", notifier_info)
def reset_status(self, context, backup_id, status): """Reset volume backup status. :param context: running context :param backup_id: The backup id for reset status operation :param status: The status to be set :raises: InvalidBackup :raises: BackupVerifyUnsupportedDriver :raises: AttributeError """ LOG.info( _('Reset backup status started, backup_id: ' '%(backup_id)s, status: %(status)s.'), { 'backup_id': backup_id, 'status': status }) try: # NOTE(flaper87): Verify the driver is enabled # before going forward. The exception will be caught # and the backup status updated. Fail early since there # are no other status to change but backup's utils.require_driver_initialized(self.driver) except exception.DriverNotInitialized: with excutils.save_and_reraise_exception(): LOG.exception(_("Backup driver has not been initialized")) backup = self.db.backup_get(context, backup_id) backup_service = self._map_service_to_driver(backup['service']) LOG.info(_('Backup service: %s.'), backup_service) if backup_service is not None: configured_service = self.driver_name if backup_service != configured_service: err = _('Reset backup status aborted, the backup service' ' currently configured [%(configured_service)s] ' 'is not the backup service that was used to create' ' this backup [%(backup_service)s].') % \ {'configured_service': configured_service, 'backup_service': backup_service} raise exception.InvalidBackup(reason=err) # Verify backup try: # check whether the backup is ok or not if status == 'available' and backup['status'] != 'restoring': # check whether we could verify the backup is ok or not if isinstance(backup_service, driver.BackupDriverWithVerify): backup_service.verify(backup_id) self.db.backup_update(context, backup_id, {'status': status}) # driver does not support verify function else: msg = (_('Backup service %(configured_service)s ' 'does not support verify. Backup id' ' %(id)s is not verified. ' 'Skipping verify.') % { 'configured_service': self.driver_name, 'id': backup_id }) raise exception.BackupVerifyUnsupportedDriver( reason=msg) # reset status to error or from restoring to available else: if (status == 'error' or (status == 'available' and backup['status'] == 'restoring')): self.db.backup_update(context, backup_id, {'status': status}) except exception.InvalidBackup: with excutils.save_and_reraise_exception(): msg = (_("Backup id %(id)s is not invalid. " "Skipping reset.") % { 'id': backup_id }) LOG.error(msg) except exception.BackupVerifyUnsupportedDriver: with excutils.save_and_reraise_exception(): msg = (_('Backup service %(configured_service)s ' 'does not support verify. Backup id' ' %(id)s is not verified. ' 'Skipping verify.') % { 'configured_service': self.driver_name, 'id': backup_id }) LOG.error(msg) except AttributeError: msg = (_('Backup service %(service)s does not support ' 'verify. Backup id %(id)s is not verified. ' 'Skipping reset.') % { 'service': self.driver_name, 'id': backup_id }) LOG.error(msg) raise exception.BackupVerifyUnsupportedDriver(reason=msg) # send notification to ceilometer notifier_info = {'id': backup_id, 'update': {'status': status}} notifier = rpc.get_notifier('backupStatusUpdate') notifier.info(context, "backups" + '.reset_status.end', notifier_info)