Merge "PROX: [WIP] Added scale up TCs."
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_attacker_general.py
1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
3 # juan_ qiu@tongji.edu.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 # Unittest for yardstick.benchmark.scenarios.availability.attacker
11 # .attacker_general
12
13 from __future__ import absolute_import
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability.attacker import baseattacker
18
19
20 @mock.patch('yardstick.benchmark.scenarios.availability.attacker.'
21             'attacker_general.ssh')
22 class GeneralAttackerServiceTestCase(unittest.TestCase):
23
24     def setUp(self):
25         host = {
26             "ip": "10.20.0.5",
27             "user": "root",
28             "key_filename": "/root/.ssh/id_rsa"
29         }
30         self.context = {"node1": host}
31         self.attacker_cfg = {
32             'fault_type': 'general-attacker',
33             'action_parameter': {'process_name': 'nova_api'},
34             'rollback_parameter': {'process_name': 'nova_api'},
35             'key': 'stop-service',
36             'attack_key': 'stop-service',
37             'host': 'node1',
38         }
39
40     def test__attacker_service_all_successful(self, mock_ssh):
41
42         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
43         ins = cls(self.attacker_cfg, self.context)
44
45         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
46         ins.setup()
47         ins.inject_fault()
48         ins.recover()
49
50     def test__attacker_service_check_failuer(self, mock_ssh):
51
52         cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
53         ins = cls(self.attacker_cfg, self.context)
54
55         mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
56         ins.setup()