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 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.availability.result_checker
11 # .result_checker_general
13 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.availability.result_checker import \
19 result_checker_general
22 # pylint: disable=unused-argument
23 # disable this for now because I keep forgetting mock patch arg ordering
26 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
27 'result_checker_general.ssh')
28 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
29 'result_checker_general.open')
30 class GeneralResultCheckerTestCase(unittest.TestCase):
36 "key_filename": "/root/.ssh/id_rsa"
38 self.context = {"node1": host}
40 'parameter': {'processname': 'process'},
41 'checker_type': 'general-result-checker',
44 'key': 'process-checker',
45 'checker_key': 'process-checker',
49 def test__result_checker_eq(self, mock_open, mock_ssh):
50 ins = result_checker_general.GeneralResultChecker(self.checker_cfg,
52 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
54 self.assertTrue(ins.verify())
56 def test__result_checker_gt(self, mock_open, mock_ssh):
57 config = copy.deepcopy(self.checker_cfg)
58 config['condition'] = 'gt'
59 ins = result_checker_general.GeneralResultChecker(config,
61 mock_ssh.SSH.from_node().execute.return_value = (0, "2", '')
63 self.assertTrue(ins.verify())
65 def test__result_checker_gt_eq(self, mock_open, mock_ssh):
66 config = copy.deepcopy(self.checker_cfg)
67 config['condition'] = 'gt_eq'
68 ins = result_checker_general.GeneralResultChecker(config,
70 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
72 self.assertTrue(ins.verify())
74 def test__result_checker_lt(self, mock_open, mock_ssh):
75 config = copy.deepcopy(self.checker_cfg)
76 config['condition'] = 'lt'
77 ins = result_checker_general.GeneralResultChecker(config,
79 mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
81 self.assertTrue(ins.verify())
83 def test__result_checker_lt_eq(self, mock_open, mock_ssh):
84 config = copy.deepcopy(self.checker_cfg)
85 config['condition'] = 'lt_eq'
86 ins = result_checker_general.GeneralResultChecker(config,
88 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
90 self.assertTrue(ins.verify())
92 def test__result_checker_in(self, mock_open, mock_ssh):
93 config = copy.deepcopy(self.checker_cfg)
94 config['condition'] = 'in'
95 config['expectedValue'] = "value"
96 ins = result_checker_general.GeneralResultChecker(config,
98 mock_ssh.SSH.from_node().execute.return_value = (0, "value return", '')
100 self.assertTrue(ins.verify())
102 def test__result_checker_wrong(self, mock_open, mock_ssh):
103 config = copy.deepcopy(self.checker_cfg)
104 config['condition'] = 'wrong'
105 ins = result_checker_general.GeneralResultChecker(config,
107 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
109 self.assertFalse(ins.verify())
111 def test__result_checker_fail(self, mock_open, mock_ssh):
112 config = copy.deepcopy(self.checker_cfg)
113 config.pop('parameter')
114 ins = result_checker_general.GeneralResultChecker(config,
116 mock_ssh.SSH.from_node().execute.return_value = (1, "fail", '')