]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware: Re-create session for RetrievePropertiesEx
authorKartik Bommepally <kbommepally@vmware.com>
Fri, 4 Oct 2013 11:05:09 +0000 (04:05 -0700)
committerKartik Bommepally <kbommepally@vmware.com>
Sat, 5 Oct 2013 07:10:02 +0000 (00:10 -0700)
When RetrievePropertiesEx API is called after session timeout, the driver
does not re-create session automatically.

This is a regression caused when moving from RetrieveProperties to
RetrievePropertiesEx API.

Fixes bug: 1235187

Change-Id: I8a1e2452dfb3029365d59eae7850d1a9363b25f0

cinder/tests/test_vmware_vmdk.py
cinder/volume/drivers/vmware/vim.py

index c974b200786f30a6bfa97467581d26ec0838181b..868e797e40ff8e397e3e89ca22d57b4c3a9cf165 100644 (file)
@@ -28,6 +28,7 @@ from cinder import units
 from cinder.volume import configuration
 from cinder.volume.drivers.vmware import api
 from cinder.volume.drivers.vmware import error_util
+from cinder.volume.drivers.vmware import vim
 from cinder.volume.drivers.vmware import vim_util
 from cinder.volume.drivers.vmware import vmdk
 from cinder.volume.drivers.vmware import vmware_images
@@ -1435,6 +1436,38 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase):
         m.UnsetStubs()
         m.VerifyAll()
 
+    def test_retrieve_properties_ex_fault_checker(self):
+        """Test retrieve_properties_ex_fault_checker is called."""
+        m = self.mox
+
+        class FakeVim(vim.Vim):
+            def __init__(self):
+                pass
+
+            @property
+            def client(self):
+
+                class FakeRetrv(object):
+                    def RetrievePropertiesEx(self, collector):
+                        pass
+
+                    def __getattr__(self, name):
+                        if name == 'service':
+                            return FakeRetrv()
+
+                return FakeRetrv()
+
+            def RetrieveServiceContent(self, type='ServiceInstance'):
+                return mox.MockAnything()
+
+        _vim = FakeVim()
+        m.ReplayAll()
+        # retrieve_properties_ex_fault_checker throws authentication error
+        self.assertRaises(error_util.VimFaultException,
+                          _vim.RetrievePropertiesEx, mox.IgnoreArg())
+        m.UnsetStubs()
+        m.VerifyAll()
+
 
 class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase):
     """Test class for VMwareVcVmdkDriver."""
index 7e08668a859513279ba3d3ca8d00d1029dbf47f2..d334d32be8f8ebab51121689f4133fe96d74066f 100644 (file)
@@ -118,19 +118,20 @@ class Vim(object):
     def __getattr__(self, attr_name):
         """Makes the API call and gets the result."""
 
-        def retrieve_properties_fault_checker(response):
-            """Checks the RetrieveProperties response for errors.
+        def retrieve_properties_ex_fault_checker(response):
+            """Checks the RetrievePropertiesEx response for errors.
 
             Certain faults are sent as part of the SOAP body as property of
             missingSet. For example NotAuthenticated fault. The method raises
             appropriate VimFaultException when an error is found.
 
-            :param response: Response from RetrieveProperties API call
+            :param response: Response from RetrievePropertiesEx API call
             """
+
             fault_list = []
             if not response:
                 # This is the case when the session has timed out. ESX SOAP
-                # server sends an empty RetrievePropertiesResponse. Normally
+                # server sends an empty RetrievePropertiesExResponse. Normally
                 # missingSet in the returnval field has the specifics about
                 # the error, but that's not the case with a timed out idle
                 # session. It is as bad as a terminated session for we cannot
@@ -150,7 +151,7 @@ class Vim(object):
                 raise error_util.VimFaultException(fault_list,
                                                    _("Error(s): %s occurred "
                                                      "in the call to "
-                                                     "RetrieveProperties.") %
+                                                     "RetrievePropertiesEx.") %
                                                    exc_msg_list)
 
         def vim_request_handler(managed_object, **kwargs):
@@ -163,15 +164,16 @@ class Vim(object):
             :param kwargs: Keyword arguments of the call
             :return: Response of the API call
             """
+
             try:
                 if isinstance(managed_object, str):
                     # For strings use string value for value and type
                     # of the managed object.
                     managed_object = get_moref(managed_object, managed_object)
-                request = getattr(self._client.service, attr_name)
+                request = getattr(self.client.service, attr_name)
                 response = request(managed_object, **kwargs)
-                if (attr_name.lower() == 'retrieveproperties'):
-                    retrieve_properties_fault_checker(response)
+                if (attr_name.lower() == 'retrievepropertiesex'):
+                    retrieve_properties_ex_fault_checker(response)
                 return response
 
             except error_util.VimFaultException as excep: