]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace urllib.unquote with urllib.parse.unquote
authorVipin Balachandran <vbala@vmware.com>
Wed, 26 Aug 2015 10:42:53 +0000 (16:12 +0530)
committerVipin Balachandran <vbala@vmware.com>
Wed, 26 Aug 2015 10:42:53 +0000 (16:12 +0530)
This patch replaces urllib.unquote with urllib.parse.unquote
in the vmdk driver.

Commit d08c7ffe52e3ee211e425c363200998704726e58 replaced
urllib and urllib2 with six.moves.urllib and changed urllib.
unquote to urllib.parse.unquote but missed one call site
in the vmdk driver since the code which introduced it was
under review at the same time. Due to this, if we set an
optional parameter 'vmware_cluster_name', the driver init
will fail with AttributeError.

This patch also adds a unit test which would have caught
this error during gate check.

Change-Id: I310456f5d677c6e100a91efc6228c533cb5bf208
Closes-Bug: #1488916

cinder/tests/unit/test_vmware_volumeops.py
cinder/volume/drivers/vmware/volumeops.py

index fbad28415361013b189c9b2015dd1d31c30d7ca6..5d1989cf2c808dd5bbc4bacd515a280b9359a7c7 100644 (file)
@@ -1630,6 +1630,26 @@ class VolumeOpsTestCase(test.TestCase):
                                                         cluster,
                                                         'host')
 
+    @mock.patch('cinder.volume.drivers.vmware.volumeops.VMwareVolumeOps.'
+                'continue_retrieval', return_value=None)
+    def test_get_all_clusters(self, continue_retrieval):
+        prop_1 = mock.Mock(val='test_cluster_1')
+        cls_1 = mock.Mock(propSet=[prop_1], obj=mock.sentinel.mor_1)
+        prop_2 = mock.Mock(val='/test_cluster_2')
+        cls_2 = mock.Mock(propSet=[prop_2], obj=mock.sentinel.mor_2)
+
+        retrieve_result = mock.Mock(objects=[cls_1, cls_2])
+        self.session.invoke_api.return_value = retrieve_result
+
+        ret = self.vops._get_all_clusters()
+        exp = {'test_cluster_1': mock.sentinel.mor_1,
+               '/test_cluster_2': mock.sentinel.mor_2}
+        self.assertEqual(exp, ret)
+        self.session.invoke_api.assert_called_once_with(
+            vim_util, 'get_objects', self.session.vim,
+            'ClusterComputeResource', self.MAX_OBJECTS)
+        continue_retrieval.assert_called_once_with(retrieve_result)
+
 
 class VirtualDiskPathTest(test.TestCase):
     """Unit tests for VirtualDiskPath."""
index 47172e5c5699aed5c5aeaced64e0191b1b88d78c..7997eacab5cee0cbd13ab203dd62d0792397c040 100644 (file)
@@ -1481,7 +1481,7 @@ class VMwareVolumeOps(object):
         while retrieve_result:
             if retrieve_result.objects:
                 for cluster in retrieve_result.objects:
-                    name = urllib.unquote(cluster.propSet[0].val)
+                    name = urllib.parse.unquote(cluster.propSet[0].val)
                     clusters[name] = cluster.obj
             retrieve_result = self.continue_retrieval(retrieve_result)
         return clusters