From: Vipin Balachandran Date: Wed, 26 Aug 2015 10:42:53 +0000 (+0530) Subject: Replace urllib.unquote with urllib.parse.unquote X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f90bcd4964d646bdad67a2cb012bd7eb499f85f9;p=openstack-build%2Fcinder-build.git Replace urllib.unquote with urllib.parse.unquote 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 --- diff --git a/cinder/tests/unit/test_vmware_volumeops.py b/cinder/tests/unit/test_vmware_volumeops.py index fbad28415..5d1989cf2 100644 --- a/cinder/tests/unit/test_vmware_volumeops.py +++ b/cinder/tests/unit/test_vmware_volumeops.py @@ -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.""" diff --git a/cinder/volume/drivers/vmware/volumeops.py b/cinder/volume/drivers/vmware/volumeops.py index 47172e5c5..7997eacab 100644 --- a/cinder/volume/drivers/vmware/volumeops.py +++ b/cinder/volume/drivers/vmware/volumeops.py @@ -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