]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use elevated context for backup destroy
authorIvan Kolodyazhny <e0ne@e0ne.info>
Sat, 20 Jun 2015 20:02:41 +0000 (23:02 +0300)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Mon, 22 Jun 2015 18:33:39 +0000 (18:33 +0000)
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

cinder/backup/manager.py
cinder/objects/backup.py
cinder/tests/unit/objects/test_backup.py

index cbc0255e71259f36348287b0bd909c6ab069efd3..4c6d7e877b2a5270e079b66e1f3e565182326dac 100644 (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
index 9132b41818b6d572e72c8873073331dc8affc302..760a633fcac428fcf743d76c2c74c7db0bea04fa 100644 (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
index e6f08f6d40b8804e8baee754e43ef89706522b35..3db5aa0da5f9949087a5a7a07af29620bd02691a 100644 (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):