aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMytnyk, Volodymyr <volodymyrx.mytnyk@intel.com>2018-08-02 09:17:48 +0100
committerMytnyk, Volodymyr <volodymyrx.mytnyk@intel.com>2018-08-02 11:24:36 +0100
commit0b7a8e5805dff72966a68c4e2c86e467cfd2640a (patch)
tree1aae3017931bbb364bcc7de4e0fb1ca06b72dbcb
parent0b7647a5a6c85a8a1762ec4482004107989c8550 (diff)
Change AutoConnectSSH to return error code by default
AutoConnectSSH execute method always returns exception when remote command returns non 0 ret code. This behavior has been introduced by https://gerrit.opnfv.org/gerrit/#/c/58579/ changes which break the NSB functionality. There are 200+ places where return code (event non zoro) is expected to be returned by AutoConnectSSH.execute() method. Right now the method returns always exception in case of remote command return not zero which causes the problem. Changed execute() method to have previous behavior (raise_on_error is always False by default) and the exception is raised only in case if raise_on_error=True is set explicitly. Added UT. JIRA: YARDSTICK-1365 Change-Id: Ib067583ea5eb704b9174084b45b920c24eb307ac Signed-off-by: Mytnyk, Volodymyr <volodymyrx.mytnyk@intel.com>
-rw-r--r--yardstick/ssh.py2
-rw-r--r--yardstick/tests/unit/test_ssh.py23
2 files changed, 24 insertions, 1 deletions
diff --git a/yardstick/ssh.py b/yardstick/ssh.py
index 69428f3af..8bdc32c7c 100644
--- a/yardstick/ssh.py
+++ b/yardstick/ssh.py
@@ -499,7 +499,7 @@ class AutoConnectSSH(SSH):
""" Don't close anything, just force creation of a new client """
self._client = False
- def execute(self, cmd, stdin=None, timeout=3600, raise_on_error=True):
+ def execute(self, cmd, stdin=None, timeout=3600, raise_on_error=False):
self._connect()
return super(AutoConnectSSH, self).execute(cmd, stdin, timeout,
raise_on_error)
diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py
index b727e821d..71929f1a2 100644
--- a/yardstick/tests/unit/test_ssh.py
+++ b/yardstick/tests/unit/test_ssh.py
@@ -617,3 +617,26 @@ class TestAutoConnectSSH(unittest.TestCase):
auto_connect_ssh.put_file('a', 'b')
mock_put_sftp.assert_called_once()
+
+ def test_execute(self):
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1')
+ auto_connect_ssh._client = mock.Mock()
+ auto_connect_ssh.run = mock.Mock(return_value=0)
+ exit_code, _, _ = auto_connect_ssh.execute('')
+ self.assertEqual(exit_code, 0)
+
+ def _mock_run(self, *args, **kwargs):
+ if args[0] == 'ls':
+ if kwargs.get('raise_on_error'):
+ raise exceptions.SSHError(error_msg='Command error')
+ return 1
+ return 0
+
+ def test_execute_command_error(self):
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1')
+ auto_connect_ssh._client = mock.Mock()
+ auto_connect_ssh.run = mock.Mock(side_effect=self._mock_run)
+ self.assertRaises(exceptions.SSHError, auto_connect_ssh.execute, 'ls',
+ raise_on_error=True)
+ exit_code, _, _ = auto_connect_ssh.execute('ls')
+ self.assertNotEqual(exit_code, 0)