diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index c1206f5ef5d..27d9115b166 100644 --- a/cinder/backup/drivers/ceph.py +++ b/cinder/backup/drivers/ceph.py @@ -616,7 +616,7 @@ class CephBackupDriver(driver.BackupDriver): return False for snap in snaps: - if snap.name == snap_name: + if snap['name'] == snap_name: return True return False diff --git a/cinder/tests/unit/backup/drivers/test_backup_ceph.py b/cinder/tests/unit/backup/drivers/test_backup_ceph.py index d0a52352a62..74371e5746c 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_ceph.py +++ b/cinder/tests/unit/backup/drivers/test_backup_ceph.py @@ -19,6 +19,7 @@ import os import tempfile import uuid +import ddt import mock from os_brick.initiator import linuxrbd from oslo_concurrency import processutils @@ -102,6 +103,7 @@ def common_mocks(f): return _common_inner_inner1 +@ddt.ddt class BackupCephTestCase(test.TestCase): """Test case for ceph backup driver.""" @@ -1151,6 +1153,19 @@ class BackupCephTestCase(test.TestCase): self.assertTrue(self.mock_rados.Object.return_value.read.called) + @ddt.data((None, False), + ([{'name': 'test'}], False), + ([{'name': 'test'}, {'name': 'fake'}], True)) + @ddt.unpack + @common_mocks + def test__snap_exists(self, snapshots, snap_exist): + client = mock.Mock() + with mock.patch.object(self.service.rbd.Image(), + 'list_snaps') as snaps: + snaps.return_value = snapshots + exist = self.service._snap_exists(None, 'fake', client) + self.assertEqual(snap_exist, exist) + def common_meta_backup_mocks(f): """Decorator to set mocks common to all metadata backup tests.