Rewrite the HA test case (1)
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_attacker_process.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.availability.attacker.attacker_process
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability.attacker import baseattacker
18
19 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh')
20 class AttackerServiceTestCase(unittest.TestCase):
21
22     def setUp(self):
23         host = {
24             "ip": "10.20.0.5",
25             "user": "root",
26             "key_filename": "/root/.ssh/id_rsa"
27         }
28         self.context = {"node1": host}
29         self.attacker_cfg = {
30             'fault_type': 'kill-process',
31             'process_name': 'nova-api',
32             'host': 'node1',
33         }
34
35     def test__attacker_service_all_successful(self, mock_ssh):
36
37         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
38         ins = cls(self.attacker_cfg, self.context)
39
40         mock_ssh.SSH().execute.return_value = (0, "running", '')
41         ins.setup()
42         ins.inject_fault()
43         ins.recover()
44
45     def test__attacker_service_check_failuer(self, mock_ssh):
46
47         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
48         ins = cls(self.attacker_cfg, self.context)
49
50         mock_ssh.SSH().execute.return_value = (0, "error check", '')
51         ins.setup()