Browse Source

VMware: Fix initialization of datastore selector

The WSDL URL of storage policy service is determined and a session is
created using it in do_setup(). This session is later used to initialize
the datastore selector property (ds_sel), which uses the session for all
storage policy related API calls.

After commit a8fa3ceb1e (Integrate
OSprofiler and Cinder), the properties defined in vmdk module are called
before do_setup(). As a result, the ds_sel (datastore selector) property
is initialized with a session instance containing a 'None' PBM (storage
policy service) WSDL URL. This results in failures of all storage policy
related APIs invoked using datastore selector. This patch fixes the
problem by re-initializing the property in do_setup().

Change-Id: Ibdf8b23f9e215000cf9053b81d374066fabd6851
Closes-Bug: #1380675
tags/2015.1.0b1
Vipin Balachandran 4 years ago
parent
commit
6ac6225e72
2 changed files with 41 additions and 22 deletions
  1. 38
    21
      cinder/tests/test_vmware_vmdk.py
  2. 3
    1
      cinder/volume/drivers/vmware/vmdk.py

+ 38
- 21
cinder/tests/test_vmware_vmdk.py View File

@@ -1956,44 +1956,61 @@ class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase):
1956 1956
         version = self._driver._get_vc_version()
1957 1957
         self.assertEqual(LooseVersion('6.0.1'), version)
1958 1958
 
1959
-    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1960
-                '_get_pbm_wsdl_location')
1961 1959
     @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1962 1960
                 '_get_vc_version')
1963 1961
     @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1964 1962
                 'session', new_callable=mock.PropertyMock)
1965
-    def test_do_setup(self, session, _get_vc_version, _get_pbm_wsdl_location):
1966
-        session = session.return_value
1963
+    def test_do_setup_with_pbm_disabled(self, session, get_vc_version):
1964
+        session_obj = mock.Mock(name='session')
1965
+        session.return_value = session_obj
1966
+        get_vc_version.return_value = LooseVersion('5.0')
1967 1967
 
1968
-        # pbm is disabled
1969
-        vc_version = LooseVersion('5.0')
1970
-        _get_vc_version.return_value = vc_version
1971 1968
         self._driver.do_setup(mock.ANY)
1969
+
1972 1970
         self.assertFalse(self._driver._storage_policy_enabled)
1973
-        _get_vc_version.assert_called_once_with()
1971
+        get_vc_version.assert_called_once_with()
1972
+        self.assertEqual(session_obj, self._driver.volumeops._session)
1973
+        self.assertEqual(session_obj, self._driver.ds_sel._session)
1974 1974
 
1975
-        # pbm is enabled and invalid pbm wsdl location
1975
+    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1976
+                '_get_pbm_wsdl_location')
1977
+    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1978
+                '_get_vc_version')
1979
+    def test_do_setup_with_invalid_pbm_wsdl(self, get_vc_version,
1980
+                                            get_pbm_wsdl_location):
1976 1981
         vc_version = LooseVersion('5.5')
1977
-        _get_vc_version.reset_mock()
1978
-        _get_vc_version.return_value = vc_version
1979
-        _get_pbm_wsdl_location.return_value = None
1982
+        get_vc_version.return_value = vc_version
1983
+        get_pbm_wsdl_location.return_value = None
1984
+
1980 1985
         self.assertRaises(error_util.VMwareDriverException,
1981 1986
                           self._driver.do_setup,
1982 1987
                           mock.ANY)
1988
+
1983 1989
         self.assertFalse(self._driver._storage_policy_enabled)
1984
-        _get_vc_version.assert_called_once_with()
1985
-        _get_pbm_wsdl_location.assert_called_once_with(vc_version)
1990
+        get_vc_version.assert_called_once_with()
1991
+        get_pbm_wsdl_location.assert_called_once_with(vc_version)
1992
+
1993
+    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1994
+                '_get_pbm_wsdl_location')
1995
+    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1996
+                '_get_vc_version')
1997
+    @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
1998
+                'session', new_callable=mock.PropertyMock)
1999
+    def test_do_setup(self, session, get_vc_version, get_pbm_wsdl_location):
2000
+        session_obj = mock.Mock(name='session')
2001
+        session.return_value = session_obj
1986 2002
 
1987
-        # pbm is enabled and valid pbm wsdl location
1988 2003
         vc_version = LooseVersion('5.5')
1989
-        _get_vc_version.reset_mock()
1990
-        _get_vc_version.return_value = vc_version
1991
-        _get_pbm_wsdl_location.reset_mock()
1992
-        _get_pbm_wsdl_location.return_value = 'fake_pbm_location'
2004
+        get_vc_version.return_value = vc_version
2005
+        get_pbm_wsdl_location.return_value = 'file:///pbm.wsdl'
2006
+
1993 2007
         self._driver.do_setup(mock.ANY)
2008
+
1994 2009
         self.assertTrue(self._driver._storage_policy_enabled)
1995
-        _get_vc_version.assert_called_once_with()
1996
-        _get_pbm_wsdl_location.assert_called_once_with(vc_version)
2010
+        get_vc_version.assert_called_once_with()
2011
+        get_pbm_wsdl_location.assert_called_once_with(vc_version)
2012
+        self.assertEqual(session_obj, self._driver.volumeops._session)
2013
+        self.assertEqual(session_obj, self._driver.ds_sel._session)
1997 2014
 
1998 2015
     @mock.patch.object(VMDK_DRIVER, '_extend_volumeops_virtual_disk')
1999 2016
     @mock.patch.object(VMDK_DRIVER, '_create_backing_in_inventory')

+ 3
- 1
cinder/volume/drivers/vmware/vmdk.py View File

@@ -1894,9 +1894,11 @@ class VMwareVcVmdkDriver(VMwareEsxVmdkDriver):
1894 1894
             # Destroy current session so that it is recreated with pbm enabled
1895 1895
             self._session = None
1896 1896
 
1897
-        # recreate session and initialize volumeops
1897
+        # recreate session and initialize volumeops and ds_sel
1898
+        # TODO(vbala) remove properties: session, volumeops and ds_sel
1898 1899
         max_objects = self.configuration.vmware_max_objects_retrieval
1899 1900
         self._volumeops = volumeops.VMwareVolumeOps(self.session, max_objects)
1901
+        self._ds_sel = hub.DatastoreSelector(self.volumeops, self.session)
1900 1902
 
1901 1903
         LOG.info(_("Successfully setup driver: %(driver)s for server: "
1902 1904
                    "%(ip)s.") % {'driver': self.__class__.__name__,

Loading…
Cancel
Save