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