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 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.availability.operation.baseoperation
17 from yardstick.benchmark.scenarios.availability.operation import baseoperation
19 @mock.patch('yardstick.benchmark.scenarios.availability.operation.baseoperation.BaseOperation')
20 class OperationMgrTestCase(unittest.TestCase):
24 'operation_type': 'general-operation',
25 'key' : 'service_status'
28 self.operation_configs = []
29 self.operation_configs.append(config)
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"]
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"]
44 class TestOperation(baseoperation.BaseOperation):
45 __operation__type__ = "test-operation"
57 class BaseOperationTestCase(unittest.TestCase):
61 'operation_type': 'general-operation',
62 'key' : 'service_status'
65 def test_all_successful(self):
66 base_ins = baseoperation.BaseOperation(self.config, None)
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");
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")
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")