Merge "Port libvirt.storage.test_rbd to Python 3"

This commit is contained in:
Jenkins 2016-12-19 17:41:13 +00:00 committed by Gerrit Code Review
commit 4b71d7e221
3 changed files with 22 additions and 6 deletions

View File

@ -13,6 +13,7 @@
from eventlet import tpool
import mock
import six
from nova.compute import task_states
from nova import exception
@ -52,6 +53,10 @@ CEPH_MON_DUMP = """dumped monmap epoch 1
"""
class FakeException(Exception):
pass
class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'rbd')
@ -198,6 +203,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_clone(self, mock_rados, mock_rbd, mock_client):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
pool = u'images'
image = u'image-name'
snap = u'snapshot-name'
@ -219,7 +226,7 @@ class RbdTestCase(test.NoDBTestCase):
self.driver.clone(location, self.volume_name)
args = [client_stack[0].ioctx, str(image), str(snap),
args = [client_stack[0].ioctx, six.b(image), six.b(snap),
client_stack[1].ioctx, str(self.volume_name)]
kwargs = {'features': client.features}
rbd.clone.assert_called_once_with(*args, **kwargs)
@ -339,6 +346,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'rados')
@mock.patch.object(rbd_utils, 'RADOSClient')
def test_cleanup_volumes(self, mock_client, mock_rados, mock_rbd):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
instance = objects.Instance(id=1, uuid=uuids.instance,
task_state=None)
# this is duplicated from nova/virt/libvirt/driver.py
@ -360,6 +369,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'RADOSClient')
def _test_cleanup_exception(self, exception_name,
mock_client, mock_rados, mock_rbd):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
instance = objects.Instance(id=1, uuid=uuids.instance,
task_state=None)
# this is duplicated from nova/virt/libvirt/driver.py
@ -393,6 +404,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'RBDVolumeProxy')
def test_cleanup_volumes_pending_resize(self, mock_proxy, mock_client,
mock_rados, mock_rbd):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
instance = objects.Instance(id=1, uuid=uuids.instance,
task_state=None)
# this is duplicated from nova/virt/libvirt/driver.py
@ -421,6 +434,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'RADOSClient')
def test_cleanup_volumes_reverting_resize(self, mock_client, mock_rados,
mock_rbd):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
instance = objects.Instance(id=1, uuid=uuids.instance,
task_state=task_states.RESIZE_REVERTING)
# this is duplicated from nova/virt/libvirt/driver.py
@ -443,6 +458,8 @@ class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'rados')
@mock.patch.object(rbd_utils, 'RADOSClient')
def test_destroy_volume(self, mock_client, mock_rados, mock_rbd):
mock_rbd.ImageBusy = FakeException
mock_rbd.ImageHasSnapshots = FakeException
rbd = mock_rbd.RBD.return_value
vol = '12345_test'
client = mock_client.return_value

View File

@ -121,11 +121,11 @@ class RADOSClient(object):
class RBDDriver(object):
def __init__(self, pool, ceph_conf, rbd_user):
self.pool = pool.encode('utf8')
self.pool = pool
# NOTE(angdraug): rados.Rados fails to connect if ceph_conf is None:
# https://github.com/ceph/ceph/pull/1787
self.ceph_conf = ceph_conf.encode('utf8') if ceph_conf else ''
self.rbd_user = rbd_user.encode('utf8') if rbd_user else None
self.ceph_conf = ceph_conf or ''
self.rbd_user = rbd_user or None
if rbd is None:
raise RuntimeError(_('rbd python libraries not found'))
@ -135,7 +135,7 @@ class RBDDriver(object):
try:
client.connect()
pool_to_open = pool or self.pool
ioctx = client.open_ioctx(pool_to_open.encode('utf-8'))
ioctx = client.open_ioctx(pool_to_open)
return client, ioctx
except rados.Error:
# shutdown cannot raise an exception

View File

@ -13,7 +13,6 @@ nova.tests.unit.compute.test_host_api.ComputeHostAPICellsTestCase
nova.tests.unit.network.test_manager.LdapDNSTestCase
nova.tests.unit.test_matchers.TestDictMatches.test__str__
nova.tests.unit.test_wsgi.TestWSGIServerWithSSL
nova.tests.unit.virt.libvirt.storage.test_rbd.RbdTestCase
nova.tests.unit.virt.libvirt.test_firewall.IptablesFirewallTestCase
nova.tests.unit.virt.libvirt.test_imagebackend.EncryptedLvmTestCase
nova.tests.unit.virt.libvirt.test_imagebackend.LvmTestCase