aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/scenarios/networking/test_iperf3.py
diff options
context:
space:
mode:
authorKristian Hunt <kristian.hunt@gmail.com>2015-07-23 10:44:18 +0200
committerJörgen Karlsson <jorgen.w.karlsson@ericsson.com>2015-09-03 11:50:22 +0000
commit3c3917962ec72fb8ee7cb39bbf126be90c1033d3 (patch)
tree355d416c3021bfa2b798442dc3f1e1d058155cea /tests/unit/benchmark/scenarios/networking/test_iperf3.py
parentc2d65daf876dca1c9bade1e7fa91653251c0c01b (diff)
Add unit test for iperf3
Sample output from the iperf3 is read from a pre-generated json file. Change-Id: I6e04c6bd2e61b841c7e5673cfa78aeb17220a5f9 JIRA:- Signed-off-by: Kristian Hunt <kristian.hunt@gmail.com>
Diffstat (limited to 'tests/unit/benchmark/scenarios/networking/test_iperf3.py')
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_iperf3.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/unit/benchmark/scenarios/networking/test_iperf3.py b/tests/unit/benchmark/scenarios/networking/test_iperf3.py
new file mode 100644
index 000000000..239e46a1c
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/test_iperf3.py
@@ -0,0 +1,133 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Ericsson AB 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
+
+import mock
+import unittest
+import os
+import json
+
+from yardstick.benchmark.scenarios.networking import iperf3
+
+
+@mock.patch('yardstick.benchmark.scenarios.networking.iperf3.ssh')
+class IperfTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': '172.16.0.137',
+ 'target': '172.16.0.138',
+ 'user': 'cirros',
+ 'key_filename': "mykey.key"
+ }
+
+ def test_iperf_successful_setup(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+
+ p.setup()
+ self.assertIsNotNone(p.target)
+ self.assertIsNotNone(p.host)
+ mock_ssh.SSH().execute.assert_called_with("iperf3 -s -D")
+
+ def test_iperf_unsuccessful_setup(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, p.setup)
+
+ def test_iperf_successful_teardown(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ p.host = mock_ssh.SSH()
+ p.target = mock_ssh.SSH()
+
+ p.teardown()
+ self.assertTrue(mock_ssh.SSH().close.called)
+ mock_ssh.SSH().execute.assert_called_with("pkill iperf3")
+
+ def test_iperf_successful_no_sla(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ p.host = mock_ssh.SSH()
+
+ options = {}
+ args = {'options': options}
+
+ sample_output = self._read_sample_output()
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ expected_result = json.loads(sample_output)
+ result = p.run(args)
+ self.assertEqual(result, expected_result)
+
+ def test_iperf_successful_sla(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ p.host = mock_ssh.SSH()
+
+ options = {}
+ args = {
+ 'options': options,
+ 'sla': {'bytes_per_second': 15000000}
+ }
+
+ sample_output = self._read_sample_output()
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ expected_result = json.loads(sample_output)
+ result = p.run(args)
+ self.assertEqual(result, expected_result)
+
+ def test_iperf_unsuccessful_sla(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ p.host = mock_ssh.SSH()
+
+ options = {}
+ args = {
+ 'options': options,
+ 'sla': {'bytes_per_second': 25000000}
+ }
+
+ sample_output = self._read_sample_output()
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+ self.assertRaises(AssertionError, p.run, args)
+
+ def test_iperf_unsuccessful_script_error(self, mock_ssh):
+
+ p = iperf3.Iperf(self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ p.host = mock_ssh.SSH()
+
+ options = {}
+ args = {'options': options}
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, p.run, args)
+
+ def _read_sample_output(self):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ output = os.path.join(curr_path, 'iperf3_sample_output.json')
+ with open(output) as f:
+ sample_output = f.read()
+ return sample_output
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()