]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock processutils.execute properly in test_ibmnas
authorJay S. Bryant <jsbryant@us.ibm.com>
Mon, 25 Aug 2014 18:09:14 +0000 (13:09 -0500)
committerJay S. Bryant <jsbryant@us.ibm.com>
Mon, 25 Aug 2014 18:14:43 +0000 (13:14 -0500)
test_delete_snapfiles and test_delete_snapfiles_nas_gpfs were
not properly mocking out cinder.openstack.common.processutils.execute .
This was causing the unittests to prompt for a sudo password during
unit test on some systems.

This change mocks out processutils.execute to return what is expected
for this test case.

Change-Id: I67f26cfd3157813758de7785157a21ebe5230833
Closes-bug: 1361287

cinder/tests/test_ibmnas.py

index a446cea430dd7873605af8e7f9f92b28a17c7f73..77bbcfc96a148f76247acf440420aa1e040edbde 100644 (file)
@@ -300,30 +300,36 @@ class IBMNASDriverTestCase(test.TestCase):
                           self.TEST_EXTEND_SIZE_IN_GB)
 
     @mock.patch('cinder.volume.drivers.ibm.ibmnas.IBMNAS_NFSDriver._run_ssh')
-    def test_delete_snapfiles(self, mock_ssh):
+    @mock.patch('cinder.openstack.common.processutils.execute')
+    def test_delete_snapfiles(self, mock_ssh, mock_execute):
         """Delete_snapfiles test case."""
 
         drv = self._driver
-        mock_ssh.return_value = ('Parent Depth Parent inode'
-                                 'File name\n yes    0 /ibm/gpfs0/gshare/\n'
-                                 'volume-123\n EFSSG1000I The command'
-                                 'completed successfully.', '')
+        expected = ('Parent Depth Parent inode'
+                    'File name\n yes    0 /ibm/gpfs0/gshare/\n'
+                    'volume-123\n EFSSG1000I The command'
+                    'completed successfully.', '')
+        mock_execute.return_value = expected
+        mock_ssh.return_value = expected
 
         drv._delete_snapfiles(self.TEST_VOLUME_PATH,
                               self.TEST_MNT_POINT)
 
     @mock.patch('cinder.volume.drivers.ibm.ibmnas.IBMNAS_NFSDriver._run_ssh')
-    def test_delete_snapfiles_nas_gpfs(self, mock_ssh):
+    @mock.patch('cinder.openstack.common.processutils.execute')
+    def test_delete_snapfiles_nas_gpfs(self, mock_ssh, mock_execute):
         """Delete_snapfiles for gpfs-nas platform test case."""
 
         drv = self._driver
         drv.configuration.platform = 'gpfs-nas'
-        mock_ssh.return_value = ('Parent  Depth   Parent inode'
-                                 'File name\n'
-                                 '------  -----  -------------'
-                                 '-  ---------\n'
-                                 'yes      0\n'
-                                 '/ibm/gpfs0/gshare/volume-123', '')
+        expected = ('Parent  Depth   Parent inode'
+                    'File name\n'
+                    '------  -----  -------------'
+                    '-  ---------\n'
+                    'yes      0\n'
+                    '/ibm/gpfs0/gshare/volume-123', '')
+        mock_execute.return_value = expected
+        mock_ssh.return_value = expected
 
         drv._delete_snapfiles(self.TEST_VOLUME_PATH,
                               self.TEST_MNT_POINT)