aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark')
-rw-r--r--tests/unit/benchmark/contexts/test_node.py96
-rw-r--r--tests/unit/benchmark/core/test_task.py24
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_nstat.py118
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vnf_generic.py170
4 files changed, 332 insertions, 76 deletions
diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py
index 64fe4a566..53a8ffa93 100644
--- a/tests/unit/benchmark/contexts/test_node.py
+++ b/tests/unit/benchmark/contexts/test_node.py
@@ -14,6 +14,7 @@
from __future__ import absolute_import
import os
import unittest
+import mock
from yardstick.benchmark.contexts import node
@@ -123,3 +124,98 @@ class NodeContextTestCase(unittest.TestCase):
curr_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(curr_path, filename)
return file_path
+
+ prefix = 'yardstick.benchmark.contexts.node'
+
+ @mock.patch('{}.NodeContext._execute_script'.format(prefix))
+ def test_deploy(self, execute_script_mock):
+ obj = node.NodeContext()
+ obj.env = {
+ 'setup': [
+ {'node5': {}}
+ ]
+ }
+ obj.deploy()
+ self.assertTrue(execute_script_mock.called)
+
+ @mock.patch('{}.NodeContext._execute_script'.format(prefix))
+ def test_undeploy(self, execute_script_mock):
+ obj = node.NodeContext()
+ obj.env = {
+ 'teardown': [
+ {'node5': {}}
+ ]
+ }
+ obj.undeploy()
+ self.assertTrue(execute_script_mock.called)
+
+ @mock.patch('{}.ssh.SSH._put_file_shell'.format(prefix))
+ @mock.patch('{}.ssh.SSH.execute'.format(prefix))
+ def test_execute_remote_script(self, execute_mock, put_file_mock):
+ obj = node.NodeContext()
+ obj.env = {'prefix': 'yardstick.benchmark.scenarios.compute'}
+ node_name_args = 'node5'
+ obj.nodes = [{
+ 'name': node_name_args,
+ 'user': 'ubuntu',
+ 'ip': '10.10.10.10',
+ 'pwd': 'ubuntu',
+ }]
+
+ info = {'script': 'computecapacity.bash'}
+ execute_mock.return_value = (0, '', '')
+ obj._execute_remote_script('node5', info)
+
+ self.assertTrue(put_file_mock.called)
+ self.assertTrue(execute_mock.called)
+
+ @mock.patch('{}.NodeContext._execute_local_script'.format(prefix))
+ def test_execute_script_local(self, local_execute_mock):
+ node_name = 'local'
+ info = {}
+ node.NodeContext()._execute_script(node_name, info)
+ self.assertTrue(local_execute_mock.called)
+
+ @mock.patch('{}.NodeContext._execute_remote_script'.format(prefix))
+ def test_execute_script_remote(self, remote_execute_mock):
+ node_name = 'node5'
+ info = {}
+ node.NodeContext()._execute_script(node_name, info)
+ self.assertTrue(remote_execute_mock.called)
+
+ def test_get_script(self):
+ script_args = 'hello.bash'
+ info_args = {
+ 'script': script_args
+ }
+ script, options = node.NodeContext()._get_script(info_args)
+ self.assertEqual(script_args, script)
+ self.assertEqual('', options)
+
+ def test_node_info(self):
+ node_name_args = 'node5'
+ obj = node.NodeContext()
+ obj.nodes = [{'name': node_name_args, 'check': node_name_args}]
+ node_info = obj._get_node_info(node_name_args)
+ self.assertEqual(node_info.get('check'), node_name_args)
+
+ @mock.patch('{}.ssh.SSH.wait'.format(prefix))
+ def test_get_client(self, wait_mock):
+ node_name_args = 'node5'
+ obj = node.NodeContext()
+ obj.nodes = [{
+ 'name': node_name_args,
+ 'user': 'ubuntu',
+ 'ip': '10.10.10.10',
+ 'pwd': 'ubuntu',
+ }]
+ obj._get_client(node_name_args)
+ self.assertTrue(wait_mock.called)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py
index c56e21047..cd7ffdebb 100644
--- a/tests/unit/benchmark/core/test_task.py
+++ b/tests/unit/benchmark/core/test_task.py
@@ -155,6 +155,30 @@ class TaskTestCase(unittest.TestCase):
self.assertEqual(task_args_fnames[0], None)
self.assertEqual(task_args_fnames[1], None)
+ def test_change_server_name_host_str(self):
+ scenario = {'host': 'demo'}
+ suffix = '-8'
+ task.change_server_name(scenario, suffix)
+ self.assertTrue(scenario['host'], 'demo-8')
+
+ def test_change_server_name_host_dict(self):
+ scenario = {'host': {'name': 'demo'}}
+ suffix = '-8'
+ task.change_server_name(scenario, suffix)
+ self.assertTrue(scenario['host']['name'], 'demo-8')
+
+ def test_change_server_name_target_str(self):
+ scenario = {'target': 'demo'}
+ suffix = '-8'
+ task.change_server_name(scenario, suffix)
+ self.assertTrue(scenario['target'], 'demo-8')
+
+ def test_change_server_name_target_dict(self):
+ scenario = {'target': {'name': 'demo'}}
+ suffix = '-8'
+ task.change_server_name(scenario, suffix)
+ self.assertTrue(scenario['target']['name'], 'demo-8')
+
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(curr_path, filename)
diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py
new file mode 100644
index 000000000..87a766302
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/networking/test_nstat.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2017 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.nstat.Nstat
+
+from __future__ import absolute_import
+
+import unittest
+
+import mock
+
+from yardstick.benchmark.scenarios.networking import nstat
+
+@mock.patch('yardstick.benchmark.scenarios.networking.nstat.ssh')
+class NstatTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ "host": {
+ "ip": "192.168.50.28",
+ "user": "root",
+ "key_filename": "mykey.key"
+ }
+ }
+
+ def test_nstat_successful_setup(self, mock_ssh):
+
+ n = nstat.Nstat({}, self.ctx)
+ n.setup()
+
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+ self.assertIsNotNone(n.client)
+ self.assertEqual(n.setup_done, True)
+
+ def test_nstat_successful_no_sla(self, mock_ssh):
+
+ options = {
+ "duration": 60
+ }
+ args = {
+ "options": options,
+ }
+ n = nstat.Nstat(args, self.ctx)
+ result = {}
+
+ sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n'
+
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+
+ n.run(result)
+ expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
+ "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
+ "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
+ "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
+ "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
+ "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
+ self.assertEqual(result, expected_result)
+
+ def test_nstat_successful_sla(self, mock_ssh):
+
+ options = {
+ "duration": 60
+ }
+ sla = {
+ "IP_datagram_error_rate": 0.1
+ }
+ args = {
+ "options": options,
+ "sla": sla
+ }
+ n = nstat.Nstat(args, self.ctx)
+ result = {}
+
+ sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n'
+
+ mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+
+ n.run(result)
+ expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
+ "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
+ "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
+ "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
+ "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
+ "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
+ self.assertEqual(result, expected_result)
+
+ def test_nstat_unsuccessful_cmd_error(self, mock_ssh):
+
+ options = {
+ "duration": 60
+ }
+ sla = {
+ "IP_datagram_error_rate": 0.1
+ }
+ args = {
+ "options": options,
+ "sla": sla
+ }
+ n = nstat.Nstat(args, self.ctx)
+ result = {}
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, n.run, result)
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
index 0d9fbafc5..1b02b6eff 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
@@ -18,12 +18,14 @@
# Unittest for yardstick.benchmark.scenarios.networking.test_vnf_generic
from __future__ import absolute_import
+
+import os
import unittest
+
import mock
-import os
from yardstick.benchmark.scenarios.networking.vnf_generic import \
- ssh_manager, NetworkServiceTestCase, IncorrectConfig, IncorrectSetup
+ SshManager, NetworkServiceTestCase, IncorrectConfig, IncorrectSetup
from yardstick.network_services.collector.subscriber import Collector
from yardstick.network_services.vnf_generic.vnf.base import \
GenericTrafficGen, GenericVNF
@@ -164,14 +166,14 @@ lrwxrwxrwx 1 root root 0 sie 3 10:37 eth2 -> """
"""
TRAFFIC_PROFILE = {
- "schema": "isb:traffic_profile:0.1",
- "name": "fixed",
- "description": "Fixed traffic profile to run UDP traffic",
- "traffic_profile": {
- "traffic_type": "FixedTraffic",
- "frame_rate": 100, # pps
- "flow_number": 10,
- "frame_size": 64}}
+ "schema": "isb:traffic_profile:0.1",
+ "name": "fixed",
+ "description": "Fixed traffic profile to run UDP traffic",
+ "traffic_profile": {
+ "traffic_type": "FixedTraffic",
+ "frame_rate": 100, # pps
+ "flow_number": 10,
+ "frame_size": 64}}
class TestNetworkServiceTestCase(unittest.TestCase):
@@ -236,60 +238,72 @@ class TestNetworkServiceTestCase(unittest.TestCase):
'if': 'xe1'}],
'password': 'r00t'}}}
- self.topology = \
- {'short-name': 'trex-tg-topology',
- 'constituent-vnfd':
- [{'member-vnf-index': '1',
- 'VNF model': 'tg_trex_tpl.yaml',
- 'vnfd-id-ref': 'trexgen__1'},
- {'member-vnf-index': '2',
- 'VNF model': 'tg_trex_tpl.yaml',
- 'vnfd-id-ref': 'trexvnf__1'}],
- 'description': 'trex-tg-topology',
- 'name': 'trex-tg-topology',
- 'vld': [{'vnfd-connection-point-ref': [
- {'vnfd-connection-point-ref': 'xe0',
- 'member-vnf-index-ref': '1',
- 'vnfd-id-ref': 'trexgen'},
- {'vnfd-connection-point-ref': 'xe0',
- 'member-vnf-index-ref': '2',
- 'vnfd-id-ref': 'trexgen'}],
- 'type': 'ELAN',
- 'id': 'private',
- 'name': 'trexgen__1 to trexvnf__1 link 1'},
- {'vnfd-connection-point-ref': [
- {'vnfd-connection-point-ref': 'xe1',
- 'member-vnf-index-ref': '1',
- 'vnfd-id-ref': 'trexgen'},
- {'vnfd-connection-point-ref': 'xe1',
- 'member-vnf-index-ref': '2',
- 'vnfd-id-ref': 'trexgen'}],
- 'type': 'ELAN',
- 'id': 'public',
- 'name': 'trexvnf__1 to trexgen__1 link 2'}],
- 'id': 'trex-tg-topology'}
-
- self.scenario_cfg = {'tc_options':
- {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
- 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
- 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
- 'runner': {'object': 'NetworkServiceTestCase',
- 'interval': 35,
- 'output_filename': 'yardstick.out',
- 'runner_id': 74476,
- 'duration': 400, 'type': 'Duration'},
- 'traffic_profile': 'ipv4_throughput_vpe.yaml',
- 'traffic_options':
- {'flow': 'ipv4_1flow_Packets_vpe.yaml',
- 'imix': 'imix_voice.yaml'},
- 'type': 'ISB',
- 'nodes': {'tg__2': 'trafficgen_2.yardstick',
- 'tg__1': 'trafficgen_1.yardstick',
- 'vnf__1': 'vnf.yardstick'},
- 'topology': 'vpe_vnf_topology.yaml'}
-
- self.scenario_cfg["topology"] = \
- self._get_file_abspath("vpe_vnf_topology.yaml")
+ self.topology = {
+ 'short-name': 'trex-tg-topology',
+ 'constituent-vnfd':
+ [{'member-vnf-index': '1',
+ 'VNF model': 'tg_trex_tpl.yaml',
+ 'vnfd-id-ref': 'trexgen__1'},
+ {'member-vnf-index': '2',
+ 'VNF model': 'tg_trex_tpl.yaml',
+ 'vnfd-id-ref': 'trexvnf__1'}],
+ 'description': 'trex-tg-topology',
+ 'name': 'trex-tg-topology',
+ 'vld': [
+ {
+ 'vnfd-connection-point-ref': [
+ {
+ 'vnfd-connection-point-ref': 'xe0',
+ 'member-vnf-index-ref': '1',
+ 'vnfd-id-ref': 'trexgen'
+ },
+ {
+ 'vnfd-connection-point-ref': 'xe0',
+ 'member-vnf-index-ref': '2',
+ 'vnfd-id-ref': 'trexgen'
+ }
+ ],
+ 'type': 'ELAN',
+ 'id': 'private',
+ 'name': 'trexgen__1 to trexvnf__1 link 1'
+ },
+ {
+ 'vnfd-connection-point-ref': [
+ {
+ 'vnfd-connection-point-ref': 'xe1',
+ 'member-vnf-index-ref': '1',
+ 'vnfd-id-ref': 'trexgen'
+ },
+ {
+ 'vnfd-connection-point-ref': 'xe1',
+ 'member-vnf-index-ref': '2',
+ 'vnfd-id-ref': 'trexgen'
+ }
+ ],
+ 'type': 'ELAN',
+ 'id': 'public',
+ 'name': 'trexvnf__1 to trexgen__1 link 2'
+ }],
+ 'id': 'trex-tg-topology',
+ }
+
+ self.scenario_cfg = {
+ 'tc_options': {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}},
+ 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
+ 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
+ 'runner': {'object': 'NetworkServiceTestCase',
+ 'interval': 35,
+ 'output_filename': 'yardstick.out',
+ 'runner_id': 74476,
+ 'duration': 400, 'type': 'Duration'},
+ 'traffic_profile': 'ipv4_throughput_vpe.yaml',
+ 'traffic_options': {'flow': 'ipv4_1flow_Packets_vpe.yaml',
+ 'imix': 'imix_voice.yaml'}, 'type': 'ISB',
+ 'nodes': {'tg__2': 'trafficgen_2.yardstick',
+ 'tg__1': 'trafficgen_1.yardstick',
+ 'vnf__1': 'vnf.yardstick'},
+ "topology": self._get_file_abspath("vpe_vnf_topology.yaml")}
+
self.s = NetworkServiceTestCase(self.scenario_cfg, self.context_cfg)
def _get_file_abspath(self, filename):
@@ -301,10 +315,10 @@ class TestNetworkServiceTestCase(unittest.TestCase):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
for node, node_dict in self.context_cfg["nodes"].items():
- with ssh_manager(node_dict) as conn:
+ with SshManager(node_dict) as conn:
self.assertIsNotNone(conn)
def test___init__(self):
@@ -342,7 +356,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
self.s.map_topology_to_infrastructure(self.context_cfg,
self.topology)
@@ -356,7 +370,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(1, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
self.assertRaises(IncorrectSetup,
@@ -364,12 +378,12 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.context_cfg, self.topology)
def test_map_topology_to_infrastructure_config_invalid(self):
- del self.context_cfg\
- ['nodes']['trexvnf__1']['interfaces']['xe0']['local_mac']
+ cfg = dict(self.context_cfg)
+ del cfg['nodes']['trexvnf__1']['interfaces']['xe0']['local_mac']
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
self.assertRaises(IncorrectConfig,
@@ -380,7 +394,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
del self.context_cfg['nodes']
@@ -413,7 +427,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET+IP_ADDR_SHOW, ""))
+ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.return_value = ssh_mock
tgen = mock.Mock(autospec=GenericTrafficGen)
@@ -443,11 +457,15 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.context_cfg))
def test__get_traffic_profile_exception(self):
- self.assertRaises(IOError, self.s._get_traffic_profile,
- self.scenario_cfg, self.context_cfg)
+ cfg = dict(self.scenario_cfg)
+ cfg["traffic_profile"] = ""
+ self.assertRaises(IOError, self.s._get_traffic_profile, cfg,
+ self.context_cfg)
def test___get_traffic_imix_exception(self):
- self.assertEqual({}, self.s._get_traffic_imix(self.scenario_cfg))
+ cfg = dict(self.scenario_cfg)
+ cfg["traffic_options"]["imix"] = ""
+ self.assertEqual({}, self.s._get_traffic_imix(cfg))
def test__fill_traffic_profile(self):
with mock.patch.dict("sys.modules", STL_MOCKS):