diff options
author | Ross Brattain <ross.b.brattain@intel.com> | 2016-12-05 16:11:54 -0500 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-01-12 18:25:04 -0800 |
commit | f036e9898a69f5041f9cde02e3652c29e2de1643 (patch) | |
tree | 36e5eea75811bb640bb30f442f5a3c617e945909 /tests/unit/benchmark/scenarios/availability | |
parent | 5f0b3d417244397b2d5e61c7a6ddd145f1d25046 (diff) |
Add support for Python 3
Porting to Python3 using Openstack guidelines:
https://wiki.openstack.org/wiki/Python3
This passes unittests on Python 3.5 and passes opnfv_smoke suite
Updates:
use six for urlparse and urlopen
fix exception.message attribute removal
run unittests on python3
use unitest.mock on python 3
fix open mock for vsperf
fix float division by using delta/eplison comparison
use unicode in StringIO
use plugin/sample_config.yaml relative path from test case
fixed apexlake unittests
upgraded to mock 2.0.0 to match python3 unittest.mock features
fixed flake8 issues
implement safe JSON decode with oslo_serialization.jsonutils.dump_as_bytes()
implement safe unicode encode/decode with oslo_utils.encodeutils
heat: convert pub key file from bytes to unicode
pkg_resources returns raw bytes, in python3
we have to decode this to utf-8 unicode
so JSON can encode it for heat template
JIRA: YARDSTICK-452
Change-Id: Ib80dd1d0c0eb0592acd832b82f6a7f8f7c20bfda
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/benchmark/scenarios/availability')
14 files changed, 173 insertions, 109 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py index 340f94cb0..9e2e8b172 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py @@ -9,15 +9,20 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal +# Unittest for +# yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal +from __future__ import absolute_import import mock import unittest -from yardstick.benchmark.scenarios.availability.attacker import baseattacker -from yardstick.benchmark.scenarios.availability.attacker import attacker_baremetal +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): @@ -26,34 +31,37 @@ 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): + def test__fun_execute_shell_command_fail_cmd_exception(self, + mock_subprocess): cmd = "env" mock_subprocess.check_output.side_effect = RuntimeError exitcode, output = attacker_baremetal._execute_shell_command(cmd) self.assertEqual(exitcode, -1) -@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal' + '.ssh') class AttackerBaremetalTestCase(unittest.TestCase): def setUp(self): - host = { - "ipmi_ip": "10.20.0.5", - "ipmi_user": "root", - "ipmi_pwd": "123456", - "ip": "10.20.0.5", - "user": "root", - "key_filename": "/root/.ssh/id_rsa" - } - self.context = {"node1": host} - self.attacker_cfg = { - 'fault_type': 'bear-metal-down', - 'host': 'node1', - } + host = { + "ipmi_ip": "10.20.0.5", + "ipmi_user": "root", + "ipmi_pwd": "123456", + "ip": "10.20.0.5", + "user": "root", + "key_filename": "/root/.ssh/id_rsa" + } + self.context = {"node1": host} + self.attacker_cfg = { + 'fault_type': 'bear-metal-down', + 'host': 'node1', + } def test__attacker_baremetal_all_successful(self, mock_ssh): - - ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) + ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, + self.context) mock_ssh.SSH().execute.return_value = (0, "running", '') ins.setup() @@ -61,8 +69,8 @@ class AttackerBaremetalTestCase(unittest.TestCase): ins.recover() def test__attacker_baremetal_check_failuer(self, mock_ssh): - - ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) + ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, + self.context) mock_ssh.SSH().execute.return_value = (0, "error check", '') ins.setup() @@ -70,7 +78,8 @@ class AttackerBaremetalTestCase(unittest.TestCase): self.attacker_cfg["jump_host"] = 'node1' self.context["node1"]["pwd"] = "123456" - ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) + ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, + self.context) mock_ssh.SSH().execute.return_value = (0, "running", '') ins.setup() diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py index aa2e0cc4d..322b58391 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py @@ -12,11 +12,13 @@ # Unittest for yardstick.benchmark.scenarios.availability.attacker # .attacker_general +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.attacker import baseattacker + @mock.patch('yardstick.benchmark.scenarios.availability.attacker.' 'attacker_general.ssh') class GeneralAttackerServiceTestCase(unittest.TestCase): @@ -30,10 +32,10 @@ class GeneralAttackerServiceTestCase(unittest.TestCase): self.context = {"node1": host} self.attacker_cfg = { 'fault_type': 'general-attacker', - 'action_parameter':{'process_name':'nova_api'}, - 'rollback_parameter':{'process_name':'nova_api'}, - 'key':'stop-service', - 'attack_key':'stop-service', + 'action_parameter': {'process_name': 'nova_api'}, + 'rollback_parameter': {'process_name': 'nova_api'}, + 'key': 'stop-service', + 'attack_key': 'stop-service', 'host': 'node1', } diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py index eb0cce70d..d7771bd33 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py @@ -9,14 +9,18 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.attacker.attacker_process +# Unittest for +# yardstick.benchmark.scenarios.availability.attacker.attacker_process +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.attacker import baseattacker -@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh') + +@mock.patch( + 'yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh') class AttackerServiceTestCase(unittest.TestCase): def setUp(self): diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py index a20cf8187..7030c7849 100644 --- a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py +++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py @@ -9,21 +9,25 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_command +# Unittest for +# yardstick.benchmark.scenarios.availability.monitor.monitor_command +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.monitor import basemonitor -@mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.BaseMonitor') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.basemonitor' + '.BaseMonitor') class MonitorMgrTestCase(unittest.TestCase): def setUp(self): config = { 'monitor_type': 'openstack-api', - 'key' : 'service-status' + 'key': 'service-status' } self.monitor_configs = [] @@ -42,10 +46,12 @@ class MonitorMgrTestCase(unittest.TestCase): monitorMgr.init_monitors(self.monitor_configs, None) monitorIns = monitorMgr['service-status'] + class BaseMonitorTestCase(unittest.TestCase): class MonitorSimple(basemonitor.BaseMonitor): __monitor_type__ = "MonitorForTest" + def setup(self): self.monitor_result = False @@ -65,14 +71,15 @@ class BaseMonitorTestCase(unittest.TestCase): ins.start_monitor() ins.wait_monitor() - def test__basemonitor_all_successful(self): ins = self.MonitorSimple(self.monitor_cfg, None) ins.setup() ins.run() ins.verify_SLA() - @mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.multiprocessing') + @mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.basemonitor' + '.multiprocessing') def test__basemonitor_func_false(self, mock_multiprocess): ins = self.MonitorSimple(self.monitor_cfg, None) ins.setup() @@ -87,4 +94,3 @@ class BaseMonitorTestCase(unittest.TestCase): except Exception: pass self.assertIsNone(cls) - diff --git a/tests/unit/benchmark/scenarios/availability/test_baseoperation.py b/tests/unit/benchmark/scenarios/availability/test_baseoperation.py index d85f1e19f..03ec1492b 100644 --- a/tests/unit/benchmark/scenarios/availability/test_baseoperation.py +++ b/tests/unit/benchmark/scenarios/availability/test_baseoperation.py @@ -9,26 +9,31 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.operation.baseoperation +# Unittest for +# yardstick.benchmark.scenarios.availability.operation.baseoperation +from __future__ import absolute_import import mock import unittest -from yardstick.benchmark.scenarios.availability.operation import baseoperation +from yardstick.benchmark.scenarios.availability.operation import baseoperation -@mock.patch('yardstick.benchmark.scenarios.availability.operation.baseoperation.BaseOperation') + +@mock.patch( + 'yardstick.benchmark.scenarios.availability.operation.baseoperation' + '.BaseOperation') class OperationMgrTestCase(unittest.TestCase): def setUp(self): config = { 'operation_type': 'general-operation', - 'key' : 'service-status' + 'key': 'service-status' } self.operation_configs = [] self.operation_configs.append(config) - def test_all_successful(self, mock_operation): + def test_all_successful(self, mock_operation): mgr_ins = baseoperation.OperationMgr() mgr_ins.init_operations(self.operation_configs, None) operation_ins = mgr_ins["service-status"] @@ -59,7 +64,7 @@ class BaseOperationTestCase(unittest.TestCase): def setUp(self): self.config = { 'operation_type': 'general-operation', - 'key' : 'service-status' + 'key': 'service-status' } def test_all_successful(self): @@ -70,7 +75,7 @@ class BaseOperationTestCase(unittest.TestCase): def test_get_script_fullpath(self): base_ins = baseoperation.BaseOperation(self.config, None) - base_ins.get_script_fullpath("ha_tools/test.bash"); + base_ins.get_script_fullpath("ha_tools/test.bash") def test_get_operation_cls_successful(self): base_ins = baseoperation.BaseOperation(self.config, None) diff --git a/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py b/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py index 9972d6b1b..36ce900fb 100644 --- a/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py +++ b/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py @@ -12,20 +12,22 @@ # Unittest for yardstick.benchmark.scenarios.availability.result_checker # .baseresultchecker +from __future__ import absolute_import import mock import unittest -from yardstick.benchmark.scenarios.availability.result_checker import baseresultchecker +from yardstick.benchmark.scenarios.availability.result_checker import \ + baseresultchecker @mock.patch('yardstick.benchmark.scenarios.availability.result_checker' - '.baseresultchecker.BaseResultChecker') + '.baseresultchecker.BaseResultChecker') class ResultCheckerMgrTestCase(unittest.TestCase): def setUp(self): config = { 'checker_type': 'general-result-checker', - 'key' : 'process-checker' + 'key': 'process-checker' } self.checker_configs = [] @@ -52,6 +54,7 @@ class BaseResultCheckerTestCase(unittest.TestCase): class ResultCheckeSimple(baseresultchecker.BaseResultChecker): __result_checker__type__ = "ResultCheckeForTest" + def setup(self): self.success = False @@ -61,7 +64,7 @@ class BaseResultCheckerTestCase(unittest.TestCase): def setUp(self): self.checker_cfg = { 'checker_type': 'general-result-checker', - 'key' : 'process-checker' + 'key': 'process-checker' } def test_baseresultchecker_setup_verify_successful(self): @@ -81,8 +84,10 @@ class BaseResultCheckerTestCase(unittest.TestCase): path = ins.get_script_fullpath("test.bash") def test_get_resultchecker_cls_successful(self): - baseresultchecker.BaseResultChecker.get_resultchecker_cls("ResultCheckeForTest") + baseresultchecker.BaseResultChecker.get_resultchecker_cls( + "ResultCheckeForTest") def test_get_resultchecker_cls_fail(self): with self.assertRaises(RuntimeError): - baseresultchecker.BaseResultChecker.get_resultchecker_cls("ResultCheckeNotExist") + baseresultchecker.BaseResultChecker.get_resultchecker_cls( + "ResultCheckeNotExist") diff --git a/tests/unit/benchmark/scenarios/availability/test_director.py b/tests/unit/benchmark/scenarios/availability/test_director.py index 06116725d..d01a60e2d 100644 --- a/tests/unit/benchmark/scenarios/availability/test_director.py +++ b/tests/unit/benchmark/scenarios/availability/test_director.py @@ -11,24 +11,26 @@ # Unittest for yardstick.benchmark.scenarios.availability.director +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.director import Director -from yardstick.benchmark.scenarios.availability import actionplayers @mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor') @mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker') -@mock.patch('yardstick.benchmark.scenarios.availability.director.baseoperation') -@mock.patch('yardstick.benchmark.scenarios.availability.director.baseresultchecker') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.director.baseoperation') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.director.baseresultchecker') class DirectorTestCase(unittest.TestCase): def setUp(self): self.scenario_cfg = { 'type': "general_scenario", 'options': { - 'attackers':[{ + 'attackers': [{ 'fault_type': "general-attacker", 'key': "kill-process"}], 'monitors': [{ @@ -36,11 +38,11 @@ class DirectorTestCase(unittest.TestCase): 'key': "service-status"}], 'operations': [{ 'operation_type': 'general-operation', - 'key' : 'service-status'}], + 'key': 'service-status'}], 'resultCheckers': [{ 'checker_type': 'general-result-checker', - 'key' : 'process-checker',}], - 'steps':[ + 'key': 'process-checker', }], + 'steps': [ { 'actionKey': "service-status", 'actionType': "operation", @@ -57,7 +59,7 @@ class DirectorTestCase(unittest.TestCase): 'actionKey': "service-status", 'actionType': "monitor", 'index': 4}, - ] + ] } } host = { @@ -67,15 +69,19 @@ class DirectorTestCase(unittest.TestCase): } self.ctx = {"nodes": {"node1": host}} - def test_director_all_successful(self, mock_checer, mock_opertion, mock_attacker, mock_monitor): + def test_director_all_successful(self, mock_checer, mock_opertion, + mock_attacker, mock_monitor): ins = Director(self.scenario_cfg, self.ctx) opertion_action = ins.createActionPlayer("operation", "service-status") attacker_action = ins.createActionPlayer("attacker", "kill-process") - checker_action = ins.createActionPlayer("resultchecker", "process-checker") + checker_action = ins.createActionPlayer("resultchecker", + "process-checker") monitor_action = ins.createActionPlayer("monitor", "service-status") - opertion_rollback = ins.createActionRollbacker("operation", "service-status") - attacker_rollback = ins.createActionRollbacker("attacker", "kill-process") + opertion_rollback = ins.createActionRollbacker("operation", + "service-status") + attacker_rollback = ins.createActionRollbacker("attacker", + "kill-process") ins.executionSteps.append(opertion_rollback) ins.executionSteps.append(attacker_rollback) @@ -91,13 +97,8 @@ class DirectorTestCase(unittest.TestCase): ins.verify() ins.knockoff() - def test_director_get_wrong_item(self, mock_checer, mock_opertion, mock_attacker, mock_monitor): + def test_director_get_wrong_item(self, mock_checer, mock_opertion, + mock_attacker, mock_monitor): ins = Director(self.scenario_cfg, self.ctx) ins.createActionPlayer("wrong_type", "wrong_key") ins.createActionRollbacker("wrong_type", "wrong_key") - - - - - - diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py index c8cda7dc7..a84bfd2c5 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py @@ -9,14 +9,19 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_command +# Unittest for +# yardstick.benchmark.scenarios.availability.monitor.monitor_command +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.monitor import monitor_command -@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.subprocess') + +@mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' + '.subprocess') class ExecuteShellTestCase(unittest.TestCase): def test__fun_execute_shell_command_successful(self, mock_subprocess): @@ -25,13 +30,17 @@ class ExecuteShellTestCase(unittest.TestCase): exitcode, output = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, 0) - def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess): + def test__fun_execute_shell_command_fail_cmd_exception(self, + mock_subprocess): cmd = "env" mock_subprocess.check_output.side_effect = RuntimeError exitcode, output = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, -1) -@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.subprocess') + +@mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' + '.subprocess') class MonitorOpenstackCmdTestCase(unittest.TestCase): def setUp(self): @@ -48,7 +57,6 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): 'sla': {'max_outage_time': 5} } - def test__monitor_command_monitor_func_successful(self, mock_subprocess): instance = monitor_command.MonitorOpenstackCmd(self.config, None) @@ -69,11 +77,15 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): instance._result = {"outage_time": 10} instance.verify_SLA() - @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.ssh') - def test__monitor_command_ssh_monitor_successful(self, mock_ssh, mock_subprocess): + @mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' + '.ssh') + def test__monitor_command_ssh_monitor_successful(self, mock_ssh, + mock_subprocess): self.config["host"] = "node1" - instance = monitor_command.MonitorOpenstackCmd(self.config, self.context) + instance = monitor_command.MonitorOpenstackCmd( + self.config, self.context) instance.setup() mock_ssh.SSH().execute.return_value = (0, "0", '') ret = instance.monitor_func() diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py index de7d26cbf..369f6f4f7 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py @@ -12,6 +12,7 @@ # Unittest for yardstick.benchmark.scenarios.availability.monitor # .monitor_general +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.monitor import monitor_general @@ -22,6 +23,7 @@ from yardstick.benchmark.scenarios.availability.monitor import monitor_general @mock.patch('yardstick.benchmark.scenarios.availability.monitor.' 'monitor_general.open') class GeneralMonitorServiceTestCase(unittest.TestCase): + def setUp(self): host = { "ip": "10.20.0.5", @@ -53,23 +55,26 @@ class GeneralMonitorServiceTestCase(unittest.TestCase): ins.setup() mock_ssh.SSH().execute.return_value = (0, "running", '') ins.monitor_func() - ins._result = {'outage_time' : 0} + ins._result = {'outage_time': 0} ins.verify_SLA() - def test__monitor_general_all_successful_noparam(self, mock_open, mock_ssh): - ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context) + def test__monitor_general_all_successful_noparam(self, mock_open, + mock_ssh): + ins = monitor_general.GeneralMonitor( + self.monitor_cfg_noparam, self.context) ins.setup() mock_ssh.SSH().execute.return_value = (0, "running", '') ins.monitor_func() - ins._result = {'outage_time' : 0} + ins._result = {'outage_time': 0} ins.verify_SLA() def test__monitor_general_failure(self, mock_open, mock_ssh): - ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context) + ins = monitor_general.GeneralMonitor( + self.monitor_cfg_noparam, self.context) ins.setup() mock_ssh.SSH().execute.return_value = (1, "error", 'error') ins.monitor_func() - ins._result = {'outage_time' : 2} + ins._result = {'outage_time': 2} ins.verify_SLA() diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_process.py b/tests/unit/benchmark/scenarios/availability/test_monitor_process.py index dda104b4e..8270405cd 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_process.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_process.py @@ -9,14 +9,18 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_process +# Unittest for +# yardstick.benchmark.scenarios.availability.monitor.monitor_process +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability.monitor import monitor_process -@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh') + +@mock.patch( + 'yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh') class MonitorProcessTestCase(unittest.TestCase): def setUp(self): @@ -53,4 +57,3 @@ class MonitorProcessTestCase(unittest.TestCase): ins.monitor_func() ins._result = {"outage_time": 10} ins.verify_SLA() - diff --git a/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/tests/unit/benchmark/scenarios/availability/test_operation_general.py index 26cd3f7c4..2c6dc1617 100644 --- a/tests/unit/benchmark/scenarios/availability/test_operation_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_operation_general.py @@ -12,9 +12,12 @@ # Unittest for yardstick.benchmark.scenarios.availability.operation # .operation_general +from __future__ import absolute_import import mock import unittest -from yardstick.benchmark.scenarios.availability.operation import operation_general +from yardstick.benchmark.scenarios.availability.operation import \ + operation_general + @mock.patch('yardstick.benchmark.scenarios.availability.operation.' 'operation_general.ssh') @@ -46,7 +49,7 @@ class GeneralOperaionTestCase(unittest.TestCase): def test__operation_successful(self, mock_open, mock_ssh): ins = operation_general.GeneralOperaion(self.operation_cfg, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "success", '') ins.setup() ins.run() @@ -54,7 +57,7 @@ class GeneralOperaionTestCase(unittest.TestCase): def test__operation_successful_noparam(self, mock_open, mock_ssh): ins = operation_general.GeneralOperaion(self.operation_cfg_noparam, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "success", '') ins.setup() ins.run() @@ -62,7 +65,7 @@ class GeneralOperaionTestCase(unittest.TestCase): def test__operation_fail(self, mock_open, mock_ssh): ins = operation_general.GeneralOperaion(self.operation_cfg, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (1, "failed", '') ins.setup() ins.run() diff --git a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py index bbadf0ac3..c5451fabd 100644 --- a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py @@ -12,11 +12,13 @@ # Unittest for yardstick.benchmark.scenarios.availability.result_checker # .result_checker_general +from __future__ import absolute_import import mock import unittest import copy -from yardstick.benchmark.scenarios.availability.result_checker import result_checker_general +from yardstick.benchmark.scenarios.availability.result_checker import \ + result_checker_general @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.' @@ -35,16 +37,16 @@ class GeneralResultCheckerTestCase(unittest.TestCase): self.checker_cfg = { 'parameter': {'processname': 'process'}, 'checker_type': 'general-result-checker', - 'condition' : 'eq', - 'expectedValue' : 1, - 'key' : 'process-checker', - 'checker_key' : 'process-checker', + 'condition': 'eq', + 'expectedValue': 1, + 'key': 'process-checker', + 'checker_key': 'process-checker', 'host': 'node1' } def test__result_checker_eq(self, mock_open, mock_ssh): ins = result_checker_general.GeneralResultChecker(self.checker_cfg, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -53,7 +55,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'gt' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "2", '') ins.setup() self.assertTrue(ins.verify()) @@ -62,7 +64,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'gt_eq' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -71,7 +73,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'lt' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "0", '') ins.setup() self.assertTrue(ins.verify()) @@ -80,7 +82,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'lt_eq' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -90,7 +92,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'in' config['expectedValue'] = "value" ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "value return", '') ins.setup() self.assertTrue(ins.verify()) @@ -99,7 +101,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'wrong' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertFalse(ins.verify()) @@ -108,7 +110,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config.pop('parameter') ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (1, "fail", '') ins.setup() - ins.verify()
\ No newline at end of file + ins.verify() diff --git a/tests/unit/benchmark/scenarios/availability/test_scenario_general.py b/tests/unit/benchmark/scenarios/availability/test_scenario_general.py index bab9d62f1..593fc77b3 100644 --- a/tests/unit/benchmark/scenarios/availability/test_scenario_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_scenario_general.py @@ -11,26 +11,29 @@ # Unittest for yardstick.benchmark.scenarios.availability.scenario_general +from __future__ import absolute_import import mock import unittest -from yardstick.benchmark.scenarios.availability.scenario_general import ScenarioGeneral +from yardstick.benchmark.scenarios.availability.scenario_general import \ + ScenarioGeneral -@mock.patch('yardstick.benchmark.scenarios.availability.scenario_general.Director') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.scenario_general.Director') class ScenarioGeneralTestCase(unittest.TestCase): def setUp(self): self.scenario_cfg = { 'type': "general_scenario", 'options': { - 'attackers':[{ + 'attackers': [{ 'fault_type': "general-attacker", 'key': "kill-process"}], 'monitors': [{ 'monitor_type': "general-monitor", 'key': "service-status"}], - 'steps':[ + 'steps': [ { 'actionKey': "kill-process", 'actionType': "attacker", diff --git a/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/tests/unit/benchmark/scenarios/availability/test_serviceha.py index 6e58b6e7a..4ae508958 100644 --- a/tests/unit/benchmark/scenarios/availability/test_serviceha.py +++ b/tests/unit/benchmark/scenarios/availability/test_serviceha.py @@ -11,13 +11,16 @@ # Unittest for yardstick.benchmark.scenarios.availability.serviceha +from __future__ import absolute_import import mock import unittest from yardstick.benchmark.scenarios.availability import serviceha + @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor') -@mock.patch('yardstick.benchmark.scenarios.availability.serviceha.baseattacker') +@mock.patch( + 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker') class ServicehaTestCase(unittest.TestCase): def setUp(self): @@ -48,7 +51,8 @@ class ServicehaTestCase(unittest.TestCase): sla = {"outage_time": 5} self.args = {"options": options, "sla": sla} - def test__serviceha_setup_run_successful(self, mock_attacker, mock_monitor): + def test__serviceha_setup_run_successful(self, mock_attacker, + mock_monitor): p = serviceha.ServiceHA(self.args, self.ctx) p.setup() |