]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove driver.set_execute()
authorEric Harney <eharney@redhat.com>
Wed, 26 Aug 2015 19:11:59 +0000 (15:11 -0400)
committerEric Harney <eharney@redhat.com>
Thu, 27 Aug 2015 20:09:30 +0000 (16:09 -0400)
This method doesn't appear to really be needed,
and mostly exists to help unit tests.  Update a
few tests to mock out the required execute calls,
and remove the method to make the driver interface
a bit simpler.

Change-Id: I70d8a7e74761ce7bc1e51bf9f3c49eb0ce0986e0

12 files changed:
cinder/tests/unit/test_glusterfs.py
cinder/tests/unit/test_gpfs.py
cinder/tests/unit/test_scality.py
cinder/tests/unit/test_srb.py
cinder/tests/unit/test_volume.py
cinder/volume/driver.py
cinder/volume/drivers/glusterfs.py
cinder/volume/drivers/hitachi/hnas_nfs.py
cinder/volume/drivers/ibm/ibmnas.py
cinder/volume/drivers/netapp/dataontap/nfs_base.py
cinder/volume/drivers/nfs.py
cinder/volume/drivers/srb.py

index 776acafa28f0fd8fc566556839d585b2233b0f77..0f19d50967032d3fca116b5a89283a67ef4bc77b 100644 (file)
@@ -119,19 +119,6 @@ class GlusterFsDriverTestCase(test.TestCase):
         if not caught:
             self.fail('Expected raised exception but nothing caught.')
 
-    def test_set_execute(self):
-        drv = self._driver
-
-        rfsclient = os_brick.remotefs.remotefs.RemoteFsClient
-
-        with mock.patch.object(rfsclient, 'set_execute') as mock_set_execute:
-            def my_execute(*a, **k):
-                pass
-
-            drv.set_execute(my_execute)
-
-            mock_set_execute.assert_called_once_with(my_execute)
-
     def test_local_path(self):
         """local_path common use case."""
         self.override_config("glusterfs_mount_point_base",
index 2114f41df6642a757e38a00e8f527997dabb0041..23698e25ed335e686ed450c10d1b949223afa917 100644 (file)
@@ -65,7 +65,10 @@ class GPFSDriverTestCase(test.TestCase):
 
         self.driver = gpfs.GPFSDriver(configuration=conf.Configuration(None))
         self.driver.gpfs_execute = self._execute_wrapper
-        self.driver.set_execute(self._execute_wrapper)
+        exec_patcher = mock.patch.object(self.driver, '_execute',
+                                         self._execute_wrapper)
+        exec_patcher.start()
+        self.addCleanup(exec_patcher.stop)
         self.driver._cluster_id = '123456'
         self.driver._gpfs_device = '/dev/gpfs'
         self.driver._storage_pool = 'system'
@@ -1915,7 +1918,6 @@ class GPFSNFSDriverTestCase(test.TestCase):
         self.driver = gpfs.GPFSNFSDriver(configuration=conf.
                                          Configuration(None))
         self.driver.gpfs_execute = self._execute_wrapper
-        self.driver.set_execute(self._execute_wrapper)
         self.context = context.get_admin_context()
         self.context.user_id = 'fake'
         self.context.project_id = 'fake'
index d7cd462e7ffad8fafcd3314edc0ed5371bfd9c7d..c82cd9d655acdeda27ce94bb39d0482b5ef663ec 100644 (file)
@@ -82,6 +82,10 @@ class ScalityDriverTestCase(test.TestCase):
 
         self.assertRaises(exception.VolumeBackendAPIException,
                           self.drv.check_for_setup_error)
+        exec_patcher = mock.patch.object(self.drv, '_execute',
+                                         mock.MagicMock())
+        exec_patcher.start()
+        self.addCleanup(exec_patcher.stop)
 
     @mock.patch.object(driver.urllib.request, 'urlopen')
     def test_check_for_setup_error_with_urlerror(self, mock_urlopen):
index dd82f767871b35c9262119b5884e760c5f3875a2..a5cb94ade733171e501fa2c246555ecfb36685af 100644 (file)
@@ -56,52 +56,51 @@ class SRBLvmTestCase(test_brick_lvm.BrickLvmTestCase):
             raise AssertionError('unexpected command called: %s' % cmd_string)
 
     def test_activate_vg(self):
-        executor = mock.MagicMock()
-        self.vg.set_execute(executor)
-        self.vg.activate_vg()
-        executor.assert_called_once_with('vgchange', '-ay',
-                                         self.configuration.volume_group_name,
-                                         root_helper=self.vg._root_helper,
-                                         run_as_root=True)
+        with mock.patch.object(self.vg, '_execute') as executor:
+            self.vg.activate_vg()
+            executor.assert_called_once_with(
+                'vgchange', '-ay',
+                self.configuration.volume_group_name,
+                root_helper=self.vg._root_helper,
+                run_as_root=True)
 
     def test_deactivate_vg(self):
-        executor = mock.MagicMock()
-        self.vg.set_execute(executor)
-        self.vg.deactivate_vg()
-        executor.assert_called_once_with('vgchange', '-an',
-                                         self.configuration.volume_group_name,
-                                         root_helper=self.vg._root_helper,
-                                         run_as_root=True)
+        with mock.patch.object(self.vg, '_execute') as executor:
+            self.vg.deactivate_vg()
+            executor.assert_called_once_with(
+                'vgchange', '-an',
+                self.configuration.volume_group_name,
+                root_helper=self.vg._root_helper,
+                run_as_root=True)
 
     def test_destroy_vg(self):
-        executor = mock.MagicMock()
-        self.vg.set_execute(executor)
-        self.vg.destroy_vg()
-        executor.assert_called_once_with('vgremove', '-f',
-                                         self.configuration.volume_group_name,
-                                         root_helper=self.vg._root_helper,
-                                         run_as_root=True)
+        with mock.patch.object(self.vg, '_execute') as executor:
+            self.vg.destroy_vg()
+            executor.assert_called_once_with(
+                'vgremove', '-f',
+                self.configuration.volume_group_name,
+                root_helper=self.vg._root_helper,
+                run_as_root=True)
 
     def test_pv_resize(self):
-        executor = mock.MagicMock()
-        self.vg.set_execute(executor)
-        self.vg.pv_resize('fake-pv', '50G')
-        executor.assert_called_once_with('pvresize',
-                                         '--setphysicalvolumesize',
-                                         '50G', 'fake-pv',
-                                         root_helper=self.vg._root_helper,
-                                         run_as_root=True)
+        with mock.patch.object(self.vg, '_execute') as executor:
+            self.vg.pv_resize('fake-pv', '50G')
+            executor.assert_called_once_with(
+                'pvresize',
+                '--setphysicalvolumesize',
+                '50G', 'fake-pv',
+                root_helper=self.vg._root_helper,
+                run_as_root=True)
 
     def test_extend_thin_pool_nothin(self):
-        executor =\
-            mock.MagicMock(side_effect=Exception('Unexpected call to execute'))
-        self.vg.set_execute(executor)
-        thin_calc =\
-            mock.MagicMock(
-                side_effect=
-                Exception('Unexpected call to _calculate_thin_pool_size'))
-        self.vg._calculate_thin_pool_size = thin_calc
-        self.vg.extend_thin_pool()
+        with mock.patch.object(self.vg, '_execute') as executor:
+            executor.side_effect = AssertionError
+            thin_calc =\
+                mock.MagicMock(
+                    side_effect=
+                    Exception('Unexpected call to _calculate_thin_pool_size'))
+            self.vg._calculate_thin_pool_size = thin_calc
+            self.vg.extend_thin_pool()
 
     def test_extend_thin_pool_thin(self):
         self.stubs.Set(processutils, 'execute', self.fake_execute)
@@ -737,7 +736,11 @@ class SRBDriverTestCase(test.TestCase):
         self._driver = srb.SRBDriver(configuration=self.configuration)
         # Stub processutils.execute for static methods
         self.stubs.Set(processutils, 'execute', self._fake_execute)
-        self._driver.set_execute(self._fake_execute)
+        exec_patcher = mock.patch.object(self._driver,
+                                         '_execute',
+                                         self._fake_execute)
+        exec_patcher.start()
+        self.addCleanup(exec_patcher.stop)
         self._configure_driver()
 
     def test_setup(self):
index 256c272090bebfa52b67161bf5f00792154d7dc1..00246389ef080dac9bd0f84a03f42fde174bc0dd 100644 (file)
@@ -5616,7 +5616,10 @@ class DriverTestCase(test.TestCase):
         def _fake_execute(_command, *_args, **_kwargs):
             """Fake _execute."""
             return self.output, None
-        self.volume.driver.set_execute(_fake_execute)
+        exec_patcher = mock.patch.object(self.volume.driver, '_execute',
+                                         _fake_execute)
+        exec_patcher.start()
+        self.addCleanup(exec_patcher.stop)
         self.volume.driver.set_initialized()
         self.addCleanup(self._cleanup)
 
index 7f6c8646e2a26a09cf8a7a8c83b5b01ed2337375..86c6f700a18d210d85f3fd7c2909fbbb374df9c1 100644 (file)
@@ -306,7 +306,7 @@ class BaseVD(object):
             self.configuration.append_config_values(iser_opts)
             utils.setup_tracing(self.configuration.safe_get('trace_flags'))
 
-        self.set_execute(execute)
+        self._execute = execute
         self._stats = {}
 
         self.pools = []
@@ -439,9 +439,6 @@ class BaseVD(object):
                 raise exception.RemoveExportException(volume=snapshot.id,
                                                       reason=ex)
 
-    def set_execute(self, execute):
-        self._execute = execute
-
     def set_initialized(self):
         self._initialized = True
 
index 49914a0a4fc378b639385c69b8d1788cb419f1e5..761ec48e67734e7652c587cf7e6a4c60bfc37403 100644 (file)
@@ -76,11 +76,6 @@ class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD,
             'glusterfs', root_helper, execute,
             glusterfs_mount_point_base=self.base)
 
-    def set_execute(self, execute):
-        super(GlusterfsDriver, self).set_execute(execute)
-        if self._remotefsclient:
-            self._remotefsclient.set_execute(execute)
-
     def do_setup(self, context):
         """Any initialization the volume driver does while starting."""
         super(GlusterfsDriver, self).do_setup(context)
index 55daa86c47596147860119039c4eedfc9effcb68..727543379266bccc80c6ba1d8eafcc8f8711c592 100644 (file)
@@ -221,9 +221,6 @@ class HDSNFSDriver(nfs.NfsDriver):
 
         return service
 
-    def set_execute(self, execute):
-        self._execute = execute
-
     def extend_volume(self, volume, new_size):
         """Extend an existing volume.
 
index 5b4e1c1132f9a8b3871074a470f7a5deef8d2fd7..9f038e5c629df3140abe7b3f8b0cd4508530b4a3 100644 (file)
@@ -90,12 +90,10 @@ class IBMNAS_NFSDriver(nfs.NfsDriver, san.SanDriver):
         self.configuration.san_ssh_port = self.configuration.nas_ssh_port
         self.configuration.ibmnas_platform_type = \
             self.configuration.ibmnas_platform_type.lower()
+        self._execute = execute
         LOG.info(_LI('Initialized driver for IBMNAS Platform: %s.'),
                  self.configuration.ibmnas_platform_type)
 
-    def set_execute(self, execute):
-        self._execute = utils.execute
-
     def do_setup(self, context):
         """Any initialization the volume driver does while starting."""
         super(IBMNAS_NFSDriver, self).do_setup(context)
index 2b0e0c092e085f4aa48afb47710f5fb11663930f..cb933063dfc05b68100a1be290306fb1131ce35d 100644 (file)
@@ -75,9 +75,6 @@ class NetAppNfsDriver(driver.ManageableVD,
         self.configuration.append_config_values(na_opts.netapp_img_cache_opts)
         self.configuration.append_config_values(na_opts.netapp_nfs_extra_opts)
 
-    def set_execute(self, execute):
-        self._execute = execute
-
     def do_setup(self, context):
         super(NetAppNfsDriver, self).do_setup(context)
         self._context = context
index 78c178434984c3a389b81b4872a1bcd406e96982..f8d109fdde2a9ab3d03f34c8171c8ed64fd4394b 100644 (file)
@@ -112,11 +112,6 @@ class NfsDriver(driver.ExtendVD, remotefs.RemoteFSDriver):
 
         self._sparse_copy_volume_data = True
 
-    def set_execute(self, execute):
-        super(NfsDriver, self).set_execute(execute)
-        if self._remotefsclient:
-            self._remotefsclient.set_execute(execute)
-
     def do_setup(self, context):
         """Any initialization the volume driver does while starting."""
         super(NfsDriver, self).do_setup(context)
index 8d163076874e551d61a7dd4284489f1d1002c606..cb79dd861e9e20207f098326a0f3d2f8844fe44c 100644 (file)
@@ -836,11 +836,6 @@ class SRBISCSIDriver(SRBDriver, driver.ISCSIDriver):
             self.configuration.safe_get('volume_backend_name') or 'SRB_iSCSI'
         self.protocol = 'iSCSI'
 
-    def set_execute(self, execute):
-        super(SRBISCSIDriver, self).set_execute(execute)
-        if self.target_driver is not None:
-            self.target_driver.set_execute(execute)
-
     def ensure_export(self, context, volume):
         device_path = self._mapper_path(volume)