diff options
Diffstat (limited to 'tests/unit')
49 files changed, 610 insertions, 370 deletions
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index 8f4852ca8..b56d0c86d 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -21,6 +21,7 @@ import uuid import mock from yardstick.benchmark.contexts import heat +from yardstick.benchmark.contexts import model LOG = logging.getLogger(__name__) @@ -102,12 +103,18 @@ class HeatContextTestCase(unittest.TestCase): self.test_context.keypair_name = "foo-key" self.test_context.secgroup_name = "foo-secgroup" self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b" + netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} + self.mock_context.name = 'bar' + self.test_context.networks = [model.Network("fool-network", self.mock_context, netattrs)] self.test_context._add_resources_to_template(mock_template) mock_template.add_keypair.assert_called_with( "foo-key", "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b") mock_template.add_security_group.assert_called_with("foo-secgroup") + mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None) + mock_template.add_router.assert_called_with("bar-fool-network-router", netattrs["external_network"], "bar-fool-network-subnet") + mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", "bar-fool-network-router", "bar-fool-network-subnet") @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_deploy(self, mock_template): diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py index a8314aef4..122f100de 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -12,8 +12,8 @@ # Unittest for yardstick.benchmark.contexts.model from __future__ import absolute_import -import mock import unittest +import mock from yardstick.benchmark.contexts import model @@ -170,6 +170,9 @@ class ServerTestCase(unittest.TestCase): self.mock_context.keypair_name = 'some-keys' self.mock_context.secgroup_name = 'some-secgroup' self.mock_context.user = "some-user" + netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} + self.mock_context.networks = [model.Network("some-network", self.mock_context, netattrs)] + def test_construct_defaults(self): @@ -208,13 +211,16 @@ class ServerTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance(self, mock_template): - attrs = {'image': 'some-image', 'flavor': 'some-flavor'} + attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', 'floating_ip_assoc': 'some-vm'} test_server = model.Server('foo', self.mock_context, attrs) mock_network = mock.Mock() mock_network.name = 'some-network' mock_network.stack_name = 'some-network-stack' mock_network.subnet_stack_name = 'some-network-stack-subnet' + mock_network.provider = 'sriov' + mock_network.external_network = 'ext_net' + mock_network.router = model.Router('some-router', 'some-network', self.mock_context, 'ext_net') test_server._add_instance(mock_template, 'some-server', [mock_network], 'hints') @@ -223,7 +229,22 @@ class ServerTestCase(unittest.TestCase): 'some-server-some-network-port', mock_network.stack_name, mock_network.subnet_stack_name, - sec_group_id=self.mock_context.secgroup_name) + sec_group_id=self.mock_context.secgroup_name, + provider=mock_network.provider) + + mock_template.add_floating_ip.assert_called_with( + 'some-server-fip', + mock_network.external_network, + 'some-server-some-network-port', + 'bar-some-network-some-router-if0', + 'some-secgroup' + ) + + mock_template.add_floating_ip_association.assert_called_with( + 'some-server-fip-assoc', + 'some-server-fip', + 'some-server-some-network-port' + ) mock_template.add_server.assert_called_with( 'some-server', 'some-image', 'some-flavor', diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py index 53a8ffa93..4b35ca421 100644 --- a/tests/unit/benchmark/contexts/test_node.py +++ b/tests/unit/benchmark/contexts/test_node.py @@ -127,27 +127,23 @@ class NodeContextTestCase(unittest.TestCase): prefix = 'yardstick.benchmark.contexts.node' - @mock.patch('{}.NodeContext._execute_script'.format(prefix)) - def test_deploy(self, execute_script_mock): + @mock.patch('{}.NodeContext._dispatch_script'.format(prefix)) + def test_deploy(self, dispatch_script_mock): obj = node.NodeContext() obj.env = { - 'setup': [ - {'node5': {}} - ] + 'type': 'script' } obj.deploy() - self.assertTrue(execute_script_mock.called) + self.assertTrue(dispatch_script_mock.called) - @mock.patch('{}.NodeContext._execute_script'.format(prefix)) - def test_undeploy(self, execute_script_mock): + @mock.patch('{}.NodeContext._dispatch_script'.format(prefix)) + def test_undeploy(self, dispatch_script_mock): obj = node.NodeContext() obj.env = { - 'teardown': [ - {'node5': {}} - ] + 'type': 'script' } obj.undeploy() - self.assertTrue(execute_script_mock.called) + self.assertTrue(dispatch_script_mock.called) @mock.patch('{}.ssh.SSH._put_file_shell'.format(prefix)) @mock.patch('{}.ssh.SSH.execute'.format(prefix)) diff --git a/tests/unit/benchmark/core/test_plugin.py b/tests/unit/benchmark/core/test_plugin.py index edc103415..f9c076159 100644 --- a/tests/unit/benchmark/core/test_plugin.py +++ b/tests/unit/benchmark/core/test_plugin.py @@ -41,7 +41,7 @@ class pluginTestCase(unittest.TestCase): def test_install(self, mock_ssh): p = plugin.Plugin() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') input_file = Arg() p.install(input_file) expected_result = {} @@ -49,7 +49,7 @@ class pluginTestCase(unittest.TestCase): def test_remove(self, mock_ssh): p = plugin.Plugin() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') input_file = Arg() p.remove(input_file) expected_result = {} @@ -57,7 +57,7 @@ class pluginTestCase(unittest.TestCase): def test_install_setup_run(self, mock_ssh): p = plugin.Plugin() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') plugins = { "name": "sample" } @@ -76,7 +76,7 @@ class pluginTestCase(unittest.TestCase): def test_remove_setup_run(self, mock_ssh): p = plugin.Plugin() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') plugins = { "name": "sample" } diff --git a/tests/unit/benchmark/core/test_report.py b/tests/unit/benchmark/core/test_report.py new file mode 100644 index 000000000..69546928c --- /dev/null +++ b/tests/unit/benchmark/core/test_report.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2017 Rajesh Kudaka. +# +# 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.core.report + +from __future__ import print_function + +from __future__ import absolute_import + +import unittest +import uuid + +try: + from unittest import mock +except ImportError: + import mock + +from yardstick.benchmark.core import report +from yardstick.cmd.commands import change_osloobj_to_paras + +FAKE_YAML_NAME = 'fake_name' +FAKE_TASK_ID = str(uuid.uuid4()) +FAKE_DB_FIELDKEYS = [{'fieldKey': 'fake_key'}] +FAKE_TIME = '0000-00-00T00:00:00.000000Z' +FAKE_DB_TASK = [{'fake_key': 0.000, 'time': FAKE_TIME}] +FAKE_TIMESTAMP = ['fake_time'] +DUMMY_TASK_ID = 'aaaaaa-aaaaaaaa-aaaaaaaaaa-aaaaaa' + + +class ReportTestCase(unittest.TestCase): + + def setUp(self): + super(ReportTestCase, self).setUp() + self.param = change_osloobj_to_paras({}) + self.param.yaml_name = [FAKE_YAML_NAME] + self.param.task_id = [FAKE_TASK_ID] + self.rep = report.Report() + + @mock.patch('yardstick.benchmark.core.report.Report._get_tasks') + @mock.patch('yardstick.benchmark.core.report.Report._get_fieldkeys') + @mock.patch('yardstick.benchmark.core.report.Report._validate') + def test_generate_success(self, mock_valid, mock_keys, mock_tasks): + mock_tasks.return_value = FAKE_DB_TASK + mock_keys.return_value = FAKE_DB_FIELDKEYS + self.rep.generate(self.param) + mock_valid.assert_called_once_with(FAKE_YAML_NAME, FAKE_TASK_ID) + self.assertEqual(1, mock_tasks.call_count) + self.assertEqual(1, mock_keys.call_count) + + def test_invalid_yaml_name(self): + self.assertRaisesRegexp(ValueError, "yaml*", self.rep._validate, + 'F@KE_NAME', FAKE_TASK_ID) + + def test_invalid_task_id(self): + self.assertRaisesRegexp(ValueError, "task*", self.rep._validate, + FAKE_YAML_NAME, DUMMY_TASK_ID) + + @mock.patch('api.utils.influx.query') + def test_task_not_found(self, mock_query): + mock_query.return_value = [] + self.rep.yaml_name = FAKE_YAML_NAME + self.rep.task_id = FAKE_TASK_ID + self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_fieldkeys) + self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_tasks) diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py index 9e2e8b172..28b27c78a 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py @@ -63,7 +63,7 @@ class AttackerBaremetalTestCase(unittest.TestCase): ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.inject_fault() ins.recover() @@ -71,7 +71,7 @@ class AttackerBaremetalTestCase(unittest.TestCase): def test__attacker_baremetal_check_failuer(self, mock_ssh): ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "error check", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '') ins.setup() def test__attacker_baremetal_recover_successful(self, mock_ssh): @@ -81,6 +81,6 @@ class AttackerBaremetalTestCase(unittest.TestCase): ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.recover() diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py index 322b58391..612b5a662 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py @@ -44,7 +44,7 @@ class GeneralAttackerServiceTestCase(unittest.TestCase): cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg) ins = cls(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.inject_fault() ins.recover() @@ -54,5 +54,5 @@ class GeneralAttackerServiceTestCase(unittest.TestCase): cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg) ins = cls(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "error check", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '') ins.setup() diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py index d7771bd33..eec512a58 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py @@ -41,7 +41,7 @@ class AttackerServiceTestCase(unittest.TestCase): cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg) ins = cls(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.inject_fault() ins.recover() @@ -51,5 +51,5 @@ class AttackerServiceTestCase(unittest.TestCase): cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg) ins = cls(self.attacker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "error check", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '') ins.setup() diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py index a84bfd2c5..c179bbfaf 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py @@ -87,5 +87,5 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): instance = monitor_command.MonitorOpenstackCmd( self.config, self.context) instance.setup() - mock_ssh.SSH().execute.return_value = (0, "0", '') + mock_ssh.SSH.from_node().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 369f6f4f7..169b630bf 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py @@ -53,7 +53,7 @@ class GeneralMonitorServiceTestCase(unittest.TestCase): ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context) ins.setup() - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.monitor_func() ins._result = {'outage_time': 0} ins.verify_SLA() @@ -64,7 +64,7 @@ class GeneralMonitorServiceTestCase(unittest.TestCase): self.monitor_cfg_noparam, self.context) ins.setup() - mock_ssh.SSH().execute.return_value = (0, "running", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.monitor_func() ins._result = {'outage_time': 0} ins.verify_SLA() @@ -74,7 +74,7 @@ class GeneralMonitorServiceTestCase(unittest.TestCase): self.monitor_cfg_noparam, self.context) ins.setup() - mock_ssh.SSH().execute.return_value = (1, "error", 'error') + mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error') ins.monitor_func() 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 8270405cd..8c267e413 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_process.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_process.py @@ -42,7 +42,7 @@ class MonitorProcessTestCase(unittest.TestCase): ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "1", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "1", '') ins.setup() ins.monitor_func() ins._result = {"outage_time": 0} @@ -52,7 +52,7 @@ class MonitorProcessTestCase(unittest.TestCase): ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "0", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "0", '') ins.setup() ins.monitor_func() ins._result = {"outage_time": 10} diff --git a/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/tests/unit/benchmark/scenarios/availability/test_operation_general.py index 2c6dc1617..fb8ccb122 100644 --- a/tests/unit/benchmark/scenarios/availability/test_operation_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_operation_general.py @@ -50,7 +50,7 @@ class GeneralOperaionTestCase(unittest.TestCase): def test__operation_successful(self, mock_open, mock_ssh): ins = operation_general.GeneralOperaion(self.operation_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "success", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "success", '') ins.setup() ins.run() ins.rollback() @@ -58,7 +58,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) - mock_ssh.SSH().execute.return_value = (0, "success", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "success", '') ins.setup() ins.run() ins.rollback() @@ -66,7 +66,7 @@ class GeneralOperaionTestCase(unittest.TestCase): def test__operation_fail(self, mock_open, mock_ssh): ins = operation_general.GeneralOperaion(self.operation_cfg, self.context) - mock_ssh.SSH().execute.return_value = (1, "failed", '') + mock_ssh.SSH.from_node().execute.return_value = (1, "failed", '') ins.setup() ins.run() ins.rollback() 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 c5451fabd..d036bb0da 100644 --- a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py @@ -47,7 +47,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): def test__result_checker_eq(self, mock_open, mock_ssh): ins = result_checker_general.GeneralResultChecker(self.checker_cfg, self.context) - mock_ssh.SSH().execute.return_value = (0, "1", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -56,7 +56,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'gt' ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "2", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "2", '') ins.setup() self.assertTrue(ins.verify()) @@ -65,7 +65,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'gt_eq' ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "1", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -74,7 +74,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'lt' ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "0", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "0", '') ins.setup() self.assertTrue(ins.verify()) @@ -83,7 +83,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'lt_eq' ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "1", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -93,7 +93,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['expectedValue'] = "value" ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "value return", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "value return", '') ins.setup() self.assertTrue(ins.verify()) @@ -102,7 +102,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'wrong' ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (0, "1", '') + mock_ssh.SSH.from_node().execute.return_value = (0, "1", '') ins.setup() self.assertFalse(ins.verify()) @@ -111,6 +111,6 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config.pop('parameter') ins = result_checker_general.GeneralResultChecker(config, self.context) - mock_ssh.SSH().execute.return_value = (1, "fail", '') + mock_ssh.SSH.from_node().execute.return_value = (1, "fail", '') ins.setup() 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 593fc77b3..ea54fbb9b 100644 --- a/tests/unit/benchmark/scenarios/availability/test_scenario_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_scenario_general.py @@ -48,7 +48,7 @@ class ScenarioGeneralTestCase(unittest.TestCase): def test_scenario_general_all_successful(self, mock_director): ins = ScenarioGeneral(self.scenario_cfg, None) ins.setup() - ins.run(None) + ins.run({}) ins.teardown() def test_scenario_general_exception(self, mock_director): @@ -56,7 +56,7 @@ class ScenarioGeneralTestCase(unittest.TestCase): mock_obj = mock.Mock() mock_obj.createActionPlayer.side_effect = KeyError('Wrong') ins.director = mock_obj - ins.run(None) + ins.run({}) ins.teardown() def test_scenario_general_case_fail(self, mock_director): @@ -64,5 +64,5 @@ class ScenarioGeneralTestCase(unittest.TestCase): mock_obj = mock.Mock() mock_obj.verify.return_value = False ins.director = mock_obj - ins.run(None) + ins.run({}) ins.teardown() diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py new file mode 100644 index 000000000..bb0e6bc79 --- /dev/null +++ b/tests/unit/benchmark/scenarios/availability/test_util.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2016 Kanglin Yin and others +# 14_ykl@tongji.edu.cn +# 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.availability.utils + +import mock +import unittest + +from yardstick.benchmark.scenarios.availability import util + +@mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess') +class ExecuteShellTestCase(unittest.TestCase): + + def test__fun_execute_shell_command_successful(self, mock_subprocess): + cmd = "env" + mock_subprocess.check_output.return_value = (0, 'unittest') + exitcode, output = util.execute_shell_command(cmd) + self.assertEqual(exitcode, 0) + + def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess): + cmd = "env" + mock_subprocess.check_output.side_effect = RuntimeError + exitcode, output = util.execute_shell_command(cmd) + self.assertEqual(exitcode, -1) diff --git a/tests/unit/benchmark/scenarios/compute/test_cachestat.py b/tests/unit/benchmark/scenarios/compute/test_cachestat.py index 8a06c754b..b0ddfc6b4 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cachestat.py +++ b/tests/unit/benchmark/scenarios/compute/test_cachestat.py @@ -35,7 +35,7 @@ class CACHEstatTestCase(unittest.TestCase): def test_cachestat_successful_setup(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) @@ -43,20 +43,20 @@ class CACHEstatTestCase(unittest.TestCase): def test_execute_command_success(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = c._execute_command("foo") self.assertEqual(result, expected_result) def test_execute_command_failed(self, mock_ssh): c = cachestat.CACHEstat({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'Failed executing \ + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'Failed executing \ command') self.assertRaises(RuntimeError, c._execute_command, "cat /proc/meminfo") @@ -67,11 +67,11 @@ class CACHEstatTestCase(unittest.TestCase): } args = {"options": options} c = cachestat.CACHEstat(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() output = self._read_file("cachestat_sample_output.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = c._get_cache_usage() expected_result = {"cachestat": {"cache0": {"HITS": "6462", "DIRTIES": "29", diff --git a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py index 4efa66932..7b9a5ad4a 100644 --- a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py +++ b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py @@ -45,7 +45,7 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_successful_setup(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) @@ -54,7 +54,7 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_successful(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads(SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) @@ -62,5 +62,5 @@ class ComputeCapacityTestCase(unittest.TestCase): def test_capacity_unsuccessful_script_error(self, mock_ssh): c = computecapacity.ComputeCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_cpuload.py b/tests/unit/benchmark/scenarios/compute/test_cpuload.py index ffa781215..840ac7885 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cpuload.py +++ b/tests/unit/benchmark/scenarios/compute/test_cpuload.py @@ -42,7 +42,7 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() self.assertIsNotNone(l.client) @@ -58,7 +58,7 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (127, '', '') + mock_ssh.SSH.from_node().execute.return_value = (127, '', '') l.setup() self.assertIsNotNone(l.client) @@ -74,11 +74,11 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = l._execute_command("foo") self.assertEqual(result, expected_result) @@ -91,10 +91,10 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'abcdefg') + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'abcdefg') self.assertRaises(RuntimeError, l._execute_command, "cat /proc/loadavg") @@ -107,10 +107,10 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() - mock_ssh.SSH().execute.return_value = \ + mock_ssh.SSH.from_node().execute.return_value = \ (0, '1.50 1.45 1.51 3/813 14322', '') result = l._get_loadavg() expected_result = \ @@ -126,13 +126,13 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() l.interval = 1 l.count = 1 mpstat_output = self._read_file("cpuload_sample_output1.txt") - mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '') result = l._get_cpu_usage_mpstat() expected_result = \ @@ -175,12 +175,12 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() l.interval = 0 output = self._read_file("cpuload_sample_output2.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = l._get_cpu_usage() expected_result = \ @@ -219,12 +219,12 @@ class CPULoadTestCase(unittest.TestCase): args = {'options': options} l = cpuload.CPULoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') l.setup() l.interval = 0 stat_output = self._read_file("cpuload_sample_output2.txt") - mock_ssh.SSH().execute.side_effect = \ + mock_ssh.SSH.from_node().execute.side_effect = \ [(0, '1.50 1.45 1.51 3/813 14322', ''), (0, stat_output, '')] l.run(self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py index 04ca2abf9..dc52a80c7 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py +++ b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py @@ -69,7 +69,7 @@ class CyclictestTestCase(unittest.TestCase): def test_cyclictest_successful_setup(self, mock_ssh): c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.guest) @@ -80,12 +80,12 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.pop("sla", None) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') c.run(result) expected_result = jsonutils.loads(sample_output) @@ -101,12 +101,12 @@ class CyclictestTestCase(unittest.TestCase): } }) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') c.run(result) expected_result = jsonutils.loads(sample_output) @@ -117,13 +117,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_min_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh): @@ -131,13 +131,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_avg_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh): @@ -145,13 +145,13 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_max_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() sample_output = '{"min": 100, "avg": 500, "max": 1000}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, c.run, result) def test_cyclictest_unsuccessful_script_error(self, mock_ssh): @@ -159,12 +159,12 @@ class CyclictestTestCase(unittest.TestCase): result = {} self.scenario_cfg.update({"sla": {"max_max_latency": 10}}) c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() - c.guest = mock_ssh.SSH() + c.guest = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, result) diff --git a/tests/unit/benchmark/scenarios/compute/test_lmbench.py b/tests/unit/benchmark/scenarios/compute/test_lmbench.py index 5b72ef75d..08f5da332 100644 --- a/tests/unit/benchmark/scenarios/compute/test_lmbench.py +++ b/tests/unit/benchmark/scenarios/compute/test_lmbench.py @@ -38,7 +38,7 @@ class LmbenchTestCase(unittest.TestCase): def test_successful_setup(self, mock_ssh): l = lmbench.Lmbench({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') l.setup() self.assertIsNotNone(l.client) @@ -66,7 +66,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 4.944, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads( '{"latencies": ' + sample_output + "}") @@ -84,7 +84,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -103,7 +103,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 4.944, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads( '{"latencies": ' + sample_output + "}") @@ -124,7 +124,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -143,7 +143,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '[{"latency": 37.5, "size": 0.00049}]' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, l.run, self.result) def test_unsuccessful_bandwidth_run_sla(self, mock_ssh): @@ -161,7 +161,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, l.run, self.result) def test_successful_latency_for_cache_run_sla(self, mock_ssh): @@ -178,7 +178,7 @@ class LmbenchTestCase(unittest.TestCase): l = lmbench.Lmbench(args, self.ctx) sample_output = "{\"L1cache\": 1.6}" - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') l.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -189,5 +189,5 @@ class LmbenchTestCase(unittest.TestCase): args = {"options": options} l = lmbench.Lmbench(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, l.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_memload.py b/tests/unit/benchmark/scenarios/compute/test_memload.py index ede3309c2..ebae9993d 100644 --- a/tests/unit/benchmark/scenarios/compute/test_memload.py +++ b/tests/unit/benchmark/scenarios/compute/test_memload.py @@ -35,7 +35,7 @@ class MEMLoadTestCase(unittest.TestCase): def test_memload_successful_setup(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() self.assertIsNotNone(m.client) @@ -43,20 +43,20 @@ class MEMLoadTestCase(unittest.TestCase): def test_execute_command_success(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = m._execute_command("foo") self.assertEqual(result, expected_result) def test_execute_command_failed(self, mock_ssh): m = memload.MEMLoad({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'Failed executing \ + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'Failed executing \ command') self.assertRaises(RuntimeError, m._execute_command, "cat /proc/meminfo") @@ -68,11 +68,11 @@ class MEMLoadTestCase(unittest.TestCase): } args = {"options": options} m = memload.MEMLoad(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') m.setup() output = self._read_file("memload_sample_output.txt") - mock_ssh.SSH().execute.return_value = (0, output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, output, '') result = m._get_mem_usage() expected_result = { "max": { diff --git a/tests/unit/benchmark/scenarios/compute/test_plugintest.py b/tests/unit/benchmark/scenarios/compute/test_plugintest.py index a5331caf7..680f6ad65 100644 --- a/tests/unit/benchmark/scenarios/compute/test_plugintest.py +++ b/tests/unit/benchmark/scenarios/compute/test_plugintest.py @@ -40,7 +40,7 @@ class PluginTestTestCase(unittest.TestCase): def test_sample_successful_setup(self, mock_ssh): s = plugintest.PluginTest({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') s.setup() self.assertIsNotNone(s.client) @@ -50,7 +50,7 @@ class PluginTestTestCase(unittest.TestCase): s = plugintest.PluginTest({}, self.ctx) sample_output = '{"Test Output": "Hello world!"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') s.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -58,5 +58,5 @@ class PluginTestTestCase(unittest.TestCase): def test_sample_unsuccessful_script_error(self, mock_ssh): s = plugintest.PluginTest({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, s.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py index 82cc93870..85d49641e 100644 --- a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py +++ b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py @@ -38,7 +38,7 @@ class RamspeedTestCase(unittest.TestCase): def test_ramspeed_successful_setup(self, mock_ssh): r = ramspeed.Ramspeed({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') r.setup() self.assertIsNotNone(r.client) @@ -75,7 +75,7 @@ class RamspeedTestCase(unittest.TestCase): {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -111,7 +111,7 @@ class RamspeedTestCase(unittest.TestCase): {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -146,7 +146,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\ "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\ "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, r.run, self.result) def test_ramspeed_unsuccessful_script_error(self, mock_ssh): @@ -158,7 +158,7 @@ class RamspeedTestCase(unittest.TestCase): args = {"options": options} r = ramspeed.Ramspeed(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, r.run, self.result) def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh): @@ -177,7 +177,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 9401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -198,7 +198,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 9401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') r.run(self.result) expected_result = jsonutils.loads(sample_output) self.assertEqual(self.result, expected_result) @@ -219,7 +219,7 @@ class RamspeedTestCase(unittest.TestCase): "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\ "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\ "Bandwidth(MBps)": 2401.58}]}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, r.run, self.result) def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh): @@ -231,7 +231,7 @@ class RamspeedTestCase(unittest.TestCase): args = {'options': options} r = ramspeed.Ramspeed(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'No such type_id: 30 for \ + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \ Ramspeed scenario') self.assertRaises(RuntimeError, r.run, self.result) diff --git a/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/tests/unit/benchmark/scenarios/compute/test_unixbench.py index 747bda1ed..7d071e91c 100644 --- a/tests/unit/benchmark/scenarios/compute/test_unixbench.py +++ b/tests/unit/benchmark/scenarios/compute/test_unixbench.py @@ -38,7 +38,7 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench({}, self.ctx) u.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(u.client) self.assertEqual(u.setup_done, True) @@ -54,10 +54,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"Score":"4425.4"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -76,10 +76,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"Score":"4425.4"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -102,10 +102,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') u.run(result) expected_result = jsonutils.loads(sample_output) @@ -120,10 +120,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, u.run, result) def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh): @@ -135,10 +135,10 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, u.run, result) def test_unixbench_unsuccessful_script_error(self, mock_ssh): @@ -158,9 +158,9 @@ class UnixbenchTestCase(unittest.TestCase): u = unixbench.Unixbench(args, self.ctx) result = {} - u.server = mock_ssh.SSH() + u.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, u.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_iperf3.py b/tests/unit/benchmark/scenarios/networking/test_iperf3.py index ea53cb9ab..45ff1b779 100644 --- a/tests/unit/benchmark/scenarios/networking/test_iperf3.py +++ b/tests/unit/benchmark/scenarios/networking/test_iperf3.py @@ -45,29 +45,29 @@ class IperfTestCase(unittest.TestCase): def test_iperf_successful_setup(self, mock_ssh): p = iperf3.Iperf({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p.setup() self.assertIsNotNone(p.target) self.assertIsNotNone(p.host) - mock_ssh.SSH().execute.assert_called_with("iperf3 -s -D") + mock_ssh.SSH.from_node().execute.assert_called_with("iperf3 -s -D") def test_iperf_unsuccessful_setup(self, mock_ssh): p = iperf3.Iperf({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.setup) def test_iperf_successful_teardown(self, mock_ssh): p = iperf3.Iperf({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() - p.target = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() + p.target = mock_ssh.SSH.from_node() p.teardown() - self.assertTrue(mock_ssh.SSH().close.called) - mock_ssh.SSH().execute.assert_called_with("pkill iperf3") + self.assertTrue(mock_ssh.SSH.from_node().close.called) + mock_ssh.SSH.from_node().execute.assert_called_with("pkill iperf3") def test_iperf_successful_no_sla(self, mock_ssh): @@ -76,11 +76,11 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.output_name_tcp) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -95,11 +95,11 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.output_name_tcp) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -114,11 +114,11 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.output_name_tcp) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_iperf_successful_sla_jitter(self, mock_ssh): @@ -130,11 +130,11 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.output_name_udp) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -148,11 +148,11 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.output_name_udp) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_iperf_unsuccessful_script_error(self, mock_ssh): @@ -162,10 +162,10 @@ class IperfTestCase(unittest.TestCase): result = {} p = iperf3.Iperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) def _read_sample_output(self, filename): diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf.py b/tests/unit/benchmark/scenarios/networking/test_netperf.py index 1b5dd6472..d0f862fb5 100755 --- a/tests/unit/benchmark/scenarios/networking/test_netperf.py +++ b/tests/unit/benchmark/scenarios/networking/test_netperf.py @@ -43,7 +43,7 @@ class NetperfTestCase(unittest.TestCase): def test_netperf_successful_setup(self, mock_ssh): p = netperf.Netperf({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p.setup() self.assertIsNotNone(p.server) @@ -57,11 +57,11 @@ class NetperfTestCase(unittest.TestCase): result = {} p = netperf.Netperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -76,11 +76,11 @@ class NetperfTestCase(unittest.TestCase): result = {} p = netperf.Netperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -95,11 +95,11 @@ class NetperfTestCase(unittest.TestCase): result = {} p = netperf.Netperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_netperf_unsuccessful_script_error(self, mock_ssh): @@ -109,10 +109,10 @@ class NetperfTestCase(unittest.TestCase): result = {} p = netperf.Netperf(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) def _read_sample_output(self): diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py index 29a7edf67..62874cc44 100755 --- a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py +++ b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py @@ -43,7 +43,7 @@ class NetperfNodeTestCase(unittest.TestCase): def test_netperf_node_successful_setup(self, mock_ssh): p = netperf_node.NetperfNode({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p.setup() self.assertIsNotNone(p.server) @@ -57,11 +57,11 @@ class NetperfNodeTestCase(unittest.TestCase): result = {} p = netperf_node.NetperfNode(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -76,11 +76,11 @@ class NetperfNodeTestCase(unittest.TestCase): result = {} p = netperf_node.NetperfNode(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') expected_result = jsonutils.loads(sample_output) p.run(result) self.assertEqual(result, expected_result) @@ -95,11 +95,11 @@ class NetperfNodeTestCase(unittest.TestCase): result = {} p = netperf_node.NetperfNode(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() sample_output = self._read_sample_output() - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_netperf_node_unsuccessful_script_error(self, mock_ssh): @@ -109,10 +109,10 @@ class NetperfNodeTestCase(unittest.TestCase): result = {} p = netperf_node.NetperfNode(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') - p.host = mock_ssh.SSH() + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + p.host = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) def _read_sample_output(self): diff --git a/tests/unit/benchmark/scenarios/networking/test_netutilization.py b/tests/unit/benchmark/scenarios/networking/test_netutilization.py index 7c04f5e9a..1227e056e 100644 --- a/tests/unit/benchmark/scenarios/networking/test_netutilization.py +++ b/tests/unit/benchmark/scenarios/networking/test_netutilization.py @@ -42,7 +42,7 @@ class NetUtilizationTestCase(unittest.TestCase): args = {'options': options} n = netutilization.NetUtilization(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') n.setup() self.assertIsNotNone(n.client) @@ -56,11 +56,11 @@ class NetUtilizationTestCase(unittest.TestCase): args = {'options': options} n = netutilization.NetUtilization(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') n.setup() expected_result = 'abcdefg' - mock_ssh.SSH().execute.return_value = (0, expected_result, '') + mock_ssh.SSH.from_node().execute.return_value = (0, expected_result, '') result = n._execute_command("foo") self.assertEqual(result, expected_result) @@ -72,10 +72,10 @@ class NetUtilizationTestCase(unittest.TestCase): args = {'options': options} n = netutilization.NetUtilization(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') n.setup() - mock_ssh.SSH().execute.return_value = (127, '', 'abcdefg') + mock_ssh.SSH.from_node().execute.return_value = (127, '', 'abcdefg') self.assertRaises(RuntimeError, n._execute_command, "failed") @@ -87,11 +87,11 @@ class NetUtilizationTestCase(unittest.TestCase): args = {'options': options} n = netutilization.NetUtilization(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') n.setup() mpstat_output = self._read_file("netutilization_sample_output1.txt") - mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '') result = n._get_network_utilization() expected_result = \ @@ -157,11 +157,11 @@ class NetUtilizationTestCase(unittest.TestCase): args = {'options': options} n = netutilization.NetUtilization(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') n.setup() mpstat_output = self._read_file("netutilization_sample_output2.txt") - mock_ssh.SSH().execute.return_value = (0, mpstat_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, mpstat_output, '') result = n._get_network_utilization() expected_result = \ diff --git a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py index 3f8d84e54..3e7a3c5ee 100644 --- a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py +++ b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py @@ -41,7 +41,7 @@ class NetworkCapacityTestCase(unittest.TestCase): def test_capacity_successful_setup(self, mock_ssh): c = networkcapacity.NetworkCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) self.assertTrue(c.setup_done) @@ -49,7 +49,7 @@ class NetworkCapacityTestCase(unittest.TestCase): def test_capacity_successful(self, mock_ssh): c = networkcapacity.NetworkCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads(SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) @@ -57,5 +57,5 @@ class NetworkCapacityTestCase(unittest.TestCase): def test_capacity_unsuccessful_script_error(self, mock_ssh): c = networkcapacity.NetworkCapacity({}, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, self.result) diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py index 87a766302..131716727 100644 --- a/tests/unit/benchmark/scenarios/networking/test_nstat.py +++ b/tests/unit/benchmark/scenarios/networking/test_nstat.py @@ -36,7 +36,7 @@ class NstatTestCase(unittest.TestCase): n = nstat.Nstat({}, self.ctx) n.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(n.client) self.assertEqual(n.setup_done, True) @@ -53,7 +53,7 @@ class NstatTestCase(unittest.TestCase): 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, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') n.run(result) expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318, @@ -81,7 +81,7 @@ class NstatTestCase(unittest.TestCase): 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, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') n.run(result) expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318, @@ -107,7 +107,7 @@ class NstatTestCase(unittest.TestCase): n = nstat.Nstat(args, self.ctx) result = {} - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, n.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_ping.py b/tests/unit/benchmark/scenarios/networking/test_ping.py index 5535a79a9..5269309c2 100644 --- a/tests/unit/benchmark/scenarios/networking/test_ping.py +++ b/tests/unit/benchmark/scenarios/networking/test_ping.py @@ -43,7 +43,7 @@ class PingTestCase(unittest.TestCase): p = ping.Ping(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '100', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '100', '') p.run(result) self.assertEqual(result, {'rtt': {'ares': 100.0}}) @@ -59,7 +59,7 @@ class PingTestCase(unittest.TestCase): p = ping.Ping(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '100', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '100', '') p.run(result) self.assertEqual(result, {'rtt': {'ares': 100.0}}) @@ -75,7 +75,7 @@ class PingTestCase(unittest.TestCase): p = ping.Ping(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '100', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '100', '') self.assertRaises(AssertionError, p.run, result) @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh') @@ -90,7 +90,7 @@ class PingTestCase(unittest.TestCase): p = ping.Ping(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_ping6.py b/tests/unit/benchmark/scenarios/networking/test_ping6.py index e22cacb36..ecce7cee5 100644 --- a/tests/unit/benchmark/scenarios/networking/test_ping6.py +++ b/tests/unit/benchmark/scenarios/networking/test_ping6.py @@ -56,7 +56,7 @@ class PingTestCase(unittest.TestCase): 'sla': {'max_rtt': 50} } p = ping6.Ping6(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '0', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '0', '') p.setup() self.assertEqual(p.setup_done, True) @@ -70,8 +70,8 @@ class PingTestCase(unittest.TestCase): result = {} p = ping6.Ping6(args, self.ctx) - p.client = mock_ssh.SSH() - mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] + p.client = mock_ssh.SSH.from_node() + mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] p.run(result) self.assertEqual(result, {'rtt': 100.0}) @@ -84,8 +84,8 @@ class PingTestCase(unittest.TestCase): result = {} p = ping6.Ping6(args, self.ctx) - p.client = mock_ssh.SSH() - mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] + p.client = mock_ssh.SSH.from_node() + mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] p.run(result) self.assertEqual(result, {'rtt': 100.0}) @@ -98,8 +98,8 @@ class PingTestCase(unittest.TestCase): result = {} p = ping6.Ping6(args, self.ctx) - p.client = mock_ssh.SSH() - mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] + p.client = mock_ssh.SSH.from_node() + mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')] self.assertRaises(AssertionError, p.run, result) @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh') @@ -112,8 +112,8 @@ class PingTestCase(unittest.TestCase): result = {} p = ping6.Ping6(args, self.ctx) - p.client = mock_ssh.SSH() - mock_ssh.SSH().execute.side_effect = [ + p.client = mock_ssh.SSH.from_node() + mock_ssh.SSH.from_node().execute.side_effect = [ (0, 'host1', ''), (1, '', 'FOOBAR')] self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py index f50fa108c..d4eb1246f 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py @@ -47,7 +47,7 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) p.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) @@ -58,14 +58,14 @@ class PktgenTestCase(unittest.TestCase): 'options': {'packetsize': 60, 'number_of_ports': 10}, } p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() p.number_of_ports = args['options']['number_of_ports'] - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p._iptables_setup() - mock_ssh.SSH().execute.assert_called_with( + mock_ssh.SSH.from_node().execute.assert_called_with( "sudo iptables -F; " "sudo iptables -A INPUT -p udp --dport 1000:%s -j DROP" % 1010) @@ -77,10 +77,10 @@ class PktgenTestCase(unittest.TestCase): } p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() p.number_of_ports = args['options']['number_of_ports'] - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p._iptables_setup) def test_pktgen_successful_iptables_get_result(self, mock_ssh): @@ -90,13 +90,13 @@ class PktgenTestCase(unittest.TestCase): } p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() p.number_of_ports = args['options']['number_of_ports'] - mock_ssh.SSH().execute.return_value = (0, '150000', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '150000', '') p._iptables_get_result() - mock_ssh.SSH().execute.assert_called_with( + mock_ssh.SSH.from_node().execute.assert_called_with( "sudo iptables -L INPUT -vnx |" "awk '/dpts:1000:%s/ {{printf \"%%s\", $1}}'" % 1010) @@ -109,10 +109,10 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() p.number_of_ports = args['options']['number_of_ports'] - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p._iptables_get_result) def test_pktgen_successful_no_sla(self, mock_ssh): @@ -124,16 +124,16 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() - p.client = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() mock_iptables_result = mock.Mock() mock_iptables_result.return_value = 149300 p._iptables_get_result = mock_iptables_result sample_output = '{"packets_per_second": 9753, "errors": 0, \ - "packets_sent": 149776, "flows": 110}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + "packets_sent": 149776, "packetsize": 60, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) expected_result = jsonutils.loads(sample_output) @@ -150,16 +150,16 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() - p.client = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() mock_iptables_result = mock.Mock() mock_iptables_result.return_value = 149300 p._iptables_get_result = mock_iptables_result sample_output = '{"packets_per_second": 9753, "errors": 0, \ - "packets_sent": 149776, "flows": 110}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + "packets_sent": 149776, "packetsize": 60, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) expected_result = jsonutils.loads(sample_output) @@ -176,16 +176,16 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() - p.client = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() mock_iptables_result = mock.Mock() mock_iptables_result.return_value = 149300 p._iptables_get_result = mock_iptables_result sample_output = '{"packets_per_second": 9753, "errors": 0, \ - "packets_sent": 149776, "flows": 110}' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + "packets_sent": 149776, "packetsize": 60, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_pktgen_unsuccessful_script_error(self, mock_ssh): @@ -198,10 +198,10 @@ class PktgenTestCase(unittest.TestCase): p = pktgen.Pktgen(args, self.ctx) - p.server = mock_ssh.SSH() - p.client = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py index 7ba4db9d9..496ee770c 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py @@ -45,7 +45,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) p.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) @@ -56,13 +56,13 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p.get_port_ip(p.server, "eth1") - mock_ssh.SSH().execute.assert_called_with( + mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' \ |cut -d ':' -f2 ") @@ -73,9 +73,9 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.get_port_ip, p.server, "eth1") def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh): @@ -84,13 +84,13 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') p.get_port_mac(p.server, "eth1") - mock_ssh.SSH().execute.assert_called_with( + mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ") def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh): @@ -100,9 +100,9 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.get_port_mac, p.server, "eth1") def test_pktgen_dpdk_successful_no_sla(self, mock_ssh): @@ -115,7 +115,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) # with python 3 we get float, might be due python division changes @@ -135,7 +135,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -151,11 +151,11 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH() - p.client = mock_ssh.SSH() + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n' - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh): @@ -168,7 +168,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_sfc.py b/tests/unit/benchmark/scenarios/networking/test_sfc.py index 224a43bd8..78c0352dd 100644 --- a/tests/unit/benchmark/scenarios/networking/test_sfc.py +++ b/tests/unit/benchmark/scenarios/networking/test_sfc.py @@ -21,22 +21,22 @@ from yardstick.benchmark.scenarios.networking import sfc class SfcTestCase(unittest.TestCase): def setUp(self): - scenario_cfg = dict() - context_cfg = dict() - - # Used in Sfc.setup() - context_cfg['target'] = dict() - context_cfg['target']['user'] = 'root' - context_cfg['target']['password'] = 'opnfv' - context_cfg['target']['ip'] = '127.0.0.1' - - # Used in Sfc.run() - context_cfg['host'] = dict() - context_cfg['host']['user'] = 'root' - context_cfg['host']['password'] = 'opnfv' - context_cfg['host']['ip'] = None - context_cfg['target'] = dict() - context_cfg['target']['ip'] = '127.0.0.1' + scenario_cfg = {} + context_cfg = { + # Used in Sfc.setup() + 'target': { + 'user': 'root', + 'password': 'opnfv', + 'ip': '127.0.0.1', + }, + + # Used in Sfc.run() + 'host': { + 'user': 'root', + 'password': 'opnfv', + 'ip': None, + } + } self.sfc = sfc.Sfc(scenario_cfg=scenario_cfg, context_cfg=context_cfg) @@ -45,7 +45,7 @@ class SfcTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess') def test_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh): # Mock a successfull SSH in Sfc.setup() and Sfc.run() - mock_ssh.SSH().execute.return_value = (0, '100', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '100', '') mock_openstack.get_an_IP.return_value = "127.0.0.1" mock_subprocess.call.return_value = 'mocked!' @@ -59,7 +59,7 @@ class SfcTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess') def test2_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh): # Mock a successfull SSH in Sfc.setup() and Sfc.run() - mock_ssh.SSH().execute.return_value = ( + mock_ssh.SSH.from_node().execute.return_value = ( 0, 'vxlan_tool.py', 'succeeded timed out') mock_openstack.get_an_IP.return_value = "127.0.0.1" mock_subprocess.call.return_value = 'mocked!' diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 1b02b6eff..4167d6f3b 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -316,7 +316,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock for node, node_dict in self.context_cfg["nodes"].items(): with SshManager(node_dict) as conn: self.assertIsNotNone(conn) @@ -357,7 +357,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock self.s.map_topology_to_infrastructure(self.context_cfg, self.topology) self.assertEqual("tg_trex_tpl.yaml", @@ -371,7 +371,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock self.assertRaises(IncorrectSetup, self.s.map_topology_to_infrastructure, @@ -384,7 +384,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock self.assertRaises(IncorrectConfig, self.s.map_topology_to_infrastructure, @@ -395,7 +395,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock del self.context_cfg['nodes'] self.assertRaises(IncorrectConfig, self.s._resolve_topology, @@ -428,7 +428,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock tgen = mock.Mock(autospec=GenericTrafficGen) tgen.traffic_finished = True diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py index 76d2afdc0..348aa4a63 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py @@ -63,7 +63,7 @@ class VsperfTestCase(unittest.TestCase): def test_vsperf_setup(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -74,7 +74,7 @@ class VsperfTestCase(unittest.TestCase): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -88,12 +88,12 @@ class VsperfTestCase(unittest.TestCase): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') - mock_ssh.SSH().execute.return_value = ( + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') result = {} @@ -106,11 +106,11 @@ class VsperfTestCase(unittest.TestCase): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) @@ -119,12 +119,12 @@ class VsperfTestCase(unittest.TestCase): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/storage/test_fio.py b/tests/unit/benchmark/scenarios/storage/test_fio.py index 603ff389e..55e443885 100644 --- a/tests/unit/benchmark/scenarios/storage/test_fio.py +++ b/tests/unit/benchmark/scenarios/storage/test_fio.py @@ -51,7 +51,7 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) p.setup() - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) @@ -67,10 +67,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['rw']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -92,10 +92,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['read']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -116,10 +116,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['write']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -143,10 +143,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['rw']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -171,10 +171,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['rw']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_fio_successful_bw_iops_sla(self, mock_ssh): @@ -192,10 +192,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['rw']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) @@ -220,10 +220,10 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() sample_output = self._read_sample_output(self.sample_output['rw']) - mock_ssh.SSH().execute.return_value = (0, sample_output, '') + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) def test_fio_unsuccessful_script_error(self, mock_ssh): @@ -238,9 +238,9 @@ class FioTestCase(unittest.TestCase): p = fio.Fio(args, self.ctx) result = {} - p.client = mock_ssh.SSH() + p.client = mock_ssh.SSH.from_node() - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) def _read_sample_output(self, file_name): diff --git a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py index 6fb5f5686..095674f72 100644 --- a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py +++ b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py @@ -50,7 +50,7 @@ class StorageCapacityTestCase(unittest.TestCase): def test_capacity_successful_setup(self, mock_ssh): c = storagecapacity.StorageCapacity(self.scn, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') c.setup() self.assertIsNotNone(c.client) self.assertTrue(c.setup_done) @@ -58,7 +58,7 @@ class StorageCapacityTestCase(unittest.TestCase): def test_capacity_disk_size_successful(self, mock_ssh): c = storagecapacity.StorageCapacity(self.scn, self.ctx) - mock_ssh.SSH().execute.return_value = (0, DISK_SIZE_SAMPLE_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, DISK_SIZE_SAMPLE_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads( DISK_SIZE_SAMPLE_OUTPUT) @@ -72,7 +72,7 @@ class StorageCapacityTestCase(unittest.TestCase): } c = storagecapacity.StorageCapacity(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, BLOCK_SIZE_SAMPLE_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, BLOCK_SIZE_SAMPLE_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads( BLOCK_SIZE_SAMPLE_OUTPUT) @@ -88,7 +88,7 @@ class StorageCapacityTestCase(unittest.TestCase): } c = storagecapacity.StorageCapacity(args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, DISK_UTIL_RAW_OUTPUT, '') + mock_ssh.SSH.from_node().execute.return_value = (0, DISK_UTIL_RAW_OUTPUT, '') c.run(self.result) expected_result = jsonutils.loads( DISK_UTIL_SAMPLE_OUTPUT) @@ -97,7 +97,7 @@ class StorageCapacityTestCase(unittest.TestCase): def test_capacity_unsuccessful_script_error(self, mock_ssh): c = storagecapacity.StorageCapacity(self.scn, self.ctx) - mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, self.result) diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py index adc9d47c6..00054d531 100644 --- a/tests/unit/benchmark/scenarios/storage/test_storperf.py +++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py @@ -55,7 +55,7 @@ def mocked_requests_job_get(*args, **kwargs): self.status_code = status_code return MockResponseJobGet( - '{"status": "completed",\ + '{"Status": "Completed",\ "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}', 200) @@ -171,7 +171,7 @@ class StorPerfTestCase(unittest.TestCase): s = storperf.StorPerf(args, self.ctx) s.setup_done = True - sample_output = '{"status": "completed",\ + sample_output = '{"Status": "Completed",\ "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}' expected_result = jsonutils.loads(sample_output) diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py index 267c71312..8f52b53b0 100644 --- a/tests/unit/common/test_utils.py +++ b/tests/unit/common/test_utils.py @@ -87,24 +87,21 @@ class ImportModulesFromPackageTestCase(unittest.TestCase): class GetParaFromYaml(unittest.TestCase): - def test_get_para_from_yaml_file_not_exist(self): - file_path = '/etc/yardstick/hello.yaml' - args = 'hello.world' - para = utils.get_para_from_yaml(file_path, args) - self.assertIsNone(para) - - def test_get_para_from_yaml_para_not_found(self): + @mock.patch('yardstick.common.utils.os.environ.get') + def test_get_param_para_not_found(self, get_env): file_path = 'config_sample.yaml' - file_path = self._get_file_abspath(file_path) + get_env.return_value = self._get_file_abspath(file_path) args = 'releng.file' - self.assertIsNone(utils.get_para_from_yaml(file_path, args)) + default = 'hello' + self.assertTrue(utils.get_param(args, default), default) - def test_get_para_from_yaml_para_exists(self): + @mock.patch('yardstick.common.utils.os.environ.get') + def test_get_param_para_exists(self, get_env): file_path = 'config_sample.yaml' - file_path = self._get_file_abspath(file_path) + get_env.return_value = self._get_file_abspath(file_path) args = 'releng.dir' para = '/home/opnfv/repos/releng' - self.assertEqual(para, utils.get_para_from_yaml(file_path, args)) + self.assertEqual(para, utils.get_param(args)) def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index 26d18838b..e2640ac74 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -90,7 +90,7 @@ class TestResourceProfile(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, {}, "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock self.resource_profile = \ ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0], @@ -120,7 +120,7 @@ class TestResourceProfile(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock resource_profile = \ ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0], [1, 2, 3]) @@ -132,7 +132,7 @@ class TestResourceProfile(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock resource_profile = \ ResourceProfile(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0], [1, 2, 3]) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 4f0855543..88df7788b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -141,7 +141,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(ping_traffic_gen._queue, None) @@ -152,7 +152,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock ping_traffic_gen = PingTrafficGen(vnfd) ping_traffic_gen._queue = Queue() ping_traffic_gen._queue.put({}) @@ -165,7 +165,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.instantiate({}, {})) @@ -176,7 +176,7 @@ class TestPingTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.listen_traffic({})) @@ -191,7 +191,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = PingTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -210,7 +210,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = PingTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -228,7 +228,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" ping_traffic_gen = PingTrafficGen(vnfd) @@ -241,7 +241,7 @@ class TestPingTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.terminate()) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index eda5cea84..4ea180851 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -195,7 +195,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertIsNotNone(trex_traffic_gen._terminated) @@ -206,7 +206,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) restult = trex_traffic_gen.collect_kpi() @@ -218,7 +218,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen.listen_traffic({})) @@ -233,7 +233,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) trex_traffic_gen._start_server = mock.Mock(return_value=0) @@ -251,7 +251,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(1, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"} @@ -265,7 +265,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual([0.8, 1.0], @@ -282,7 +282,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen._start_server()) @@ -304,7 +304,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGenRFC(vnfd) self.sut.connection = mock.Mock() @@ -327,7 +327,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) result = ['0x00', '0x00', '0x00', '0x00', '0x00', '0x01'] @@ -342,7 +342,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) tg_rfc2544_trex.WAIT_TIME = 1 @@ -358,7 +358,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGenRFC(vnfd) self.sut.connection = mock.Mock() @@ -376,7 +376,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" trex_traffic_gen = TrexTrafficGenRFC(vnfd) @@ -389,7 +389,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGenRFC(vnfd) self.assertEqual(None, trex_traffic_gen.terminate()) @@ -399,7 +399,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGenRFC(vnfd) client = mock.Mock(autospec=STLClient) client.connect = mock.Mock(return_value=0) 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 a76fbbd2a..ca8421919 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 @@ -176,7 +176,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertIsNotNone(trex_traffic_gen._terminated) @@ -187,7 +187,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) trex_traffic_gen._queue.put({}) @@ -200,7 +200,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen.listen_traffic({})) @@ -215,7 +215,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(0, trex_traffic_gen.instantiate({}, {})) @@ -230,7 +230,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(1, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertRaises(RuntimeError, @@ -243,7 +243,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen._start_server()) @@ -259,7 +259,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -279,7 +279,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen._generate_trex_cfg(vnfd)) @@ -291,7 +291,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) result = ['0x00', '0x00', '0x00', '0x00', '0x00', '0x01'] @@ -309,7 +309,7 @@ class TestTrexTrafficGen(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] self.sut = TrexTrafficGen(vnfd) self.sut.connection = mock.Mock() @@ -326,7 +326,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] flavor = "" trex_traffic_gen = TrexTrafficGen(vnfd) @@ -339,7 +339,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual( None, trex_traffic_gen.setup_vnf_environment(ssh_mock)) @@ -350,7 +350,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen.terminate()) @@ -360,7 +360,7 @@ class TestTrexTrafficGen(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) client = mock.Mock(autospec=STLClient) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index 36b8c2a22..b69e537aa 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -229,7 +229,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) vpe_approx_vnf.resource = mock.Mock(autospec=ResourceProfile) @@ -249,7 +249,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) cmd = "quit" @@ -261,7 +261,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) vpe_approx_vnf.execute_command = \ @@ -277,7 +277,7 @@ class TestVpeApproxVnf(unittest.TestCase): mock.Mock(return_value=(0, "", "")) ssh_mock.run = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -294,7 +294,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}} @@ -311,7 +311,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}} @@ -332,7 +332,7 @@ class TestVpeApproxVnf(unittest.TestCase): ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "", "")) - ssh.return_value = ssh_mock + ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.assertEqual(None, diff --git a/tests/unit/orchestrator/__init__.py b/tests/unit/orchestrator/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/unit/orchestrator/__init__.py diff --git a/tests/unit/orchestrator/test_heat.py b/tests/unit/orchestrator/test_heat.py index 97314c275..2f9c800aa 100644 --- a/tests/unit/orchestrator/test_heat.py +++ b/tests/unit/orchestrator/test_heat.py @@ -13,6 +13,7 @@ import unittest import uuid +import mock from yardstick.orchestrator import heat @@ -24,3 +25,61 @@ class HeatContextTestCase(unittest.TestCase): k = heat.get_short_key_uuid(u) self.assertEqual(heat.HEAT_KEY_UUID_LENGTH, len(k)) self.assertIn(k, str(u)) + +class HeatTemplateTestCase(unittest.TestCase): + + def setUp(self): + self.template = heat.HeatTemplate('test') + + def test_add_tenant_network(self): + self.template.add_network('some-network') + + self.assertEqual(self.template.resources['some-network']['type'], 'OS::Neutron::Net') + + def test_add_provider_network(self): + self.template.add_network('some-network', 'physnet2', 'sriov') + + self.assertEqual(self.template.resources['some-network']['type'], 'OS::Neutron::ProviderNet') + self.assertEqual(self.template.resources['some-network']['properties']['physical_network'], 'physnet2') + + def test_add_subnet(self): + netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} + self.template.add_subnet('some-subnet', "some-network", netattrs['cidr']) + + self.assertEqual(self.template.resources['some-subnet']['type'], 'OS::Neutron::Subnet') + self.assertEqual(self.template.resources['some-subnet']['properties']['cidr'], '10.0.0.0/24') + + def test_add_router(self): + self.template.add_router('some-router', 'ext-net', 'some-subnet') + + self.assertEqual(self.template.resources['some-router']['type'], 'OS::Neutron::Router') + self.assertIn('some-subnet', self.template.resources['some-router']['depends_on']) + + def test_add_router_interface(self): + self.template.add_router_interface('some-router-if', 'some-router', 'some-subnet') + + self.assertEqual(self.template.resources['some-router-if']['type'], 'OS::Neutron::RouterInterface') + self.assertIn('some-subnet', self.template.resources['some-router-if']['depends_on']) + + def test_add_servergroup(self): + self.template.add_servergroup('some-server-group', 'anti-affinity') + + self.assertEqual(self.template.resources['some-server-group']['type'], 'OS::Nova::ServerGroup') + self.assertEqual(self.template.resources['some-server-group']['properties']['policies'], ['anti-affinity']) + +class HeatStackTestCase(unittest.TestCase): + + def test_delete_calls__delete_multiple_times(self): + stack = heat.HeatStack('test') + stack.uuid = 1 + with mock.patch.object(stack, "_delete") as delete_mock: + stack.delete() + # call once and then call again if uuid is not none + self.assertGreater(delete_mock.call_count, 1) + + def test_delete_all_calls_delete(self): + stack = heat.HeatStack('test') + stack.uuid = 1 + with mock.patch.object(stack, "delete") as delete_mock: + stack.delete_all() + self.assertGreater(delete_mock.call_count, 0) diff --git a/tests/unit/test_ssh.py b/tests/unit/test_ssh.py index 1c63c00a3..236736baa 100644 --- a/tests/unit/test_ssh.py +++ b/tests/unit/test_ssh.py @@ -52,6 +52,62 @@ class SSHTestCase(unittest.TestCase): self.assertEqual("kf", test_ssh.key_filename) self.assertEqual("secret", test_ssh.password) + @mock.patch("yardstick.ssh.SSH._get_pkey") + def test_ssh_from_node(self, mock_ssh__get_pkey): + mock_ssh__get_pkey.return_value = "pkey" + node = { + "user": "root", "ip": "example.net", "ssh_port": 33, + "key_filename": "kf", "password": "secret" + } + test_ssh = ssh.SSH.from_node(node) + self.assertEqual("root", test_ssh.user) + self.assertEqual("example.net", test_ssh.host) + self.assertEqual(33, test_ssh.port) + self.assertEqual("kf", test_ssh.key_filename) + self.assertEqual("secret", test_ssh.password) + + @mock.patch("yardstick.ssh.SSH._get_pkey") + def test_ssh_from_node_password_default(self, mock_ssh__get_pkey): + mock_ssh__get_pkey.return_value = "pkey" + node = { + "user": "root", "ip": "example.net", "ssh_port": 33, + "key_filename": "kf" + } + test_ssh = ssh.SSH.from_node(node) + self.assertEqual("root", test_ssh.user) + self.assertEqual("example.net", test_ssh.host) + self.assertEqual(33, test_ssh.port) + self.assertEqual("kf", test_ssh.key_filename) + self.assertIsNone(test_ssh.password) + + @mock.patch("yardstick.ssh.SSH._get_pkey") + def test_ssh_from_node_ssh_port_default(self, mock_ssh__get_pkey): + mock_ssh__get_pkey.return_value = "pkey" + node = { + "user": "root", "ip": "example.net", + "key_filename": "kf", "password": "secret" + } + test_ssh = ssh.SSH.from_node(node) + self.assertEqual("root", test_ssh.user) + self.assertEqual("example.net", test_ssh.host) + self.assertEqual(ssh.SSH_PORT, test_ssh.port) + self.assertEqual("kf", test_ssh.key_filename) + self.assertEqual("secret", test_ssh.password) + + @mock.patch("yardstick.ssh.SSH._get_pkey") + def test_ssh_from_node_key_filename_default(self, mock_ssh__get_pkey): + mock_ssh__get_pkey.return_value = "pkey" + node = { + "user": "root", "ip": "example.net", "ssh_port": 33, + "password": "secret" + } + test_ssh = ssh.SSH.from_node(node) + self.assertEqual("root", test_ssh.user) + self.assertEqual("example.net", test_ssh.host) + self.assertEqual(33, test_ssh.port) + self.assertIsNone(test_ssh.key_filename) + self.assertEqual("secret", test_ssh.password) + def test_construct_default(self): self.assertEqual("root", self.test_client.user) self.assertEqual("example.net", self.test_client.host) |