diff options
Diffstat (limited to 'tests/unit/benchmark/scenarios/networking')
-rw-r--r-- | tests/unit/benchmark/scenarios/networking/test_nstat.py | 118 | ||||
-rw-r--r-- | tests/unit/benchmark/scenarios/networking/test_vnf_generic.py | 170 |
2 files changed, 212 insertions, 76 deletions
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): |