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.result_checker
13 # .result_checker_general
19 from yardstick.benchmark.scenarios.availability.result_checker import result_checker_general
22 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
23 'result_checker_general.ssh')
24 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
25 'result_checker_general.open')
26 class GeneralResultCheckerTestCase(unittest.TestCase):
32 "key_filename": "/root/.ssh/id_rsa"
34 self.context = {"node1": host}
36 'parameter': {'processname': 'process'},
37 'checker_type': 'general-result-checker',
40 'key' : 'process-checker',
41 'checker_key' : 'process-checker',
45 def test__result_checker_eq(self, mock_open, mock_ssh):
46 ins = result_checker_general.GeneralResultChecker(self.checker_cfg,
48 mock_ssh.SSH().execute.return_value = (0, "1", '')
50 self.assertTrue(ins.verify())
52 def test__result_checker_gt(self, mock_open, mock_ssh):
53 config = copy.deepcopy(self.checker_cfg)
54 config['condition'] = 'gt'
55 ins = result_checker_general.GeneralResultChecker(config,
57 mock_ssh.SSH().execute.return_value = (0, "2", '')
59 self.assertTrue(ins.verify())
61 def test__result_checker_gt_eq(self, mock_open, mock_ssh):
62 config = copy.deepcopy(self.checker_cfg)
63 config['condition'] = 'gt_eq'
64 ins = result_checker_general.GeneralResultChecker(config,
66 mock_ssh.SSH().execute.return_value = (0, "1", '')
68 self.assertTrue(ins.verify())
70 def test__result_checker_lt(self, mock_open, mock_ssh):
71 config = copy.deepcopy(self.checker_cfg)
72 config['condition'] = 'lt'
73 ins = result_checker_general.GeneralResultChecker(config,
75 mock_ssh.SSH().execute.return_value = (0, "0", '')
77 self.assertTrue(ins.verify())
79 def test__result_checker_lt_eq(self, mock_open, mock_ssh):
80 config = copy.deepcopy(self.checker_cfg)
81 config['condition'] = 'lt_eq'
82 ins = result_checker_general.GeneralResultChecker(config,
84 mock_ssh.SSH().execute.return_value = (0, "1", '')
86 self.assertTrue(ins.verify())
88 def test__result_checker_in(self, mock_open, mock_ssh):
89 config = copy.deepcopy(self.checker_cfg)
90 config['condition'] = 'in'
91 config['expectedValue'] = "value"
92 ins = result_checker_general.GeneralResultChecker(config,
94 mock_ssh.SSH().execute.return_value = (0, "value return", '')
96 self.assertTrue(ins.verify())
98 def test__result_checker_wrong(self, mock_open, mock_ssh):
99 config = copy.deepcopy(self.checker_cfg)
100 config['condition'] = 'wrong'
101 ins = result_checker_general.GeneralResultChecker(config,
103 mock_ssh.SSH().execute.return_value = (0, "1", '')
105 self.assertFalse(ins.verify())
107 def test__result_checker_fail(self, mock_open, mock_ssh):
108 config = copy.deepcopy(self.checker_cfg)
109 config.pop('parameter')
110 ins = result_checker_general.GeneralResultChecker(config,
112 mock_ssh.SSH().execute.return_value = (1, "fail", '')