]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix unit test test_import_record_with_verify
authorMarc Koderer <marc@koderer.com>
Thu, 31 Jul 2014 08:10:17 +0000 (10:10 +0200)
committerMarc Koderer <marc@koderer.com>
Tue, 5 Aug 2014 12:45:55 +0000 (14:45 +0200)
The test case test_import_record_with_verify is intended to call a
backup service class with a defined verify function. This verify
function wasn't overloaded by the fake service.

Change-Id: Ib5738e9c463856dd71a47717b7abb8dff785b3b1
Closes-bug: #1350699

cinder/tests/backup/fake_service_with_verify.py [new file with mode: 0644]
cinder/tests/test_backup.py

diff --git a/cinder/tests/backup/fake_service_with_verify.py b/cinder/tests/backup/fake_service_with_verify.py
new file mode 100644 (file)
index 0000000..32695c1
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright (C) 2014 Deutsche Telekom AG
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from cinder.openstack.common import log as logging
+from cinder.tests.backup import fake_service
+
+LOG = logging.getLogger(__name__)
+
+
+class FakeBackupServiceWithVerify(fake_service.FakeBackupService):
+    def verify(self, backup):
+        pass
+
+
+def get_backup_driver(context):
+    return FakeBackupServiceWithVerify(context)
index dd0b604a6596f14cf074becff98484ac6dba1d99..8b6af7abb681eb9786eb25ac2e11032b19b76d69 100644 (file)
@@ -40,11 +40,9 @@ class FakeBackupException(Exception):
     pass
 
 
-class BackupTestCase(test.TestCase):
-    """Test Case for backups."""
-
+class BaseBackupTest(test.TestCase):
     def setUp(self):
-        super(BackupTestCase, self).setUp()
+        super(BaseBackupTest, self).setUp()
         vol_tmpdir = tempfile.mkdtemp()
         self.flags(volumes_dir=vol_tmpdir)
         self.backup_mgr = \
@@ -124,6 +122,10 @@ class BackupTestCase(test.TestCase):
         backup['status'] = status
         return db.backup_create(self.ctxt, backup)['id']
 
+
+class BackupTestCase(BaseBackupTest):
+    """Test Case for backups."""
+
     def test_init_host(self):
         """Make sure stuck volumes and backups are reset to correct
         states when backup_manager.init_host() is called
@@ -484,31 +486,6 @@ class BackupTestCase(test.TestCase):
         self.assertEqual(backup['status'], 'available')
         self.assertEqual(backup['size'], vol_size)
 
-    def test_import_record_with_verify(self):
-        """Test normal backup record import.
-
-        Test the case when import succeeds for the case that the
-        driver implements verify.
-        """
-        vol_size = 1
-        export = self._create_exported_record_entry(vol_size=vol_size)
-        imported_record = self._create_export_record_db_entry()
-        backup_hosts = []
-        backup_driver = self.backup_mgr.service.get_backup_driver(self.ctxt)
-        _mock_backup_verify_class = ('%s.%s.%s' %
-                                     (backup_driver.__module__,
-                                      backup_driver.__class__.__name__,
-                                      'verify'))
-        with mock.patch(_mock_backup_verify_class):
-            self.backup_mgr.import_record(self.ctxt,
-                                          imported_record,
-                                          export['backup_service'],
-                                          export['backup_url'],
-                                          backup_hosts)
-        backup = db.backup_get(self.ctxt, imported_record)
-        self.assertEqual(backup['status'], 'available')
-        self.assertEqual(backup['size'], vol_size)
-
     def test_import_record_with_bad_service(self):
         """Test error handling when attempting an import of a backup
         record with a different service to that used to create the backup.
@@ -564,6 +541,40 @@ class BackupTestCase(test.TestCase):
         backup = db.backup_get(self.ctxt, imported_record)
         self.assertEqual(backup['status'], 'error')
 
+
+class BackupTestCaseWithVerify(BaseBackupTest):
+    """Test Case for backups."""
+
+    def setUp(self):
+        CONF.set_override("backup_driver",
+                          "cinder.tests.backup.fake_service_with_verify")
+        super(BackupTestCaseWithVerify, self).setUp()
+
+    def test_import_record_with_verify(self):
+        """Test normal backup record import.
+
+        Test the case when import succeeds for the case that the
+        driver implements verify.
+        """
+        vol_size = 1
+        export = self._create_exported_record_entry(vol_size=vol_size)
+        imported_record = self._create_export_record_db_entry()
+        backup_hosts = []
+        backup_driver = self.backup_mgr.service.get_backup_driver(self.ctxt)
+        _mock_backup_verify_class = ('%s.%s.%s' %
+                                     (backup_driver.__module__,
+                                      backup_driver.__class__.__name__,
+                                      'verify'))
+        with mock.patch(_mock_backup_verify_class):
+            self.backup_mgr.import_record(self.ctxt,
+                                          imported_record,
+                                          export['backup_service'],
+                                          export['backup_url'],
+                                          backup_hosts)
+        backup = db.backup_get(self.ctxt, imported_record)
+        self.assertEqual(backup['status'], 'available')
+        self.assertEqual(backup['size'], vol_size)
+
     def test_import_record_with_verify_invalid_backup(self):
         """Test error handling when attempting an import of a backup
         record where the backup driver returns an exception.