From: Kartik Bommepally Date: Fri, 4 Oct 2013 11:05:09 +0000 (-0700) Subject: VMware: Re-create session for RetrievePropertiesEx X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=46afd20ac76d5c947c33395eeff80b53e6493a98;p=openstack-build%2Fcinder-build.git VMware: Re-create session for RetrievePropertiesEx 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 (cherry picked from commit 2d4ea101252141486fa6fd61b100772fafd40102) --- diff --git a/cinder/tests/test_vmware_vmdk.py b/cinder/tests/test_vmware_vmdk.py index c974b2007..868e797e4 100644 --- a/cinder/tests/test_vmware_vmdk.py +++ b/cinder/tests/test_vmware_vmdk.py @@ -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.""" diff --git a/cinder/volume/drivers/vmware/vim.py b/cinder/volume/drivers/vmware/vim.py index 7e08668a8..d334d32be 100644 --- a/cinder/volume/drivers/vmware/vim.py +++ b/cinder/volume/drivers/vmware/vim.py @@ -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: