aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py26
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py5
-rw-r--r--yardstick/vTC/apexlake/tests/deployment_unit_test.py21
-rw-r--r--yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py49
-rw-r--r--yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py6
5 files changed, 53 insertions, 54 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
index 28b27c78a..cc179602e 100644
--- a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
+++ b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
@@ -20,9 +20,7 @@ from yardstick.benchmark.scenarios.availability.attacker import \
attacker_baremetal
-@mock.patch(
- 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal'
- '.subprocess')
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
class ExecuteShellTestCase(unittest.TestCase):
def test__fun_execute_shell_command_successful(self, mock_subprocess):
@@ -31,17 +29,17 @@ class ExecuteShellTestCase(unittest.TestCase):
exitcode, output = attacker_baremetal._execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self,
- mock_subprocess):
+ @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.LOG')
+ def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, mock_subprocess):
cmd = "env"
mock_subprocess.check_output.side_effect = RuntimeError
exitcode, output = attacker_baremetal._execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
+ mock_log.error.assert_called_once()
-@mock.patch(
- 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal'
- '.ssh')
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh')
class AttackerBaremetalTestCase(unittest.TestCase):
def setUp(self):
@@ -59,28 +57,28 @@ class AttackerBaremetalTestCase(unittest.TestCase):
'host': 'node1',
}
- def test__attacker_baremetal_all_successful(self, mock_ssh):
+ def test__attacker_baremetal_all_successful(self, mock_ssh, mock_subprocess):
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
self.context)
- mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
ins.setup()
ins.inject_fault()
ins.recover()
- def test__attacker_baremetal_check_failuer(self, mock_ssh):
+ def test__attacker_baremetal_check_failuer(self, mock_ssh, mock_subprocess):
+ mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
self.context)
- mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
ins.setup()
- def test__attacker_baremetal_recover_successful(self, mock_ssh):
+ def test__attacker_baremetal_recover_successful(self, mock_ssh, mock_subprocess):
self.attacker_cfg["jump_host"] = 'node1'
self.context["node1"]["pwd"] = "123456"
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
self.context)
- mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
ins.setup()
ins.recover()
diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
index 22de0b645..50d44c1ca 100644
--- a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
+++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
@@ -9,7 +9,6 @@
from __future__ import absolute_import
import logging
import subprocess
-import traceback
import yardstick.ssh as ssh
from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \
@@ -26,9 +25,7 @@ def _execute_shell_command(command, stdin=None):
output = subprocess.check_output(command, stdin=stdin, shell=True)
except Exception:
exitcode = -1
- output = traceback.format_exc()
- LOG.error("exec command '%s' error:\n ", command)
- LOG.error(traceback.format_exc())
+ LOG.error("exec command '%s' error:\n ", command, exc_info=True)
return exitcode, output
diff --git a/yardstick/vTC/apexlake/tests/deployment_unit_test.py b/yardstick/vTC/apexlake/tests/deployment_unit_test.py
index 5a9178f53..1ff4225d6 100644
--- a/yardstick/vTC/apexlake/tests/deployment_unit_test.py
+++ b/yardstick/vTC/apexlake/tests/deployment_unit_test.py
@@ -130,6 +130,7 @@ class DummyDeploymentUnit(mut.DeploymentUnit):
raise Exception
+@mock.patch("experimental_framework.deployment_unit.time")
class TestDeploymentUnit(unittest.TestCase):
def setUp(self):
@@ -140,7 +141,7 @@ class TestDeploymentUnit(unittest.TestCase):
@mock.patch('experimental_framework.heat_manager.HeatManager',
side_effect=DummyHeatManager)
- def test_constructor_for_sanity(self, mock_heat_manager):
+ def test_constructor_for_sanity(self, mock_heat_manager, mock_time):
du = mut.DeploymentUnit(dict())
self.assertTrue(isinstance(du.heat_manager, DummyHeatManager))
mock_heat_manager.assert_called_once_with(dict())
@@ -150,7 +151,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManager)
@mock.patch('os.path.isfile')
def test_deploy_heat_template_for_failure(self, mock_os_is_file,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
mock_os_is_file.return_value = False
du = mut.DeploymentUnit(dict())
template_file = ''
@@ -163,7 +164,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManager)
@mock.patch('os.path.isfile')
def test_deploy_heat_template_for_success(self, mock_os_is_file,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
mock_os_is_file.return_value = True
du = mut.DeploymentUnit(dict())
template_file = ''
@@ -178,7 +179,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManagerComplete)
@mock.patch('os.path.isfile')
def test_deploy_heat_template_2_for_success(self, mock_os_is_file,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
mock_os_is_file.return_value = True
du = mut.DeploymentUnit(dict())
template_file = ''
@@ -196,7 +197,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyDeploymentUnit)
def test_deploy_heat_template_3_for_success(self, mock_dep_unit,
mock_os_is_file,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
mock_os_is_file.return_value = True
du = mut.DeploymentUnit(dict())
template_file = ''
@@ -212,7 +213,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManagerFailed)
@mock.patch('os.path.isfile')
def test_deploy_heat_template_for_success_2(self, mock_os_is_file,
- mock_heat_manager, mock_log):
+ mock_heat_manager, mock_log, mock_time):
mock_os_is_file.return_value = True
du = DummyDeploymentUnit(dict())
template_file = ''
@@ -226,7 +227,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManagerDestroy)
@mock.patch('experimental_framework.common.LOG')
def test_destroy_heat_template_for_success(self, mock_log,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
openstack_credentials = dict()
du = mut.DeploymentUnit(openstack_credentials)
du.deployed_stacks = ['stack']
@@ -238,14 +239,14 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManagerDestroyException)
@mock.patch('experimental_framework.common.LOG')
def test_destroy_heat_template_for_success_2(self, mock_log,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
openstack_credentials = dict()
du = mut.DeploymentUnit(openstack_credentials)
du.deployed_stacks = ['stack']
stack_name = 'stack'
self.assertFalse(du.destroy_heat_template(stack_name))
- def test_destroy_all_deployed_stacks_for_success(self):
+ def test_destroy_all_deployed_stacks_for_success(self, mock_time):
du = DeploymentUnitDestroy()
du.destroy_all_deployed_stacks()
self.assertTrue(du.destroy_heat_template())
@@ -254,7 +255,7 @@ class TestDeploymentUnit(unittest.TestCase):
side_effect=DummyHeatManagerReiteration)
@mock.patch('os.path.isfile')
def test_deploy_heat_template_for_success_3(self, mock_os_is_file,
- mock_heat_manager):
+ mock_heat_manager, mock_time):
mock_os_is_file.return_value = True
du = mut.DeploymentUnit(dict())
template = 'template_reiteration'
diff --git a/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py
index 96ead5ef7..9fa860ab4 100644
--- a/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py
+++ b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py
@@ -359,6 +359,7 @@ class MockRunCommand:
return MockRunCommand.ret_val_finalization
+@mock.patch('experimental_framework.packet_generators.dpdk_packet_generator.time')
class TestDpdkPacketGenOthers(unittest.TestCase):
def setUp(self):
@@ -370,7 +371,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
@mock.patch('experimental_framework.packet_generators.'
'dpdk_packet_generator.DpdkPacketGenerator.'
'_cores_configuration')
- def test__get_core_nics_for_failure(self, mock_cores_configuration):
+ def test__get_core_nics_for_failure(self, mock_cores_configuration, mock_time):
mock_cores_configuration.return_value = None
self.assertRaises(ValueError, mut.DpdkPacketGenerator._get_core_nics,
'', '')
@@ -379,7 +380,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
'dpdk_packet_generator.DpdkPacketGenerator.'
'_cores_configuration')
def test__get_core_nics_one_nic_for_success(self,
- mock_cores_configuration):
+ mock_cores_configuration, mock_time):
mock_cores_configuration.return_value = 'ret_val'
expected = 'ret_val'
output = mut.DpdkPacketGenerator._get_core_nics(1, 'coremask')
@@ -390,7 +391,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
'dpdk_packet_generator.DpdkPacketGenerator.'
'_cores_configuration')
def test__get_core_nics_two_nics_for_success(self,
- mock_cores_configuration):
+ mock_cores_configuration, mock_time):
mock_cores_configuration.return_value = 'ret_val'
expected = 'ret_val'
output = mut.DpdkPacketGenerator._get_core_nics(2, 'coremask')
@@ -398,7 +399,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
mock_cores_configuration.assert_called_once_with('coremask', 1, 2, 2)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_success(self, mock_is_file):
+ def test__init_input_validation_for_success(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_file_0 = 'pcap_file_0'
@@ -419,7 +420,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
variables), None)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_failure(self, mock_is_file):
+ def test__init_input_validation_for_failure(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_file_0 = 'pcap_file_0'
@@ -440,7 +441,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_failure_2(self, mock_is_file):
+ def test__init_input_validation_for_failure_2(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_directory = None
@@ -461,7 +462,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_failure_3(self, mock_is_file):
+ def test__init_input_validation_for_failure_3(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_directory = 'directory'
@@ -482,7 +483,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_failure_4(self, mock_is_file):
+ def test__init_input_validation_for_failure_4(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_directory = 'directory'
@@ -503,7 +504,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile')
- def test__init_input_validation_for_failure_5(self, mock_is_file):
+ def test__init_input_validation_for_failure_5(self, mock_is_file, mock_time):
mock_is_file.return_value = True
pcap_directory = 'directory'
@@ -524,7 +525,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile', side_effect=[False])
- def test__init_input_validation_for_failure_6(self, mock_is_file):
+ def test__init_input_validation_for_failure_6(self, mock_is_file, mock_time):
# mock_is_file.return_value = False
pcap_directory = 'directory'
@@ -545,7 +546,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile', side_effect=[True, False])
- def test__init_input_validation_for_failure_7(self, mock_is_file):
+ def test__init_input_validation_for_failure_7(self, mock_is_file, mock_time):
pcap_directory = 'directory'
pcap_file_0 = 'pcap_file_0'
pcap_file_1 = 'pcap_file_1'
@@ -564,7 +565,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.path.isfile', side_effect=[True, True, False])
- def test__init_input_validation_for_failure_8(self, mock_is_file):
+ def test__init_input_validation_for_failure_8(self, mock_is_file, mock_time):
pcap_directory = 'directory'
pcap_file_0 = 'pcap_file_0'
pcap_file_1 = 'pcap_file_1'
@@ -583,13 +584,13 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
lua_script, pcap_directory, lua_directory, variables)
@mock.patch('os.chdir')
- def test__chdir_for_success(self, mock_os_chdir):
+ def test__chdir_for_success(self, mock_os_chdir, mock_time):
mut.DpdkPacketGenerator._chdir('directory')
mock_os_chdir.assert_called_once_with('directory')
@mock.patch('experimental_framework.common.run_command',
side_effect=MockRunCommand.mock_run_command)
- def test__init_physical_nics_for_success(self, mock_run_command):
+ def test__init_physical_nics_for_success(self, mock_run_command, mock_time):
dpdk_interfaces = 1
dpdk_vars = dict()
@@ -608,7 +609,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
@mock.patch('experimental_framework.common.run_command',
side_effect=MockRunCommand.mock_run_command)
- def test__init_physical_nics_for_success_2(self, mock_run_command):
+ def test__init_physical_nics_for_success_2(self, mock_run_command, mock_time):
dpdk_interfaces = 2
dpdk_vars = dict()
@@ -626,7 +627,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
[True, True, True, True, True, True])
@mock.patch('experimental_framework.common.run_command')
- def test__init_physical_nics_for_failure(self, mock_run_command):
+ def test__init_physical_nics_for_failure(self, mock_run_command, mock_time):
dpdk_interfaces = 3
dpdk_vars = dict()
self.assertRaises(ValueError, self.mut._init_physical_nics,
@@ -634,7 +635,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
@mock.patch('experimental_framework.common.run_command',
side_effect=MockRunCommand.mock_run_command_finalization)
- def test__finalize_physical_nics_for_success(self, mock_run_command):
+ def test__finalize_physical_nics_for_success(self, mock_run_command, mock_time):
dpdk_interfaces = 1
dpdk_vars = dict()
dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
@@ -652,7 +653,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
@mock.patch('experimental_framework.common.run_command',
side_effect=MockRunCommand.mock_run_command_finalization)
- def test__finalize_physical_nics_for_success_2(self, mock_run_command):
+ def test__finalize_physical_nics_for_success_2(self, mock_run_command, mock_time):
dpdk_interfaces = 2
dpdk_vars = dict()
dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
@@ -668,34 +669,34 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
self.assertEqual(MockRunCommand.mock_run_command_finalization(),
[True, True, True, True, True, True])
- def test__finalize_physical_nics_for_failure(self):
+ def test__finalize_physical_nics_for_failure(self, mock_time):
dpdk_interfaces = 0
dpdk_vars = dict()
self.assertRaises(ValueError, self.mut._finalize_physical_nics,
dpdk_interfaces, dpdk_vars)
- def test__cores_configuration_for_success(self):
+ def test__cores_configuration_for_success(self, mock_time):
coremask = '1f'
expected = '[2:1].0,[4:3].1'
output = mut.DpdkPacketGenerator._cores_configuration(coremask,
1, 2, 2)
self.assertEqual(expected, output)
- def test__cores_configuration_for_success_2(self):
+ def test__cores_configuration_for_success_2(self, mock_time):
coremask = '1f'
expected = '2.0,[4:3].1'
output = mut.DpdkPacketGenerator._cores_configuration(coremask,
1, 1, 2)
self.assertEqual(expected, output)
- def test__cores_configuration_for_success_3(self):
+ def test__cores_configuration_for_success_3(self, mock_time):
coremask = '1f'
expected = '[3:2].0,4.1'
output = mut.DpdkPacketGenerator._cores_configuration(coremask,
1, 2, 1)
self.assertEqual(expected, output)
- def test__cores_configuration_for_failure(self):
+ def test__cores_configuration_for_failure(self, mock_time):
coremask = '1'
self.assertRaises(ValueError,
mut.DpdkPacketGenerator._cores_configuration,
@@ -703,7 +704,7 @@ class TestDpdkPacketGenOthers(unittest.TestCase):
@mock.patch('experimental_framework.common.LOG')
@mock.patch('experimental_framework.common.run_command')
- def test__change_vlan_for_success(self, mock_run_command, mock_log):
+ def test__change_vlan_for_success(self, mock_run_command, mock_log, mock_time):
mut.DpdkPacketGenerator._change_vlan('/directory/', 'pcap_file', '10')
expected_param = '/directory/vlan_tag.sh /directory/pcap_file 10'
mock_run_command.assert_called_with(expected_param)
diff --git a/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py
index 2bd8b7b38..69c5d745e 100644
--- a/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py
+++ b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py
@@ -257,6 +257,7 @@ class InstantiationValidationInitTest(unittest.TestCase):
self.assertEqual(dummy_os_kill('', '', True), [1, 1])
self.assertEqual(dummy_run_command('', True), [1, 1, 0, 0, 0])
+ @mock.patch('experimental_framework.benchmarks.instantiation_validation_benchmark.time')
@mock.patch('os.chdir')
@mock.patch('experimental_framework.common.run_command',
side_effect=dummy_run_command_2)
@@ -265,7 +266,7 @@ class InstantiationValidationInitTest(unittest.TestCase):
'InstantiationValidationBenchmark._get_pids')
@mock.patch('os.kill', side_effect=dummy_os_kill)
def test__init_packet_checker_for_success(self, mock_kill, mock_pids,
- mock_run_command, mock_chdir):
+ mock_run_command, mock_chdir, mock_time):
global command_counter
command_counter = [0, 0, 0, 0, 0]
mock_pids.return_value = [1234, 4321]
@@ -314,13 +315,14 @@ class InstantiationValidationInitTest(unittest.TestCase):
self.assertEqual(dummy_replace_in_file('', '', '', True),
[0, 0, 0, 1, 1, 1])
+ @mock.patch('experimental_framework.benchmarks.instantiation_validation_benchmark.time')
@mock.patch('experimental_framework.common.LOG')
@mock.patch('experimental_framework.packet_generators.'
'dpdk_packet_generator.DpdkPacketGenerator',
side_effect=DummyDpdkPacketGenerator)
@mock.patch('experimental_framework.common.get_dpdk_pktgen_vars')
def test_run_for_success(self, mock_common_get_vars, mock_pktgen,
- mock_log):
+ mock_log, mock_time):
rval = dict()
rval[cfs.CFSP_DPDK_BUS_SLOT_NIC_2] = 'bus_2'
rval[cfs.CFSP_DPDK_NAME_IF_2] = 'if_2'