1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
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.compute.unixbench.Unixbench
12 from __future__ import absolute_import
17 from oslo_serialization import jsonutils
19 from yardstick.benchmark.scenarios.compute import unixbench
22 @mock.patch('yardstick.benchmark.scenarios.compute.unixbench.ssh')
23 class UnixbenchTestCase(unittest.TestCase):
28 "ip": "192.168.50.28",
30 "key_filename": "mykey.key"
34 def test_unixbench_successful_setup(self, mock_ssh):
36 u = unixbench.Unixbench({}, self.ctx)
39 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
40 self.assertIsNotNone(u.client)
41 self.assertTrue(u.setup_done)
43 def test_unixbench_successful_no_sla(self, mock_ssh):
46 "test_type": 'dhry2reg',
52 u = unixbench.Unixbench(args, self.ctx)
55 u.server = mock_ssh.SSH.from_node()
57 sample_output = '{"Score":"4425.4"}'
58 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
61 expected_result = jsonutils.loads(sample_output)
62 self.assertEqual(result, expected_result)
64 def test_unixbench_successful_in_quiet_mode(self, mock_ssh):
67 "test_type": 'dhry2reg',
74 u = unixbench.Unixbench(args, self.ctx)
77 u.server = mock_ssh.SSH.from_node()
79 sample_output = '{"Score":"4425.4"}'
80 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
83 expected_result = jsonutils.loads(sample_output)
84 self.assertEqual(result, expected_result)
86 def test_unixbench_successful_sla(self, mock_ssh):
89 "test_type": 'dhry2reg',
93 "single_score": '100',
94 "parallel_score": '500'
100 u = unixbench.Unixbench(args, self.ctx)
103 u.server = mock_ssh.SSH.from_node()
105 sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}'
106 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
109 expected_result = jsonutils.loads(sample_output)
110 self.assertEqual(result, expected_result)
112 def test_unixbench_unsuccessful_sla_single_score(self, mock_ssh):
116 "sla": {"single_score": "500"}
118 u = unixbench.Unixbench(args, self.ctx)
121 u.server = mock_ssh.SSH.from_node()
122 sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}'
124 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
125 self.assertRaises(AssertionError, u.run, result)
127 def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh):
131 "sla": {"parallel_score": "4000"}
133 u = unixbench.Unixbench(args, self.ctx)
136 u.server = mock_ssh.SSH.from_node()
137 sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}'
139 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
140 self.assertRaises(AssertionError, u.run, result)
142 def test_unixbench_unsuccessful_script_error(self, mock_ssh):
145 "test_type": 'dhry2reg',
146 "run_mode": 'verbose'
149 "single_score": '100',
150 "parallel_score": '500'
156 u = unixbench.Unixbench(args, self.ctx)
159 u.server = mock_ssh.SSH.from_node()
161 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
162 self.assertRaises(RuntimeError, u.run, result)