From 3e2a593ae9eb80d9753cd118e59008a77a315c11 Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Wed, 12 Apr 2017 01:15:30 +0800 Subject: [PATCH] Fix wrong usage of rbd.list_snaps return value the return value of rbd.list_snaps is a generator with dict. Co-Authored-By: Ivan Kolodyazhny Change-Id: Id3576a52e253ed242685999e96d638e98ce605bf Closes-Bug: #1681895 --- cinder/backup/drivers/ceph.py | 2 +- .../tests/unit/backup/drivers/test_backup_ceph.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index 88a1605b9ea..0f2eb9ef65b 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 de0e7cdd4ae..f3867419921 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 @@ -101,6 +102,7 @@ def common_mocks(f): return _common_inner_inner1 +@ddt.ddt class BackupCephTestCase(test.TestCase): """Test case for ceph backup driver.""" @@ -1135,6 +1137,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.