aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/apiserver/resources/test_env_action.py10
-rw-r--r--tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml8
-rw-r--r--tests/unit/benchmark/contexts/nodes_sample.yaml8
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py9
-rw-r--r--tests/unit/benchmark/contexts/test_model.py10
-rw-r--r--tests/unit/benchmark/contexts/test_node.py96
-rw-r--r--tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml8
-rw-r--r--tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml8
-rw-r--r--tests/unit/benchmark/core/test_task.py24
-rw-r--r--tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml8
-rw-r--r--tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml8
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_nstat.py118
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vnf_generic.py170
-rw-r--r--tests/unit/cmd/commands/test_testcase.py8
-rw-r--r--tests/unit/common/config_sample.yaml8
-rw-r--r--tests/unit/common/test_openstack_utils.py28
-rw-r--r--tests/unit/dispatcher/test_influxdb_line_protocol.py8
-rw-r--r--tests/unit/network_services/test_utils.py13
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py2
19 files changed, 458 insertions, 94 deletions
diff --git a/tests/unit/apiserver/resources/test_env_action.py b/tests/unit/apiserver/resources/test_env_action.py
index e8f99b706..c7ae10a20 100644
--- a/tests/unit/apiserver/resources/test_env_action.py
+++ b/tests/unit/apiserver/resources/test_env_action.py
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
from __future__ import absolute_import
import time
@@ -10,7 +18,7 @@ class EnvTestCase(APITestCase):
def test_create_grafana(self):
url = 'yardstick/env/action'
- data = dict(action='createGrafanaContainer')
+ data = {'action': 'createGrafanaContainer'}
resp = self._post(url, data)
time.sleep(1)
diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml
index cdb5138c2..dbdd3700d 100644
--- a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml
+++ b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
nodes:
-
name: node1
diff --git a/tests/unit/benchmark/contexts/nodes_sample.yaml b/tests/unit/benchmark/contexts/nodes_sample.yaml
index 59b5bb9fe..8d50c3aea 100644
--- a/tests/unit/benchmark/contexts/nodes_sample.yaml
+++ b/tests/unit/benchmark/contexts/nodes_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
nodes:
-
name: node1
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index f8f349205..8f4852ca8 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -39,6 +39,7 @@ class HeatContextTestCase(unittest.TestCase):
self.assertEqual(self.test_context.networks, [])
self.assertEqual(self.test_context.servers, [])
self.assertEqual(self.test_context.placement_groups, [])
+ self.assertEqual(self.test_context.server_groups, [])
self.assertIsNone(self.test_context.keypair_name)
self.assertIsNone(self.test_context.secgroup_name)
self.assertEqual(self.test_context._server_map, {})
@@ -51,15 +52,18 @@ class HeatContextTestCase(unittest.TestCase):
self.assertIsNotNone(self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
+ @mock.patch('yardstick.benchmark.contexts.heat.ServerGroup')
@mock.patch('yardstick.benchmark.contexts.heat.Network')
@mock.patch('yardstick.benchmark.contexts.heat.Server')
- def test_init(self, mock_server, mock_network, mock_pg):
+ def test_init(self, mock_server, mock_network, mock_sg, mock_pg):
pgs = {'pgrp1': {'policy': 'availability'}}
+ sgs = {'servergroup1': {'policy': 'affinity'}}
networks = {'bar': {'cidr': '10.0.1.0/24'}}
servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}}
attrs = {'name': 'foo',
'placement_groups': pgs,
+ 'server_groups': sgs,
'networks': networks,
'servers': servers}
@@ -71,7 +75,10 @@ class HeatContextTestCase(unittest.TestCase):
mock_pg.assert_called_with('pgrp1', self.test_context,
pgs['pgrp1']['policy'])
+ mock_sg.assert_called_with('servergroup1', self.test_context,
+ sgs['servergroup1']['policy'])
self.assertTrue(len(self.test_context.placement_groups) == 1)
+ self.assertTrue(len(self.test_context.server_groups) == 1)
mock_network.assert_called_with(
'bar', self.test_context, networks['bar'])
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index 537a8c008..a4b7d81ef 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -180,6 +180,7 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(test_server.keypair_name, 'some-keys')
self.assertEqual(test_server.secgroup_name, 'some-secgroup')
self.assertEqual(test_server.placement_groups, [])
+ self.assertIsNone(test_server.server_group)
self.assertEqual(test_server.instances, 1)
self.assertIsNone(test_server.floating_ip)
self.assertIsNone(test_server._image)
@@ -195,6 +196,15 @@ class ServerTestCase(unittest.TestCase):
self.assertRaises(ValueError, model.Server, 'foo',
self.mock_context, attrs)
+ @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup')
+ def test_construct_get_wrong_server_group(self, mock_sg):
+
+ attrs = {'server_group': 'baz'}
+ mock_sg.get.return_value = None
+
+ self.assertRaises(ValueError, model.Server, 'foo',
+ self.mock_context, attrs)
+
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_instance(self, mock_template):
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/no_constraint_no_args_scenario_sample.yaml b/tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml
index 4933b93ae..44c4a31ff 100644
--- a/tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
---
# Huawei US bare daily task suite
diff --git a/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml b/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml
index f39df7346..ced13f19e 100644
--- a/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
---
# Huawei US bare daily task suite
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/core/with_constraint_no_args_scenario_sample.yaml b/tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml
index 8194a2361..168d4b01a 100644
--- a/tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
---
# Huawei US bare daily task suite
diff --git a/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml b/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml
index 86c9b2800..299e5de56 100644
--- a/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
---
# Huawei US bare daily task suite
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):
diff --git a/tests/unit/cmd/commands/test_testcase.py b/tests/unit/cmd/commands/test_testcase.py
index 515784352..7ef157c19 100644
--- a/tests/unit/cmd/commands/test_testcase.py
+++ b/tests/unit/cmd/commands/test_testcase.py
@@ -1,3 +1,11 @@
+##############################################################################
+# 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
+##############################################################################
import unittest
from mock import patch
diff --git a/tests/unit/common/config_sample.yaml b/tests/unit/common/config_sample.yaml
index 8caa19ec6..09218cc79 100644
--- a/tests/unit/common/config_sample.yaml
+++ b/tests/unit/common/config_sample.yaml
@@ -1,2 +1,10 @@
+##############################################################################
+# 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
+##############################################################################
releng:
dir: /home/opnfv/repos/releng
diff --git a/tests/unit/common/test_openstack_utils.py b/tests/unit/common/test_openstack_utils.py
index d610e181c..b3dc2d9c4 100644
--- a/tests/unit/common/test_openstack_utils.py
+++ b/tests/unit/common/test_openstack_utils.py
@@ -22,21 +22,25 @@ class GetCredentialsTestCase(unittest.TestCase):
@mock.patch('yardstick.common.openstack_utils.os')
def test_get_credentials(self, mock_os):
- mock_os.getenv.return_value = ('2')
- openstack_utils.get_credentials()
+ with mock.patch.dict('os.environ', {'OS_IDENTITY_API_VERSION': '2'},
+ clear=True):
+ openstack_utils.get_credentials()
class GetHeatApiVersionTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.os')
- def test_get_heat_api_version(self, mock_os):
+ def test_get_heat_api_version_check_result(self):
API = 'HEAT_API_VERSION'
- openstack_utils.get_heat_api_version()
- mock_os.getenv.assert_called_with(API)
-
- @mock.patch('yardstick.common.openstack_utils.os')
- def test_get_heat_api_version(self, mock_os):
- mock_os.getenv.return_value = ('2')
expected_result = '2'
- api_version = openstack_utils.get_heat_api_version()
- self.assertEqual(api_version, expected_result)
+
+ with mock.patch.dict('os.environ', {API: '2'}, clear=True):
+ api_version = openstack_utils.get_heat_api_version()
+ self.assertEqual(api_version, expected_result)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/dispatcher/test_influxdb_line_protocol.py b/tests/unit/dispatcher/test_influxdb_line_protocol.py
index debb1994a..51dc39e3c 100644
--- a/tests/unit/dispatcher/test_influxdb_line_protocol.py
+++ b/tests/unit/dispatcher/test_influxdb_line_protocol.py
@@ -1,3 +1,11 @@
+##############################################################################
+# 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.dispatcher.influxdb_line_protocol
# yardstick comment: this file is a modified copy of
diff --git a/tests/unit/network_services/test_utils.py b/tests/unit/network_services/test_utils.py
index ecacac7c3..8d9e74adf 100644
--- a/tests/unit/network_services/test_utils.py
+++ b/tests/unit/network_services/test_utils.py
@@ -16,6 +16,8 @@
# Unittest for yardstick.network_services.utils
from __future__ import absolute_import
+
+import os
import unittest
import mock
@@ -25,19 +27,24 @@ from yardstick.network_services import utils
class UtilsTestCase(unittest.TestCase):
"""Test all VNF helper methods."""
- DPDK_PATH = "/opt/nsb_bin/dpdk_nic_bind.py"
+ DPDK_PATH = os.path.join(utils.NSB_ROOT, "dpdk_nic_bind.py")
def setUp(self):
super(UtilsTestCase, self).setUp()
def test_get_nsb_options(self):
result = utils.get_nsb_option("bin_path", None)
- self.assertEqual(result, "/opt/nsb_bin")
+ self.assertEqual(result, utils.NSB_ROOT)
- def test_get_nsb_optionsi_invalid_key(self):
+ def test_get_nsb_option_is_invalid_key(self):
result = utils.get_nsb_option("bin", None)
self.assertEqual(result, None)
+ def test_get_nsb_option_default(self):
+ default = object()
+ result = utils.get_nsb_option("nosuch", default)
+ self.assertIs(result, default)
+
def test_provision_tool(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
index eb0dbf628..a76fbbd2a 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
@@ -195,7 +195,7 @@ class TestTrexTrafficGen(unittest.TestCase):
self.assertEqual({}, restult)
def test_listen_traffic(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
+ with mock.patch("yardstick.ssh.SSH") as ssh:
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \