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 <e0ne@e0ne.info>
Change-Id: Id3576a52e253ed242685999e96d638e98ce605bf
Closes-Bug: #1681895
(cherry picked from commit 3e2a593ae9)
This commit is contained in:
Jeffrey Zhang 2017-04-12 01:15:30 +08:00 committed by melanie witt
parent 0a78c4af4b
commit 197f33bcd0
2 changed files with 16 additions and 1 deletions

View File

@ -585,7 +585,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

View File

@ -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
@ -98,6 +99,7 @@ def common_mocks(f):
return _common_inner_inner1
@ddt.ddt
class BackupCephTestCase(test.TestCase):
"""Test case for ceph backup driver."""
@ -1105,6 +1107,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.