3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
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.compute.unixbench.Unixbench
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.compute import unixbench
24 @mock.patch('yardstick.benchmark.scenarios.compute.unixbench.ssh')
25 class UnixbenchTestCase(unittest.TestCase):
30 "ip": "192.168.50.28",
32 "key_filename": "mykey.key"
36 def test_unixbench_successful_setup(self, mock_ssh):
38 u = unixbench.Unixbench({}, self.ctx)
41 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
42 self.assertIsNotNone(u.client)
43 self.assertEqual(u.setup_done, True)
45 def test_unixbench_successful_no_sla(self, mock_ssh):
48 "test_type": 'dhry2reg',
54 u = unixbench.Unixbench(args, self.ctx)
57 u.server = mock_ssh.SSH.from_node()
59 sample_output = '{"Score":"4425.4"}'
60 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
63 expected_result = jsonutils.loads(sample_output)
64 self.assertEqual(result, expected_result)
66 def test_unixbench_successful_in_quiet_mode(self, mock_ssh):
69 "test_type": 'dhry2reg',
76 u = unixbench.Unixbench(args, self.ctx)
79 u.server = mock_ssh.SSH.from_node()
81 sample_output = '{"Score":"4425.4"}'
82 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
85 expected_result = jsonutils.loads(sample_output)
86 self.assertEqual(result, expected_result)
88 def test_unixbench_successful_sla(self, mock_ssh):
91 "test_type": 'dhry2reg',
95 "single_score": '100',
96 "parallel_score": '500'
102 u = unixbench.Unixbench(args, self.ctx)
105 u.server = mock_ssh.SSH.from_node()
107 sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}'
108 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
111 expected_result = jsonutils.loads(sample_output)
112 self.assertEqual(result, expected_result)
114 def test_unixbench_unsuccessful_sla_single_score(self, mock_ssh):
118 "sla": {"single_score": "500"}
120 u = unixbench.Unixbench(args, self.ctx)
123 u.server = mock_ssh.SSH.from_node()
124 sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}'
126 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
127 self.assertRaises(AssertionError, u.run, result)
129 def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh):
133 "sla": {"parallel_score": "4000"}
135 u = unixbench.Unixbench(args, self.ctx)
138 u.server = mock_ssh.SSH.from_node()
139 sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}'
141 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
142 self.assertRaises(AssertionError, u.run, result)
144 def test_unixbench_unsuccessful_script_error(self, mock_ssh):
147 "test_type": 'dhry2reg',
148 "run_mode": 'verbose'
151 "single_score": '100',
152 "parallel_score": '500'
158 u = unixbench.Unixbench(args, self.ctx)
161 u.server = mock_ssh.SSH.from_node()
163 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
164 self.assertRaises(RuntimeError, u.run, result)
170 if __name__ == '__main__':