Merge "Add test case description and task file for TC047"
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_operation_general.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Huan Li and others
5 # lihuansse@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.operation
13 # .operation_general
14
15 import mock
16 import unittest
17 from yardstick.benchmark.scenarios.availability.operation import operation_general
18
19 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
20             'operation_general.ssh')
21 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
22             'operation_general.open')
23 class GeneralOperaionTestCase(unittest.TestCase):
24
25     def setUp(self):
26         host = {
27             "ip": "10.20.0.5",
28             "user": "root",
29             "key_filename": "/root/.ssh/id_rsa"
30         }
31         self.context = {"node1": host}
32         self.operation_cfg = {
33             'operation_type': 'general-operation',
34             'action_parameter': {'ins_cup': 2},
35             'rollback_parameter': {'ins_id': 'id123456'},
36             'key': 'nova-create-instance',
37             'host': 'node1',
38         }
39         self.operation_cfg_noparam = {
40             'operation_type': 'general-operation',
41             'key': 'nova-create-instance',
42             'host': 'node1',
43         }
44
45     def test__operation_successful(self, mock_open, mock_ssh):
46         ins = operation_general.GeneralOperaion(self.operation_cfg,
47             self.context);
48         mock_ssh.SSH().execute.return_value = (0, "success", '')
49         ins.setup()
50         ins.run()
51         ins.rollback()
52
53     def test__operation_successful_noparam(self, mock_open, mock_ssh):
54         ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
55             self.context);
56         mock_ssh.SSH().execute.return_value = (0, "success", '')
57         ins.setup()
58         ins.run()
59         ins.rollback()
60
61     def test__operation_fail(self, mock_open, mock_ssh):
62         ins = operation_general.GeneralOperaion(self.operation_cfg,
63             self.context);
64         mock_ssh.SSH().execute.return_value = (1, "failed", '')
65         ins.setup()
66         ins.run()
67         ins.rollback()