3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
13 # yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal
15 from __future__ import absolute_import
19 from yardstick.benchmark.scenarios.availability.attacker import \
23 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
24 class ExecuteShellTestCase(unittest.TestCase):
26 def test__fun_execute_shell_command_successful(self, mock_subprocess):
28 mock_subprocess.check_output.return_value = (0, 'unittest')
29 exitcode, output = attacker_baremetal._execute_shell_command(cmd)
30 self.assertEqual(exitcode, 0)
32 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.LOG')
33 def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, mock_subprocess):
35 mock_subprocess.check_output.side_effect = RuntimeError
36 exitcode, output = attacker_baremetal._execute_shell_command(cmd)
37 self.assertEqual(exitcode, -1)
38 mock_log.error.assert_called_once()
41 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
42 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh')
43 class AttackerBaremetalTestCase(unittest.TestCase):
47 "ipmi_ip": "10.20.0.5",
52 "key_filename": "/root/.ssh/id_rsa"
54 self.context = {"node1": host}
56 'fault_type': 'bear-metal-down',
60 def test__attacker_baremetal_all_successful(self, mock_ssh, mock_subprocess):
61 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
62 ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
69 def test__attacker_baremetal_check_failuer(self, mock_ssh, mock_subprocess):
70 mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
71 ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
75 def test__attacker_baremetal_recover_successful(self, mock_ssh, mock_subprocess):
77 self.attacker_cfg["jump_host"] = 'node1'
78 self.context["node1"]["pwd"] = "123456"
79 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
80 ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,