Merge "contexts/node: default to pod.yaml"
[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             'operation_key': 'nova-create-instance',
38             'host': 'node1',
39         }
40         self.operation_cfg_noparam = {
41             'operation_type': 'general-operation',
42             'key': 'nova-create-instance',
43             'operation_key': 'nova-create-instance',
44             'host': 'node1',
45         }
46
47     def test__operation_successful(self, mock_open, mock_ssh):
48         ins = operation_general.GeneralOperaion(self.operation_cfg,
49             self.context);
50         mock_ssh.SSH().execute.return_value = (0, "success", '')
51         ins.setup()
52         ins.run()
53         ins.rollback()
54
55     def test__operation_successful_noparam(self, mock_open, mock_ssh):
56         ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
57             self.context);
58         mock_ssh.SSH().execute.return_value = (0, "success", '')
59         ins.setup()
60         ins.run()
61         ins.rollback()
62
63     def test__operation_fail(self, mock_open, mock_ssh):
64         ins = operation_general.GeneralOperaion(self.operation_cfg,
65             self.context);
66         mock_ssh.SSH().execute.return_value = (1, "failed", '')
67         ins.setup()
68         ins.run()
69         ins.rollback()