]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes the EQL driver CI tests AttributeError
authorrajinir <rajini_ram@dell.com>
Tue, 3 Feb 2015 21:38:13 +0000 (15:38 -0600)
committerrajinir <rajini_ram@dell.com>
Tue, 3 Feb 2015 22:51:36 +0000 (16:51 -0600)
Moved the ssh object back to a 'with' Block to
fix the AttributeError thrown by the GeneralContextManager
in the Eqlx CI tests

Fixed the unit tests to mock the enter and exit methods
instead

Change-Id: I629d20e815fb7da3df90dfeee76abc1c60daeefe
Closes-Bug: #1417772

cinder/tests/test_eqlx.py
cinder/volume/drivers/eqlx.py

index 546d8b355e1410894f13acd093d82393c0417ecf..6ef37a1cdf18249d068eeb91cd88aacaf136943c 100644 (file)
@@ -341,8 +341,10 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase):
                                     password="test",
                                     min_size=1,
                                     max_size=1)
-        self.mock_object(sshpool.item(), 'close')
         self.driver.sshpool = mock.Mock(return_value=sshpool)
+        ssh = mock.Mock(paramiko.SSHClient)
+        self.driver.sshpool.item().__enter__ = mock.Mock(return_value=ssh)
+        self.driver.sshpool.item().__exit__ = mock.Mock(return_value=False)
         # now call the execute
         self.assertRaises(exception.VolumeBackendAPIException,
                           self.driver._eql_execute, "fake command")
@@ -363,8 +365,10 @@ class DellEQLSanISCSIDriverTestCase(test.TestCase):
                                     password="test",
                                     min_size=1,
                                     max_size=1)
-        self.mock_object(sshpool.item(), 'close')
         self.driver.sshpool = mock.Mock(return_value=sshpool)
+        ssh = mock.Mock(paramiko.SSHClient)
+        self.driver.sshpool.item().__enter__ = mock.Mock(return_value=ssh)
+        self.driver.sshpool.item().__exit__ = mock.Mock(return_value=False)
         # mocks for _ssh_execute and _get_output
         self.mock_object(self.driver, '_get_output',
                          mock.Mock(side_effect=exception.
index 84df8d45690bfbb76964b2add08c9a41d66d3293..5ad6f1125eceb782d609565cbe46dada26284df7 100644 (file)
@@ -211,25 +211,24 @@ class DellEQLSanISCSIDriver(SanISCSIDriver):
                 max_size=max_size)
         try:
             total_attempts = attempts
-            ssh = self.sshpool.item()
-            while attempts > 0:
-                attempts -= 1
-                try:
-                    LOG.info(_LI('EQL-driver: executing "%s".'), command)
-                    return self._ssh_execute(
-                        ssh, command,
-                        timeout=self.configuration.eqlx_cli_timeout)
-                except processutils.ProcessExecutionError:
-                    raise
-                except Exception as e:
-                    LOG.exception(e)
-                    greenthread.sleep(random.randint(20, 500) / 100.0)
-            msg = (_("SSH Command failed after '%(total_attempts)r' "
-                     "attempts : '%(command)s'") %
-                   {'total_attempts': total_attempts - attempts,
-                    'command': command})
-            ssh.close()
-            raise exception.VolumeBackendAPIException(data=msg)
+            with self.sshpool.item() as ssh:
+                while attempts > 0:
+                    attempts -= 1
+                    try:
+                        LOG.info(_LI('EQL-driver: executing "%s".'), command)
+                        return self._ssh_execute(
+                            ssh, command,
+                            timeout=self.configuration.eqlx_cli_timeout)
+                    except processutils.ProcessExecutionError:
+                        raise
+                    except Exception as e:
+                        LOG.exception(e)
+                        greenthread.sleep(random.randint(20, 500) / 100.0)
+                msg = (_("SSH Command failed after '%(total_attempts)r' "
+                         "attempts : '%(command)s'") %
+                       {'total_attempts': total_attempts - attempts,
+                        'command': command})
+                raise exception.VolumeBackendAPIException(data=msg)
 
         except Exception:
             with excutils.save_and_reraise_exception():