Merge "[bugfix]tc006 failed due to volume attached to different location "/dev/vdc""
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_operation_general.py
1 ##############################################################################
2 # Copyright (c) 2016 Huan Li and others
3 # lihuansse@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.operation
11 # .operation_general
12
13 from __future__ import absolute_import
14 import mock
15 import unittest
16 from yardstick.benchmark.scenarios.availability.operation import \
17     operation_general
18
19
20 # pylint: disable=unused-argument
21 # disable this for now because I keep forgetting mock patch arg ordering
22
23
24 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
25             'operation_general.ssh')
26 @mock.patch('yardstick.benchmark.scenarios.availability.operation.'
27             'operation_general.open')
28 class GeneralOperaionTestCase(unittest.TestCase):
29
30     def setUp(self):
31         host = {
32             "ip": "10.20.0.5",
33             "user": "root",
34             "key_filename": "/root/.ssh/id_rsa"
35         }
36         self.context = {"node1": host}
37         self.operation_cfg = {
38             'operation_type': 'general-operation',
39             'action_parameter': {'ins_cup': 2},
40             'rollback_parameter': {'ins_id': 'id123456'},
41             'key': 'nova-create-instance',
42             'operation_key': 'nova-create-instance',
43             'host': 'node1',
44         }
45         self.operation_cfg_noparam = {
46             'operation_type': 'general-operation',
47             'key': 'nova-create-instance',
48             'operation_key': 'nova-create-instance',
49             'host': 'node1',
50         }
51
52     def test__operation_successful(self, mock_open, mock_ssh):
53         ins = operation_general.GeneralOperaion(self.operation_cfg,
54                                                 self.context)
55         mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
56         ins.setup()
57         ins.run()
58         ins.rollback()
59
60     def test__operation_successful_noparam(self, mock_open, mock_ssh):
61         ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
62                                                 self.context)
63         mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
64         ins.setup()
65         ins.run()
66         ins.rollback()
67
68     def test__operation_fail(self, mock_open, mock_ssh):
69         ins = operation_general.GeneralOperaion(self.operation_cfg,
70                                                 self.context)
71         mock_ssh.SSH.from_node().execute.return_value = (1, "failed", '')
72         ins.setup()
73         ins.run()
74         ins.rollback()