From 40849f168a705fd6db54c727a5f4cb6f8e521dcd Mon Sep 17 00:00:00 2001 From: Yuriy Nesenenko Date: Thu, 30 Jul 2015 15:56:10 +0300 Subject: [PATCH] Add support '--all-tenants' for cinder backup-list Cinder backup-list doesn't support '--all-tenants' argument for admin. So it is always listing all tenants's backups for admin not only admin's tenant. This patch fixes it. APIImpact Closes-Bug: #1435158 Related-Bug: #1422046 Change-Id: I73f6377c7d6fd92d0464d13f9c8dd6682fef78e3 --- cinder/backup/api.py | 8 +++++--- cinder/tests/unit/objects/test_backup.py | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cinder/backup/api.py b/cinder/backup/api.py index f04e1962d..d22a90be2 100644 --- a/cinder/backup/api.py +++ b/cinder/backup/api.py @@ -99,11 +99,13 @@ class API(base.Base): self.backup_rpcapi.delete_backup(context, backup) def get_all(self, context, search_opts=None): - if search_opts is None: - search_opts = {} check_policy(context, 'get_all') - if context.is_admin: + search_opts = search_opts or {} + + if (context.is_admin and 'all_tenants' in search_opts): + # Need to remove all_tenants to pass the filtering below. + search_opts.pop('all_tenants', None) backups = objects.BackupList.get_all(context, filters=search_opts) else: backups = objects.BackupList.get_all_by_project( diff --git a/cinder/tests/unit/objects/test_backup.py b/cinder/tests/unit/objects/test_backup.py index cbc8fd626..e3e80de42 100644 --- a/cinder/tests/unit/objects/test_backup.py +++ b/cinder/tests/unit/objects/test_backup.py @@ -109,3 +109,10 @@ class TestBackupList(test_objects.BaseObjectsTestCase): fake_volume_obj.id) self.assertEqual(1, len(backups)) TestBackup._compare(self, fake_backup, backups[0]) + + @mock.patch('cinder.db.backup_get_all', return_value=[fake_backup]) + def test_get_all_tenants(self, backup_get_all): + search_opts = {'all_tenants': 1} + backups = objects.BackupList.get_all(self.context, search_opts) + self.assertEqual(1, len(backups)) + TestBackup._compare(self, fake_backup, backups[0]) -- 2.45.2