From 8f045d2dd2cb84099dd54701e9d27b12a779e191 Mon Sep 17 00:00:00 2001 From: Michael Kerrin Date: Tue, 16 Apr 2013 08:09:35 +0000 Subject: [PATCH] Cinder wasn't filtering the backups returned to backup list API This has the side effect of return all backups in the system (regardless of who created them) to the user. You should only see the backups created in your current active project. Fixes bug: 1169461 Change-Id: I121e8ed215b28f1b21e24b2104f8294039e09b48 --- cinder/db/sqlalchemy/api.py | 3 ++- cinder/tests/test_backup.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index c931dd900..96dccc7d8 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1957,7 +1957,8 @@ def backup_get_all_by_host(context, host): def backup_get_all_by_project(context, project_id): authorize_project_context(context, project_id) - return model_query(context, models.Backup, read_deleted="yes").all() + return model_query(context, models.Backup, read_deleted="yes").\ + filter_by(project_id=project_id).all() @require_context diff --git a/cinder/tests/test_backup.py b/cinder/tests/test_backup.py index 8ffe9006c..70a836118 100644 --- a/cinder/tests/test_backup.py +++ b/cinder/tests/test_backup.py @@ -56,7 +56,8 @@ class BackupTestCase(test.TestCase): container='volumebackups', status='creating', size=0, - object_count=0): + object_count=0, + project_id='fake'): """ Create a backup entry in the DB. Return the entry ID @@ -64,7 +65,7 @@ class BackupTestCase(test.TestCase): backup = {} backup['volume_id'] = volume_id backup['user_id'] = 'fake' - backup['project_id'] = 'fake' + backup['project_id'] = project_id backup['host'] = 'testhost' backup['availability_zone'] = '1' backup['display_name'] = display_name @@ -339,3 +340,13 @@ class BackupTestCase(test.TestCase): db.backup_get, self.ctxt, backup_id) + + def test_list_backup(self): + backups = db.backup_get_all_by_project(self.ctxt, 'project1') + self.assertEqual(len(backups), 0) + + b1 = self._create_backup_db_entry() + b2 = self._create_backup_db_entry(project_id='project1') + backups = db.backup_get_all_by_project(self.ctxt, 'project1') + self.assertEqual(len(backups), 1) + self.assertEqual(backups[0].id, b2) -- 2.45.2