raise exception.InvalidBackup(reason=err)
backup_service = backup['service']
- configured_service = FLAGS.backup_service
- if backup_service != configured_service:
- err = _('delete_backup aborted, the backup service currently'
- ' configured [%(configured_service)s] is not the'
- ' backup service that was used to create this'
- ' backup [%(backup_service)s]') % locals()
- self.db.backup_update(context, backup_id, {'status': 'available'})
- raise exception.InvalidBackup(reason=err)
-
- try:
- backup_service = self.service.get_backup_service(context)
- backup_service.delete(backup)
- except Exception as err:
- with excutils.save_and_reraise_exception():
- self.db.backup_update(context, backup_id, {'status': 'error',
- 'fail_reason':
- unicode(err)})
+ if backup_service is not None:
+ configured_service = FLAGS.backup_service
+ if backup_service != configured_service:
+ err = _('delete_backup aborted, the backup service currently'
+ ' configured [%(configured_service)s] is not the'
+ ' backup service that was used to create this'
+ ' backup [%(backup_service)s]') % locals()
+ self.db.backup_update(context, backup_id,
+ {'status': 'error'})
+ raise exception.InvalidBackup(reason=err)
+
+ try:
+ backup_service = self.service.get_backup_service(context)
+ backup_service.delete(backup)
+ except Exception as err:
+ with excutils.save_and_reraise_exception():
+ self.db.backup_update(context, backup_id,
+ {'status': 'error',
+ 'fail_reason':
+ unicode(err)})
context = context.elevated()
self.db.backup_destroy(context, backup_id)
self.ctxt,
backup_id)
backup = db.backup_get(self.ctxt, backup_id)
- self.assertEquals(backup['status'], 'available')
+ self.assertEquals(backup['status'], 'error')
+
+ def test_delete_backup_with_no_service(self):
+ """Test error handling when attempting a delete of a backup
+ with no service defined for that backup, relates to bug #1162908"""
+ vol_id = self._create_volume_db_entry(size=1)
+ backup_id = self._create_backup_db_entry(status='deleting',
+ volume_id=vol_id)
+ db.backup_update(self.ctxt, backup_id, {'service': None})
+ self.backup_mgr.delete_backup(self.ctxt, backup_id)
def test_delete_backup(self):
"""Test normal backup deletion"""