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