diff options
author | Miikka Koistinen <miikka.koistinen@nokia.com> | 2018-06-15 11:54:14 +0300 |
---|---|---|
committer | Miikka Koistinen <miikka.koistinen@nokia.com> | 2018-07-31 15:24:54 +0300 |
commit | 0b7647a5a6c85a8a1762ec4482004107989c8550 (patch) | |
tree | 9eb9c235289116c4c782502eee2898af81334da3 /yardstick/tests/unit | |
parent | 7cd4ce42210b54ee27cc7e618d58f42177fdc5a3 (diff) |
Fix remote command execution in common.utils
yardstick.common.utils get_port_mac and get_port_ip both raise a
RuntimeError on positive remote command exit status. This commit fixes
them to use the error raising mechanism in yardstick.ssh.SSH.
Additionally, the class AutoConnectSSH class needed an additional
argument to allow the raising mechanism to work correctly.
JIRA: YARDSTICK-1240
Change-Id: Idad125ebbd668cef10a6149eb3e601a437a8d40d
Signed-off-by: Miikka Koistinen <miikka.koistinen@nokia.com>
Diffstat (limited to 'yardstick/tests/unit')
-rw-r--r-- | yardstick/tests/unit/common/test_utils.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py index b634ff4b4..eae0a3245 100644 --- a/yardstick/tests/unit/common/test_utils.py +++ b/yardstick/tests/unit/common/test_utils.py @@ -1346,3 +1346,35 @@ class SendSocketCommandTestCase(unittest.TestCase): mock_socket_obj.connect_ex.assert_called_once_with(('host', 22)) mock_socket_obj.sendall.assert_called_once_with(six.b('command')) mock_socket_obj.close.assert_called_once() + + +class GetPortMacTestCase(unittest.TestCase): + + def setUp(self): + self.ssh_client = mock.Mock() + self.ssh_client.execute.return_value = (0, 'foo ', '') + + def test_ssh_client_execute_called(self): + utils.get_port_mac(self.ssh_client, 99) + self.ssh_client.execute.assert_called_once_with( + "ifconfig |grep HWaddr |grep 99 |awk '{print $5}' ", + raise_on_error=True) + + def test_return_value(self): + self.assertEqual('foo', utils.get_port_mac(self.ssh_client, 99)) + + +class GetPortIPTestCase(unittest.TestCase): + + def setUp(self): + self.ssh_client = mock.Mock() + self.ssh_client.execute.return_value = (0, 'foo ', '') + + def test_ssh_client_execute_called(self): + utils.get_port_ip(self.ssh_client, 99) + self.ssh_client.execute.assert_called_once_with( + "ifconfig 99 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ", + raise_on_error=True) + + def test_return_value(self): + self.assertEqual('foo', utils.get_port_ip(self.ssh_client, 99)) |