Merge "PROX: [WIP] Added scale up TCs."
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_baseoperation.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 import mock
11 import unittest
12
13 from yardstick.benchmark.scenarios.availability.operation import baseoperation
14
15
16 class OperationMgrTestCase(unittest.TestCase):
17
18     def setUp(self):
19         config = {
20             'operation_type': 'general-operation',
21             'key': 'service-status'
22         }
23
24         self.operation_configs = []
25         self.operation_configs.append(config)
26
27     @mock.patch.object(baseoperation, 'BaseOperation')
28     def test_all_successful(self, *args):
29         mgr_ins = baseoperation.OperationMgr()
30         mgr_ins.init_operations(self.operation_configs, None)
31         _ = mgr_ins["service-status"]
32         mgr_ins.rollback()
33
34     @mock.patch.object(baseoperation, 'BaseOperation')
35     def test_getitem_fail(self, *args):
36         mgr_ins = baseoperation.OperationMgr()
37         mgr_ins.init_operations(self.operation_configs, None)
38         with self.assertRaises(KeyError):
39             _ = mgr_ins["operation-not-exist"]
40
41
42 class TestOperation(baseoperation.BaseOperation):
43     __operation__type__ = "test-operation"
44
45     def setup(self):
46         pass
47
48     def run(self):
49         pass
50
51     def rollback(self):
52         pass
53
54
55 class BaseOperationTestCase(unittest.TestCase):
56
57     def setUp(self):
58         self.config = {
59             'operation_type': 'general-operation',
60             'key': 'service-status'
61         }
62         self.base_ins = baseoperation.BaseOperation(self.config, None)
63
64     def test_all_successful(self):
65         self.base_ins.setup()
66         self.base_ins.run()
67         self.base_ins.rollback()
68
69     def test_get_script_fullpath(self):
70         self.base_ins.get_script_fullpath("ha_tools/test.bash")
71
72     # TODO(elfoley): Fix test to check on expected outputs
73     # pylint: disable=unused-variable
74     def test_get_operation_cls_successful(self):
75         operation_ins = self.base_ins.get_operation_cls("test-operation")
76
77     def test_get_operation_cls_fail(self):
78         with self.assertRaises(RuntimeError):
79             self.base_ins.get_operation_cls("operation-not-exist")