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
15 from __future__ import absolute_import
20 from yardstick.benchmark.scenarios.availability.result_checker import \
21 result_checker_general
24 # pylint: disable=unused-argument
25 # disable this for now because I keep forgetting mock patch arg ordering
28 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
29 'result_checker_general.ssh')
30 @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
31 'result_checker_general.open')
32 class GeneralResultCheckerTestCase(unittest.TestCase):
38 "key_filename": "/root/.ssh/id_rsa"
40 self.context = {"node1": host}
42 'parameter': {'processname': 'process'},
43 'checker_type': 'general-result-checker',
46 'key': 'process-checker',
47 'checker_key': 'process-checker',
51 def test__result_checker_eq(self, mock_open, mock_ssh):
52 ins = result_checker_general.GeneralResultChecker(self.checker_cfg,
54 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
56 self.assertTrue(ins.verify())
58 def test__result_checker_gt(self, mock_open, mock_ssh):
59 config = copy.deepcopy(self.checker_cfg)
60 config['condition'] = 'gt'
61 ins = result_checker_general.GeneralResultChecker(config,
63 mock_ssh.SSH.from_node().execute.return_value = (0, "2", '')
65 self.assertTrue(ins.verify())
67 def test__result_checker_gt_eq(self, mock_open, mock_ssh):
68 config = copy.deepcopy(self.checker_cfg)
69 config['condition'] = 'gt_eq'
70 ins = result_checker_general.GeneralResultChecker(config,
72 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
74 self.assertTrue(ins.verify())
76 def test__result_checker_lt(self, mock_open, mock_ssh):
77 config = copy.deepcopy(self.checker_cfg)
78 config['condition'] = 'lt'
79 ins = result_checker_general.GeneralResultChecker(config,
81 mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
83 self.assertTrue(ins.verify())
85 def test__result_checker_lt_eq(self, mock_open, mock_ssh):
86 config = copy.deepcopy(self.checker_cfg)
87 config['condition'] = 'lt_eq'
88 ins = result_checker_general.GeneralResultChecker(config,
90 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
92 self.assertTrue(ins.verify())
94 def test__result_checker_in(self, mock_open, mock_ssh):
95 config = copy.deepcopy(self.checker_cfg)
96 config['condition'] = 'in'
97 config['expectedValue'] = "value"
98 ins = result_checker_general.GeneralResultChecker(config,
100 mock_ssh.SSH.from_node().execute.return_value = (0, "value return", '')
102 self.assertTrue(ins.verify())
104 def test__result_checker_wrong(self, mock_open, mock_ssh):
105 config = copy.deepcopy(self.checker_cfg)
106 config['condition'] = 'wrong'
107 ins = result_checker_general.GeneralResultChecker(config,
109 mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
111 self.assertFalse(ins.verify())
113 def test__result_checker_fail(self, mock_open, mock_ssh):
114 config = copy.deepcopy(self.checker_cfg)
115 config.pop('parameter')
116 ins = result_checker_general.GeneralResultChecker(config,
118 mock_ssh.SSH.from_node().execute.return_value = (1, "fail", '')