summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/api/actions/test_test.py21
-rw-r--r--tests/unit/api/test_views.py24
-rw-r--r--tests/unit/api/utils/test_common.py8
-rw-r--r--tests/unit/api/utils/test_daemonthread.py29
-rw-r--r--tests/unit/api/utils/test_influx.py22
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf.py10
-rw-r--r--tests/unit/cmd/commands/test_env.py29
-rw-r--r--tests/unit/common/test_httpClient.py33
-rw-r--r--tests/unit/test_ssh.py79
9 files changed, 173 insertions, 82 deletions
diff --git a/tests/unit/api/actions/test_test.py b/tests/unit/api/actions/test_test.py
deleted file mode 100644
index 158062ff4..000000000
--- a/tests/unit/api/actions/test_test.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import unittest
-import json
-
-from api.actions import test
-
-
-class RunTestCase(unittest.TestCase):
-
- def test_runTestCase_with_no_testcase_arg(self):
- args = {}
- output = json.loads(test.runTestCase(args))
-
- self.assertEqual('error', output['status'])
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/tests/unit/api/test_views.py b/tests/unit/api/test_views.py
deleted file mode 100644
index 650ed569c..000000000
--- a/tests/unit/api/test_views.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import unittest
-import mock
-import json
-
-from api.views import Test
-
-
-class TestTestCase(unittest.TestCase):
-
- @mock.patch('api.views.request')
- def test_post(self, mock_request):
- mock_request.json.get.side_effect = ['runTestSuite', {}]
-
- result = json.loads(Test().post())
-
- self.assertEqual('error', result['status'])
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/tests/unit/api/utils/test_common.py b/tests/unit/api/utils/test_common.py
index 5d858a32c..5d177409e 100644
--- a/tests/unit/api/utils/test_common.py
+++ b/tests/unit/api/utils/test_common.py
@@ -1,3 +1,11 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
import unittest
from api.utils import common
diff --git a/tests/unit/api/utils/test_daemonthread.py b/tests/unit/api/utils/test_daemonthread.py
deleted file mode 100644
index 918f1f506..000000000
--- a/tests/unit/api/utils/test_daemonthread.py
+++ /dev/null
@@ -1,29 +0,0 @@
-import unittest
-import mock
-
-from api.utils.daemonthread import DaemonThread
-
-
-class DaemonThreadTestCase(unittest.TestCase):
-
- @mock.patch('api.utils.daemonthread.os')
- def test_run(self, mock_os):
- def func(common_list, task_id):
- return task_id
-
- common_list = []
- task_id = '1234'
- thread = DaemonThread(func, (common_list, task_id))
- thread.run()
-
- mock_os.path.exist.return_value = True
- pre_path = '../tests/opnfv/test_suites/'
- mock_os.remove.assert_called_with(pre_path + '1234.yaml')
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/tests/unit/api/utils/test_influx.py b/tests/unit/api/utils/test_influx.py
index 5f1e2c36f..0852da2dd 100644
--- a/tests/unit/api/utils/test_influx.py
+++ b/tests/unit/api/utils/test_influx.py
@@ -1,3 +1,11 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
import unittest
import mock
import uuid
@@ -13,7 +21,7 @@ class GetDataDbClientTestCase(unittest.TestCase):
mock_parser.ConfigParser().get.return_value = 'file'
try:
influx.get_data_db_client()
- except Exception, e:
+ except Exception as e:
self.assertIsInstance(e, RuntimeError)
@@ -54,6 +62,18 @@ class WriteDataTasklistTestCase(unittest.TestCase):
mock_write_data.assert_called_with('tasklist', field, timestamp, tags)
+class QueryTestCase(unittest.TestCase):
+
+ @mock.patch('api.utils.influx.ConfigParser')
+ def test_query_dispatcher_not_influxdb(self, mock_parser):
+ mock_parser.ConfigParser().get.return_value = 'file'
+ try:
+ sql = 'select * form tasklist'
+ influx.query(sql)
+ except Exception as e:
+ self.assertIsInstance(e, RuntimeError)
+
+
def main():
unittest.main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
index cb5c09ab3..25d52212b 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
@@ -39,17 +39,17 @@ class VsperfTestCase(unittest.TestCase):
}
self.args = {
'options': {
- 'testname': 'rfc2544_p2p_continuous',
+ 'testname': 'p2p_rfc2544_continuous',
'traffic_type': 'continuous',
- 'pkt_sizes': '64',
+ 'frame_size': '64',
'bidirectional': 'True',
'iload': 100,
- 'duration': 29,
'trafficgen_port1': 'eth1',
'trafficgen_port2': 'eth3',
'external_bridge': 'br-ex',
- 'conf-file': 'vsperf-yardstick.conf',
- 'setup-script': 'setup_yardstick.sh',
+ 'conf_file': 'vsperf-yardstick.conf',
+ 'setup_script': 'setup_yardstick.sh',
+ 'test_params': 'TRAFFICGEN_DURATION=30;',
},
'sla': {
'metrics': 'throughput_rx_fps',
diff --git a/tests/unit/cmd/commands/test_env.py b/tests/unit/cmd/commands/test_env.py
new file mode 100644
index 000000000..af1ab8030
--- /dev/null
+++ b/tests/unit/cmd/commands/test_env.py
@@ -0,0 +1,29 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import unittest
+import mock
+
+from yardstick.cmd.commands.env import EnvCommand
+
+
+class EnvCommandTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.cmd.commands.env.HttpClient')
+ def test_do_influxdb(self, mock_http_client):
+ env = EnvCommand()
+ env.do_influxdb({})
+ self.assertTrue(mock_http_client().post.called)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/common/test_httpClient.py b/tests/unit/common/test_httpClient.py
new file mode 100644
index 000000000..b39dc2332
--- /dev/null
+++ b/tests/unit/common/test_httpClient.py
@@ -0,0 +1,33 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import unittest
+import mock
+import json
+
+from yardstick.common import httpClient
+
+
+class HttpClientTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.common.httpClient.requests')
+ def test_post(self, mock_requests):
+ url = 'http://localhost:5000/hello'
+ data = {'hello': 'world'}
+ headers = {'Content-Type': 'application/json'}
+ httpClient.HttpClient().post(url, data)
+ mock_requests.post.assert_called_with(url, data=json.dumps(data),
+ headers=headers)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/test_ssh.py b/tests/unit/test_ssh.py
index a27052462..88638a0a8 100644
--- a/tests/unit/test_ssh.py
+++ b/tests/unit/test_ssh.py
@@ -17,7 +17,10 @@
# rally/tests/unit/common/test_sshutils.py
import os
+import socket
import unittest
+from cStringIO import StringIO
+
import mock
from yardstick import ssh
@@ -162,10 +165,10 @@ class SSHTestCase(unittest.TestCase):
def test_send_command(self, mock_paramiko):
paramiko_sshclient = self.test_client._get_client()
with mock.patch.object(paramiko_sshclient, "exec_command") \
- as mock_paramiko_exec_command:
+ as mock_paramiko_exec_command:
self.test_client.send_command('cmd')
mock_paramiko_exec_command.assert_called_once_with('cmd',
- get_pty=True)
+ get_pty=True)
class SSHRunTestCase(unittest.TestCase):
@@ -275,6 +278,23 @@ class SSHRunTestCase(unittest.TestCase):
self.assertEqual(send_calls, self.fake_session.send.mock_calls)
@mock.patch("yardstick.ssh.select")
+ def test_run_stdin_keep_open(self, mock_select):
+ """Test run method with stdin.
+
+ Third send call was called with "e2" because only 3 bytes was sent
+ by second call. So remainig 2 bytes of "line2" was sent by third call.
+ """
+ mock_select.select.return_value = ([], [], [])
+ self.fake_session.exit_status_ready.side_effect = [0, 0, 0, True]
+ self.fake_session.send_ready.return_value = True
+ self.fake_session.send.side_effect = len
+ fake_stdin = StringIO("line1\nline2\n")
+ self.test_client.run("cmd", stdin=fake_stdin, keep_stdin_open=True)
+ call = mock.call
+ send_calls = [call("line1\nline2\n")]
+ self.assertEqual(send_calls, self.fake_session.send.mock_calls)
+
+ @mock.patch("yardstick.ssh.select")
def test_run_select_error(self, mock_select):
self.fake_session.exit_status_ready.return_value = False
mock_select.select.return_value = ([], [], [True])
@@ -288,6 +308,61 @@ class SSHRunTestCase(unittest.TestCase):
self.fake_session.exit_status_ready.return_value = False
self.assertRaises(ssh.SSHTimeout, self.test_client.run, "cmd")
+ @mock.patch("yardstick.ssh.open", create=True)
+ def test__put_file_shell(self, mock_open):
+ self.test_client.run = mock.Mock()
+ self.test_client._put_file_shell("localfile", "remotefile", 0o42)
+
+ self.test_client.run.assert_called_once_with(
+ 'cat > "remotefile"&& chmod -- 042 "remotefile"',
+ stdin=mock_open.return_value.__enter__.return_value)
+
+ @mock.patch("yardstick.ssh.os.stat")
+ def test__put_file_sftp(self, mock_stat):
+ sftp = self.fake_client.open_sftp.return_value = mock.MagicMock()
+ sftp.__enter__.return_value = sftp
+
+ mock_stat.return_value = os.stat_result([0o753] + [0] * 9)
+
+ self.test_client._put_file_sftp("localfile", "remotefile")
+
+ sftp.put.assert_called_once_with("localfile", "remotefile")
+ mock_stat.assert_called_once_with("localfile")
+ sftp.chmod.assert_called_once_with("remotefile", 0o753)
+ sftp.__exit__.assert_called_once_with(None, None, None)
+
+ def test__put_file_sftp_mode(self):
+ sftp = self.fake_client.open_sftp.return_value = mock.MagicMock()
+ sftp.__enter__.return_value = sftp
+
+ self.test_client._put_file_sftp("localfile", "remotefile", mode=0o753)
+
+ sftp.put.assert_called_once_with("localfile", "remotefile")
+ sftp.chmod.assert_called_once_with("remotefile", 0o753)
+ sftp.__exit__.assert_called_once_with(None, None, None)
+
+ def test_put_file_SSHException(self):
+ exc = ssh.paramiko.SSHException
+ self.test_client._put_file_sftp = mock.Mock(side_effect=exc())
+ self.test_client._put_file_shell = mock.Mock()
+
+ self.test_client.put_file("foo", "bar", 42)
+ self.test_client._put_file_sftp.assert_called_once_with("foo", "bar",
+ mode=42)
+ self.test_client._put_file_shell.assert_called_once_with("foo", "bar",
+ mode=42)
+
+ def test_put_file_socket_error(self):
+ exc = socket.error
+ self.test_client._put_file_sftp = mock.Mock(side_effect=exc())
+ self.test_client._put_file_shell = mock.Mock()
+
+ self.test_client.put_file("foo", "bar", 42)
+ self.test_client._put_file_sftp.assert_called_once_with("foo", "bar",
+ mode=42)
+ self.test_client._put_file_shell.assert_called_once_with("foo", "bar",
+ mode=42)
+
def main():
unittest.main()