diff options
Diffstat (limited to 'tests/unit/benchmark/scenarios/networking')
5 files changed, 312 insertions, 5 deletions
diff --git a/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt new file mode 100644 index 000000000..f90457cb3 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output1.txt @@ -0,0 +1,9 @@ +Linux 3.19.0-25-generic (huawei-pod4) 07/19/2016 _x86_64_ (1 CPU) + +02:01:50 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil +02:01:51 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 +02:01:51 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 + +Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil +Average: eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 +Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 diff --git a/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt new file mode 100644 index 000000000..417613ec1 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/netutilization_sample_output2.txt @@ -0,0 +1,13 @@ +Linux 3.19.0-25-generic (huawei-pod4) 07/19/2016 _x86_64_ (1 CPU) + +02:01:50 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil +02:01:51 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 +02:01:51 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 + +02:01:52 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil +02:01:53 PM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 +02:01:53 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 + +Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil +Average: eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 +Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 diff --git a/tests/unit/benchmark/scenarios/networking/test_netutilization.py b/tests/unit/benchmark/scenarios/networking/test_netutilization.py new file mode 100644 index 000000000..eb6626fea --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/test_netutilization.py @@ -0,0 +1,225 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2016 Huawei Technologies Co.,Ltd and other. +# +# 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.netutilization.NetUtilization + +import mock +import unittest +import os + +from yardstick.benchmark.scenarios.networking import netutilization + + +@mock.patch('yardstick.benchmark.scenarios.networking.netutilization.ssh') +class NetUtilizationTestCase(unittest.TestCase): + + def setUp(self): + self.ctx = { + 'host': { + 'ip': '172.16.0.137', + 'user': 'cirros', + 'key_filename': "mykey.key" + } + } + + self.result = {} + + def test_setup_success(self, mock_ssh): + options = { + "interval": 1, + "count": 1 + } + args = {'options': options} + + n = netutilization.NetUtilization(args, self.ctx) + mock_ssh.SSH().execute.return_value = (0, '', '') + + n.setup() + self.assertIsNotNone(n.client) + self.assertTrue(n.setup_done) + + def test_execute_command_success(self, mock_ssh): + options = { + "interval": 1, + "count": 1 + } + args = {'options': options} + + n = netutilization.NetUtilization(args, self.ctx) + mock_ssh.SSH().execute.return_value = (0, '', '') + n.setup() + + expected_result = 'abcdefg' + mock_ssh.SSH().execute.return_value = (0, expected_result, '') + result = n._execute_command("foo") + self.assertEqual(result, expected_result) + + def test_execute_command_failed(self, mock_ssh): + options = { + "interval": 1, + "count": 1 + } + args = {'options': options} + + n = netutilization.NetUtilization(args, self.ctx) + mock_ssh.SSH().execute.return_value = (0, '', '') + n.setup() + + mock_ssh.SSH().execute.return_value = (127, '', 'abcdefg') + self.assertRaises(RuntimeError, n._execute_command, + "failed") + + def test_get_network_utilization_success(self, mock_ssh): + options = { + "interval": 1, + "count": 1 + } + args = {'options': options} + + n = netutilization.NetUtilization(args, self.ctx) + mock_ssh.SSH().execute.return_value = (0, '', '') + n.setup() + + mpstat_output = self._read_file("netutilization_sample_output1.txt") + mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + result = n._get_network_utilization() + + expected_result = \ + {"network_utilization_maximun": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}, + "network_utilization_average": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}, + "network_utilization_minimum": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}} + + self.assertDictEqual(result, expected_result) + + def test_get_network_utilization_2_success(self, mock_ssh): + options = { + "interval": 1, + "count": 2 + } + args = {'options': options} + + n = netutilization.NetUtilization(args, self.ctx) + mock_ssh.SSH().execute.return_value = (0, '', '') + n.setup() + + mpstat_output = self._read_file("netutilization_sample_output2.txt") + mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + result = n._get_network_utilization() + + expected_result = \ + {"network_utilization_maximun": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}, + "network_utilization_average": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}, + "network_utilization_minimum": { + "lo": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}, + "eth0": {"rxcmp/s": "0.00", + "%ifutil": "0.00", + "txcmp/s": "0.00", + "txkB/s": "0.00", + "rxkB/s": "0.00", + "rxpck/s": "0.00", + "txpck/s": "0.00", + "rxmcst/s": "0.00"}}} + + self.assertDictEqual(result, expected_result) + + def _read_file(self, filename): + curr_path = os.path.dirname(os.path.abspath(__file__)) + output = os.path.join(curr_path, filename) + with open(output) as f: + sample_output = f.read() + return sample_output diff --git a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py new file mode 100644 index 000000000..e3a096446 --- /dev/null +++ b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
+
+import mock
+import unittest
+import os
+import json
+
+from yardstick.benchmark.scenarios.networking import networkcapacity
+
+SAMPLE_OUTPUT = '{"Number of connections":"308","Number of frames received": "166503"}'
+
+@mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
+class NetworkCapacityTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'password': "root"
+ },
+ }
+
+ self.result = {}
+
+ def test_capacity_successful_setup(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ c.setup()
+ self.assertIsNotNone(c.client)
+ self.assertTrue(c.setup_done)
+
+ def test_capacity_successful(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_unsuccessful_script_error(self, mock_ssh):
+ c = networkcapacity.NetworkCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, c.run, self.result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping.py b/tests/unit/benchmark/scenarios/networking/test_ping.py index 600974510..8d35b8490 100644 --- a/tests/unit/benchmark/scenarios/networking/test_ping.py +++ b/tests/unit/benchmark/scenarios/networking/test_ping.py @@ -36,6 +36,7 @@ class PingTestCase(unittest.TestCase): args = { 'options': {'packetsize': 200}, + 'target': 'ares.demo' } result = {} @@ -43,14 +44,15 @@ class PingTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, '100', '') p.run(result) - self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}}) + self.assertEqual(result, {'rtt': {'ares': 100.0}}) @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh') def test_ping_successful_sla(self, mock_ssh): args = { 'options': {'packetsize': 200}, - 'sla': {'max_rtt': 150} + 'sla': {'max_rtt': 150}, + 'target': 'ares.demo' } result = {} @@ -58,14 +60,15 @@ class PingTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, '100', '') p.run(result) - self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}}) + self.assertEqual(result, {'rtt': {'ares': 100.0}}) @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh') def test_ping_unsuccessful_sla(self, mock_ssh): args = { 'options': {'packetsize': 200}, - 'sla': {'max_rtt': 50} + 'sla': {'max_rtt': 50}, + 'target': 'ares.demo' } result = {} @@ -79,7 +82,8 @@ class PingTestCase(unittest.TestCase): args = { 'options': {'packetsize': 200}, - 'sla': {'max_rtt': 50} + 'sla': {'max_rtt': 50}, + 'target': 'ares.demo' } result = {} |