Use elevated context for backup destroy

db.backup_destroy requires admin context to mark backup record as
deleted. Commit Icff37261b367463b71a1268be16f9c97f595bf0c removed admin
context passed to backup_destroy method.

This patch uses elevated context to destroy backup.
Change-Id: I75b9e1fff48569a8aa320f2f02914fc7b6665d79
Closes-Bug: #1467167
This commit is contained in:
Ivan Kolodyazhny 2015-06-20 23:02:41 +03:00
parent 4ea25fa280
commit fb2c5e9937
3 changed files with 14 additions and 3 deletions

View File

@ -456,7 +456,6 @@ class BackupManager(manager.SchedulerDependentManager):
reservations = None
LOG.exception(_LE("Failed to update usages deleting backup"))
context = context.elevated()
backup.destroy()
# Commit the reservations

View File

@ -105,7 +105,8 @@ class Backup(base.CinderPersistentObject, base.CinderObject,
@base.remotable
def destroy(self):
db.backup_destroy(self._context, self.id)
with self.obj_as_admin():
db.backup_destroy(self._context, self.id)
@base.CinderObjectRegistry.register

View File

@ -14,6 +14,7 @@
import mock
from cinder import context
from cinder import objects
from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects
@ -32,6 +33,14 @@ fake_backup = {
class TestBackup(test_objects.BaseObjectsTestCase):
def setUp(self):
super(TestBackup, self).setUp()
# NOTE (e0ne): base tests contains original RequestContext from
# oslo_context. We change it to our RequestContext implementation
# to have 'elevated' method
self.context = context.RequestContext(self.user_id, self.project_id,
is_admin=False)
@staticmethod
def _compare(test, db, obj):
for field, value in db.items():
@ -62,7 +71,9 @@ class TestBackup(test_objects.BaseObjectsTestCase):
def test_destroy(self, backup_destroy):
backup = objects.Backup(context=self.context, id=1)
backup.destroy()
backup_destroy.assert_called_once_with(self.context, '1')
self.assertTrue(backup_destroy.called)
admin_context = backup_destroy.call_args[0][0]
self.assertTrue(admin_context.is_admin)
class TestBackupList(test_objects.BaseObjectsTestCase):