aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xrun_tests.sh23
-rw-r--r--tests/unit/apiserver/resources/test_env_action.py2
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vnf_generic.py170
-rw-r--r--tests/unit/network_services/test_utils.py13
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py2
-rw-r--r--yardstick/benchmark/contexts/dummy.py2
-rw-r--r--yardstick/benchmark/contexts/heat.py13
-rw-r--r--yardstick/benchmark/contexts/model.py6
-rw-r--r--yardstick/benchmark/contexts/node.py2
-rw-r--r--yardstick/benchmark/contexts/standalone.py2
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_general.py8
-rw-r--r--yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py32
-rw-r--r--yardstick/benchmark/scenarios/availability/scenario_general.py4
-rw-r--r--yardstick/benchmark/scenarios/networking/vnf_generic.py60
-rw-r--r--yardstick/cmd/commands/task.py2
-rw-r--r--yardstick/common/openstack_utils.py2
-rw-r--r--yardstick/common/utils.py3
-rw-r--r--yardstick/dispatcher/influxdb.py2
-rw-r--r--yardstick/network_services/utils.py10
-rw-r--r--yardstick/network_services/vnf_generic/vnfdgen.py6
-rw-r--r--yardstick/orchestrator/heat.py2
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py11
-rw-r--r--yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json2
-rw-r--r--yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json2
24 files changed, 194 insertions, 187 deletions
diff --git a/run_tests.sh b/run_tests.sh
index 1f985b6c1..2519d94f6 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -33,32 +33,9 @@ run_flake8() {
fi
}
-get_external_libs() {
- cd $(dirname ${BASH_SOURCE[0]})
- TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/v2.05.tar.gz"
- TREX_DIR=$PWD/trex/scripts
- if [ ! -d "$TREX_DIR" ]; then
- rm -rf ${TREX_DOWNLOAD##*/}
- if [ ! -e ${TREX_DOWNLOAD##*/} ] ; then
- wget -nv $TREX_DOWNLOAD
- fi
- tar xf ${TREX_DOWNLOAD##*/}
- pushd .
- rm -rf trex && mkdir -p trex
- mv v2.05 trex/scripts
- rm -rf v2.05.tar.gz
- touch "$PWD/trex/scripts/automation/trex_control_plane/stl/__init__.py"
- popd
- fi
- echo "Done."
- export PYTHONPATH=$PYTHONPATH:"$PWD/trex/scripts/automation/trex_control_plane"
- export PYTHONPATH=$PYTHONPATH:"$PWD/trex/scripts/automation/trex_control_plane/stl"
- echo $PYTHONPATH
-}
run_tests() {
echo "Get external libs needed for unit test"
- get_external_libs
echo "Running unittest ... "
if [ $FILE_OPTION == "f" ]; then
diff --git a/tests/unit/apiserver/resources/test_env_action.py b/tests/unit/apiserver/resources/test_env_action.py
index e8f99b706..0411a66c4 100644
--- a/tests/unit/apiserver/resources/test_env_action.py
+++ b/tests/unit/apiserver/resources/test_env_action.py
@@ -10,7 +10,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/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/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 = \
diff --git a/yardstick/benchmark/contexts/dummy.py b/yardstick/benchmark/contexts/dummy.py
index f7530035c..0edc250f8 100644
--- a/yardstick/benchmark/contexts/dummy.py
+++ b/yardstick/benchmark/contexts/dummy.py
@@ -22,7 +22,7 @@ class DummyContext(Context):
__context_type__ = "Dummy"
def __init__(self):
- super(self.__class__, self).__init__()
+ super(DummyContext, self).__init__()
def init(self, attrs):
pass
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py
index 0346efcf4..4c7f05236 100644
--- a/yardstick/benchmark/contexts/heat.py
+++ b/yardstick/benchmark/contexts/heat.py
@@ -55,7 +55,7 @@ class HeatContext(Context):
self.key_filename = ''.join(
[YARDSTICK_ROOT_PATH, 'yardstick/resources/files/yardstick_key-',
get_short_key_uuid(self.key_uuid)])
- super(self.__class__, self).__init__()
+ super(HeatContext, self).__init__()
def init(self, attrs):
"""initializes itself from the supplied arguments"""
@@ -94,9 +94,10 @@ class HeatContext(Context):
rsa_key = paramiko.RSAKey.generate(bits=2048, progress_func=None)
rsa_key.write_private_key_file(self.key_filename)
- open(self.key_filename + ".pub", "w").write("%s %s\n" %
- (rsa_key.get_name(),
- rsa_key.get_base64()))
+ print("Writing %s ..." % self.key_filename)
+ with open(self.key_filename + ".pub", "w") as pubkey_file:
+ pubkey_file.write(
+ "%s %s\n" % (rsa_key.get_name(), rsa_key.get_base64()))
del rsa_key
@property
@@ -220,9 +221,9 @@ class HeatContext(Context):
# copy some vital stack output into server objects
for server in self.servers:
- if len(server.ports) > 0:
+ if server.ports:
# TODO(hafe) can only handle one internal network for now
- port = list(server.ports.values())[0]
+ port = next(iter(server.ports.values()))
server.private_ip = self.stack.outputs[port["stack_name"]]
if server.floating_ip:
diff --git a/yardstick/benchmark/contexts/model.py b/yardstick/benchmark/contexts/model.py
index 636abfa35..c83a209cf 100644
--- a/yardstick/benchmark/contexts/model.py
+++ b/yardstick/benchmark/contexts/model.py
@@ -66,7 +66,7 @@ class Router(Object):
"""Class that represents a router in the logical model"""
def __init__(self, name, network_name, context, external_gateway_info):
- super(self.__class__, self).__init__(name, context)
+ super(Router, self).__init__(name, context)
self.stack_name = context.name + "-" + network_name + "-" + self.name
self.stack_if_name = self.stack_name + "-if0"
@@ -78,7 +78,7 @@ class Network(Object):
list = []
def __init__(self, name, context, attrs):
- super(self.__class__, self).__init__(name, context)
+ super(Network, self).__init__(name, context)
self.stack_name = context.name + "-" + self.name
self.subnet_stack_name = self.stack_name + "-subnet"
self.subnet_cidr = attrs.get('cidr', '10.0.1.0/24')
@@ -118,7 +118,7 @@ class Server(Object):
list = []
def __init__(self, name, context, attrs):
- super(self.__class__, self).__init__(name, context)
+ super(Server, self).__init__(name, context)
self.stack_name = self.name + "." + context.name
self.keypair_name = context.keypair_name
self.secgroup_name = context.secgroup_name
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
index 9242e2727..c7ed3b3f1 100644
--- a/yardstick/benchmark/contexts/node.py
+++ b/yardstick/benchmark/contexts/node.py
@@ -32,7 +32,7 @@ class NodeContext(Context):
self.controllers = []
self.computes = []
self.baremetals = []
- super(self.__class__, self).__init__()
+ super(NodeContext, self).__init__()
def read_config_file(self):
"""Read from config file"""
diff --git a/yardstick/benchmark/contexts/standalone.py b/yardstick/benchmark/contexts/standalone.py
index c1d963f50..eff700974 100644
--- a/yardstick/benchmark/contexts/standalone.py
+++ b/yardstick/benchmark/contexts/standalone.py
@@ -37,7 +37,7 @@ class StandaloneContext(Context):
self.file_path = None
self.nodes = []
self.nfvi_node = []
- super(self.__class__, self).__init__()
+ super(StandaloneContext, self).__init__()
def read_config_file(self):
"""Read from config file"""
diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
index 38a966803..24888af98 100644
--- a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
+++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
@@ -62,11 +62,11 @@ class GeneralAttacker(BaseAttacker):
self.fault_cfg['recovery_script'])
def inject_fault(self):
- LOG.debug("{0} starting inject!".format(self.key))
- LOG.debug("the inject_script path:{0}".format(self.inject_script))
+ LOG.debug("%s starting inject!", self.key)
+ LOG.debug("the inject_script path:%s", self.inject_script)
if "action_parameter" in self._config:
- LOG.debug("the shell command is: {0}".format(self.action_param))
+ LOG.debug("the shell command is: %s", self.action_param)
with open(self.inject_script, "r") as stdin_file:
exit_status, stdout, stderr = self.connection.execute(
self.action_param,
@@ -88,7 +88,7 @@ class GeneralAttacker(BaseAttacker):
def recover(self):
if "rollback_parameter" in self._config:
- LOG.debug("the shell command is: {0}".format(self.rollback_param))
+ LOG.debug("the shell command is: %s", self.rollback_param)
with open(self.recovery_script, "r") as stdin_file:
exit_status, stdout, stderr = self.connection.execute(
self.rollback_param,
diff --git a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
index 75c433a0e..8f987a647 100644
--- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
+++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
@@ -61,28 +61,26 @@ class GeneralResultChecker(BaseResultChecker):
exit_status, stdout, stderr = self.connection.execute(
self.shell_cmd,
stdin=stdin_file)
- LOG.debug("action script of the operation is: {0}"
- .format(self.verify_script))
- LOG.debug("action parameter the of operation is: {0}"
- .format(self.shell_cmd))
+ LOG.debug("action script of the operation is: %s",
+ self.verify_script)
+ LOG.debug("action parameter the of operation is: %s",
+ self.shell_cmd)
else:
with open(self.verify_script, "r") as stdin_file:
exit_status, stdout, stderr = self.connection.execute(
"/bin/bash -s ",
stdin=stdin_file)
- LOG.debug("action script of the operation is: {0}"
- .format(self.verify_script))
+ LOG.debug("action script of the operation is: %s",
+ self.verify_script)
LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
if exit_status == 0 and stdout:
self.actualResult = stdout
- LOG.debug("verifying resultchecker: {0}".format(self.key))
- LOG.debug("verifying resultchecker,expected: {0}"
- .format(self.expectedResult))
- LOG.debug("verifying resultchecker,actual: {0}"
- .format(self.actualResult))
- LOG.debug("verifying resultchecker,condition: {0}"
- .format(self.condition))
+ LOG.debug("verifying resultchecker: %s", self.key)
+ LOG.debug("verifying resultchecker,expected: %s",
+ self.expectedResult)
+ LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
+ LOG.debug("verifying resultchecker,condition: %s", self.condition)
if (type(self.expectedResult) is int):
self.actualResult = int(self.actualResult)
if self.condition == Condition.EQUAL:
@@ -100,13 +98,13 @@ class GeneralResultChecker(BaseResultChecker):
else:
self.success = False
LOG.debug(
- "error happened when resultchecker: {0} Invalid condition"
- .format(self.key))
+ "error happened when resultchecker: %s Invalid condition",
+ self.key)
else:
self.success = False
LOG.debug(
- "error happened when resultchecker: {0} verifying the result"
- .format(self.key))
+ "error happened when resultchecker: %s verifying the result",
+ self.key)
LOG.error(stderr)
LOG.debug(
diff --git a/yardstick/benchmark/scenarios/availability/scenario_general.py b/yardstick/benchmark/scenarios/availability/scenario_general.py
index 2d7ce664e..a950ef933 100644
--- a/yardstick/benchmark/scenarios/availability/scenario_general.py
+++ b/yardstick/benchmark/scenarios/availability/scenario_general.py
@@ -47,8 +47,8 @@ class ScenarioGeneral(base.Scenario):
except Exception:
LOG.exception("Exception")
LOG.debug(
- "\033[91m exception when running step: {0} .... \033[0m"
- .format(orderedSteps.index(step)))
+ "\033[91m exception when running step: %s .... \033[0m",
+ orderedSteps.index(step))
break
finally:
pass
diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py
index d7ba418c3..447c550ed 100644
--- a/yardstick/benchmark/scenarios/networking/vnf_generic.py
+++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py
@@ -15,7 +15,6 @@
from __future__ import absolute_import
import logging
-from contextlib import contextmanager
import yaml
from yardstick.benchmark.scenarios import base
@@ -49,31 +48,32 @@ class IncorrectSetup(Exception):
pass
-@contextmanager
-def ssh_manager(node):
- """
- args -> network device mappings
- returns -> ssh connection ready to be used
- """
- conn = None
- try:
- ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT)
- conn = ssh.SSH(user=node.get("user", ""),
- host=node.get("ip", ""),
- password=node.get("password", ""),
- port=ssh_port)
- conn.wait()
-
- except (SSHError) as error:
- LOG.info("connect failed to %s, due to %s", node.get("ip", ""), error)
- try:
- if conn:
- yield conn
- else:
- yield False
- finally:
- if conn:
- conn.close()
+class SshManager(object):
+ def __init__(self, node):
+ super(SshManager, self).__init__()
+ self.node = node
+ self.conn = None
+
+ def __enter__(self):
+ """
+ args -> network device mappings
+ returns -> ssh connection ready to be used
+ """
+ try:
+ ssh_port = self.node.get("ssh_port", ssh.DEFAULT_PORT)
+ self.conn = ssh.SSH(user=self.node["user"],
+ host=self.node["ip"],
+ password=self.node["password"],
+ port=ssh_port)
+ self.conn.wait()
+ except (SSHError) as error:
+ LOG.info("connect failed to %s, due to %s", self.node["ip"], error)
+ # self.conn defaults to None
+ return self.conn
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ if self.conn:
+ self.conn.close()
class NetworkServiceTestCase(base.Scenario):
@@ -208,7 +208,7 @@ class NetworkServiceTestCase(base.Scenario):
for node, node_dict in context_cfg["nodes"].items():
cmd = "PATH=$PATH:/sbin:/usr/sbin ip addr show"
- with ssh_manager(node_dict) as conn:
+ with SshManager(node_dict) as conn:
exit_status = conn.execute(cmd)[0]
if exit_status != 0:
raise IncorrectSetup("Node's %s lacks ip tool." % node)
@@ -237,10 +237,10 @@ class NetworkServiceTestCase(base.Scenario):
import_modules_from_package(
"yardstick.network_services.vnf_generic.vnf")
expected_name = vnf_model['id']
- impl = [c for c in itersubclasses(GenericVNF)
- if c.__name__ == expected_name]
+ impl = (c for c in itersubclasses(GenericVNF)
+ if c.__name__ == expected_name)
try:
- return next(iter(impl))
+ return next(impl)
except StopIteration:
raise IncorrectConfig("No implementation for %s", expected_name)
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index 20ab086e5..57c2b1526 100644
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -48,7 +48,7 @@ class TaskCommands(object):
self._init_result_file()
try:
- Task().start(param)
+ Task().start(param, **kwargs)
except Exception as e:
self._write_error_data(e)
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index e351d16d3..5026e819d 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -65,7 +65,7 @@ def get_credentials():
creds.update({"insecure": "True", "https_insecure": "True"})
if not os.path.isfile(cacert):
log.info("WARNING: The 'OS_CACERT' environment variable is set\
- to %s but the file does not exist." % cacert)
+ to %s but the file does not exist.", cacert)
return creds
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index 473bbf540..174ac0a5a 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -149,7 +149,8 @@ def get_neutron_client():
def write_json_to_file(path, data, mode='w'):
- write_file(path, jsonutils.dump_as_bytes(data), mode)
+ with open(path, mode) as f:
+ jsonutils.dump(data, f)
def write_file(path, data, mode='w'):
diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py
index 427e669a2..d388d28a1 100644
--- a/yardstick/dispatcher/influxdb.py
+++ b/yardstick/dispatcher/influxdb.py
@@ -164,7 +164,7 @@ class InfluxdbDispatcher(DispatchBase):
timeout=self.timeout)
if res.status_code != 204:
LOG.error('Test result posting finished with status code'
- ' %d.' % res.status_code)
+ ' %d.', res.status_code)
LOG.error(res.text)
except Exception as err:
diff --git a/yardstick/network_services/utils.py b/yardstick/network_services/utils.py
index b75091326..cb71a6029 100644
--- a/yardstick/network_services/utils.py
+++ b/yardstick/network_services/utils.py
@@ -15,18 +15,21 @@
from __future__ import absolute_import
import logging
+import os
from oslo_config import cfg
from oslo_config.cfg import NoSuchOptError
from oslo_utils import encodeutils
+NSB_ROOT = "/opt/nsb_bin"
+
CONF = cfg.CONF
OPTS = [
cfg.StrOpt('bin_path',
- default='/opt/nsb_bin',
+ default=NSB_ROOT,
help='bin_path for VNFs location.'),
cfg.StrOpt('trex_path',
- default='/opt/nsb_bin/trex/scripts',
+ default=os.path.join(NSB_ROOT, 'trex/scripts'),
help='trex automation lib pathh.'),
]
CONF.register_opts(OPTS, group="nsb")
@@ -39,8 +42,7 @@ def get_nsb_option(option, default=None):
return CONF.nsb.__getitem__(option)
except NoSuchOptError:
logging.debug("Invalid key %s", option)
- else:
- return default
+ return default
def provision_tool(connection, tool_path):
diff --git a/yardstick/network_services/vnf_generic/vnfdgen.py b/yardstick/network_services/vnf_generic/vnfdgen.py
index 9a02050a2..64554cdaf 100644
--- a/yardstick/network_services/vnf_generic/vnfdgen.py
+++ b/yardstick/network_services/vnf_generic/vnfdgen.py
@@ -16,7 +16,6 @@
from __future__ import absolute_import
import collections
import yaml
-import six
from yardstick.common.task_template import TaskTemplate
@@ -46,13 +45,14 @@ def dict_key_flatten(data):
"""
next_data = {}
+ # check for non-string iterables
if not any((isinstance(v, collections.Iterable) and not isinstance(v, str))
for v in data.values()):
return data
- for key, val in six.iteritems(data):
+ for key, val in data.items():
if isinstance(val, collections.Mapping):
- for n_k, n_v in six.iteritems(val):
+ for n_k, n_v in val.items():
next_data["%s.%s" % (key, n_k)] = n_v
elif isinstance(val, collections.Iterable) and not isinstance(val,
str):
diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py
index c098de9e3..e39c4356c 100644
--- a/yardstick/orchestrator/heat.py
+++ b/yardstick/orchestrator/heat.py
@@ -179,7 +179,7 @@ class HeatTemplate(HeatObject):
with open(template_file) as stream:
print("Parsing external template:", template_file)
template_str = stream.read()
- self._template = template_format.parse(template_str)
+ self._template = template_format.parse(template_str)
self._parameters = heat_parameters
else:
self._init_template()
diff --git a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
index 1904af20b..bbf55853d 100644
--- a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
+++ b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
@@ -18,9 +18,11 @@ Generation of the heat templates from the base template
"""
from __future__ import absolute_import
-import json
import os
import shutil
+
+from oslo_serialization import jsonutils
+
from experimental_framework import common
from experimental_framework.constants import framework_parameters as fp
@@ -193,7 +195,7 @@ def generates_templates(base_heat_template, deployment_configuration):
new_template += "_" + str(counter) + template_file_extension
shutil.copy(base_template, new_template)
- metadata = dict()
+ metadata = {}
for var in heat_template_vars:
if var.get_variable_name():
common.replace_in_file(new_template, "#" +
@@ -203,7 +205,8 @@ def generates_templates(base_heat_template, deployment_configuration):
# Save the metadata on a JSON file
with open(new_template + ".json", 'w') as outfile:
- json.dump(metadata, outfile)
+ # sort keys to maintain persistent order for git
+ jsonutils.dump(metadata, outfile, sort_keys=True)
common.LOG.debug("Heat Templates and Metadata file " + str(counter) +
" created")
@@ -222,7 +225,7 @@ def get_all_heat_templates(template_dir, template_file_extension):
(type: str)
:return: type: list
"""
- template_files = list()
+ template_files = []
for dirname, dirnames, filenames in os.walk(template_dir):
for filename in filenames:
if template_file_extension in filename and \
diff --git a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json
index 3af9a1cc7..44a8aeb2e 100644
--- a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json
+++ b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_1.yaml.json
@@ -1 +1 @@
-{"vnic_type": "normal", "ram": "1024", "vcpus": "2"} \ No newline at end of file
+{"ram": "1024", "vcpus": "2", "vnic_type": "normal"} \ No newline at end of file
diff --git a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json
index 9f246891d..0a66448b7 100644
--- a/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json
+++ b/yardstick/vTC/apexlake/tests/data/generated_templates/experiment_2.yaml.json
@@ -1 +1 @@
-{"vnic_type": "direct", "ram": "1024", "vcpus": "2"} \ No newline at end of file
+{"ram": "1024", "vcpus": "2", "vnic_type": "direct"} \ No newline at end of file