Fixed document for Grafana Port usage
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_attacker_general.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Juan Qiu and others
5 # juan_ qiu@tongji.edu.cn
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
13 # .attacker_general
14
15 from __future__ import absolute_import
16 import mock
17 import unittest
18
19 from yardstick.benchmark.scenarios.availability.attacker import baseattacker
20
21
22 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.'
23             'attacker_general.ssh')
24 class GeneralAttackerServiceTestCase(unittest.TestCase):
25
26     def setUp(self):
27         host = {
28             "ip": "10.20.0.5",
29             "user": "root",
30             "key_filename": "/root/.ssh/id_rsa"
31         }
32         self.context = {"node1": host}
33         self.attacker_cfg = {
34             'fault_type': 'general-attacker',
35             'action_parameter': {'process_name': 'nova_api'},
36             'rollback_parameter': {'process_name': 'nova_api'},
37             'key': 'stop-service',
38             'attack_key': 'stop-service',
39             'host': 'node1',
40         }
41
42     def test__attacker_service_all_successful(self, mock_ssh):
43
44         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
45         ins = cls(self.attacker_cfg, self.context)
46
47         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
48         ins.setup()
49         ins.inject_fault()
50         ins.recover()
51
52     def test__attacker_service_check_failuer(self, mock_ssh):
53
54         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
55         ins = cls(self.attacker_cfg, self.context)
56
57         mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
58         ins.setup()