]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
convert unicode to string before we connect to rados
authorLuo Gangyi <luogangyi@chinamobile.com>
Wed, 17 May 2017 05:16:29 +0000 (13:16 +0800)
committerLee Yarwood <lyarwood@redhat.com>
Mon, 22 May 2017 21:12:05 +0000 (21:12 +0000)
rados client only support string argument, therefore we have to
convert argument to string first.

closes-Bug: #1672792

Change-Id: I007c15dc61db9dbf7df7b8bea7c3dce49f0396f5
(cherry picked from commit 2f5ebdba5f9c5c1485d143c9ec5989c8fbe1e859)

nova/tests/unit/virt/libvirt/storage/test_rbd.py
nova/virt/libvirt/storage/rbd_utils.py

index 4cb2488a530fb421cd52923bc3ae2d145b96333b..504b4df0cd0bd6fc564f8be77dd92b2f3eaa419e 100644 (file)
@@ -310,6 +310,12 @@ class RbdTestCase(test.NoDBTestCase):
         mock_rados.Rados.open_ioctx.assert_called_once_with(self.rbd_pool)
         mock_rados.Rados.shutdown.assert_called_once_with()
 
+    @mock.patch.object(rbd_utils, 'rados')
+    def test_connect_to_rados_unicode_arg(self, mock_rados):
+        self.driver._connect_to_rados(u'unicode_pool')
+        self.mock_rados.Rados.open_ioctx.assert_called_with(
+            test.MatchType(str))
+
     def test_ceph_args_none(self):
         self.driver.rbd_user = None
         self.driver.ceph_conf = None
index 8388f0e24aacf80a401e9ab0c54b1977a1787233..dc082aa3b5770f23bad9f6db1224c885c0272f2e 100644 (file)
@@ -135,7 +135,11 @@ class RBDDriver(object):
         try:
             client.connect()
             pool_to_open = pool or self.pool
-            ioctx = client.open_ioctx(pool_to_open)
+            # NOTE(luogangyi): open_ioctx >= 10.1.0 could handle unicode
+            # arguments perfectly as part of Python 3 support.
+            # Therefore, when we turn to Python 3, it's safe to remove
+            # str() conversion.
+            ioctx = client.open_ioctx(str(pool_to_open))
             return client, ioctx
         except rados.Error:
             # shutdown cannot raise an exception