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
20 from yardstick.common import exceptions as y_exc
23 @mock.patch('yardstick.benchmark.scenarios.compute.unixbench.ssh')
24 class UnixbenchTestCase(unittest.TestCase):
29 "ip": "192.168.50.28",
31 "key_filename": "mykey.key"
35 def test_unixbench_successful_setup(self, mock_ssh):
37 u = unixbench.Unixbench({}, self.ctx)
40 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
41 self.assertIsNotNone(u.client)
42 self.assertTrue(u.setup_done)
44 def test_unixbench_successful_no_sla(self, mock_ssh):
47 "test_type": 'dhry2reg',
53 u = unixbench.Unixbench(args, self.ctx)
56 u.server = mock_ssh.SSH.from_node()
58 sample_output = '{"Score":"4425.4"}'
59 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
62 expected_result = jsonutils.loads(sample_output)
63 self.assertEqual(result, expected_result)
65 def test_unixbench_successful_in_quiet_mode(self, mock_ssh):
68 "test_type": 'dhry2reg',
75 u = unixbench.Unixbench(args, self.ctx)
78 u.server = mock_ssh.SSH.from_node()
80 sample_output = '{"Score":"4425.4"}'
81 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
84 expected_result = jsonutils.loads(sample_output)
85 self.assertEqual(result, expected_result)
87 def test_unixbench_successful_sla(self, mock_ssh):
90 "test_type": 'dhry2reg',
94 "single_score": '100',
95 "parallel_score": '500'
101 u = unixbench.Unixbench(args, self.ctx)
104 u.server = mock_ssh.SSH.from_node()
106 sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}'
107 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
110 expected_result = jsonutils.loads(sample_output)
111 self.assertEqual(result, expected_result)
113 def test_unixbench_unsuccessful_sla_single_score(self, mock_ssh):
117 "sla": {"single_score": "500"}
119 u = unixbench.Unixbench(args, self.ctx)
122 u.server = mock_ssh.SSH.from_node()
123 sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}'
125 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
126 self.assertRaises(y_exc.SLAValidationError, u.run, result)
128 def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh):
132 "sla": {"parallel_score": "4000"}
134 u = unixbench.Unixbench(args, self.ctx)
137 u.server = mock_ssh.SSH.from_node()
138 sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}'
140 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
141 self.assertRaises(y_exc.SLAValidationError, u.run, result)
143 def test_unixbench_unsuccessful_script_error(self, mock_ssh):
146 "test_type": 'dhry2reg',
147 "run_mode": 'verbose'
150 "single_score": '100',
151 "parallel_score": '500'
157 u = unixbench.Unixbench(args, self.ctx)
160 u.server = mock_ssh.SSH.from_node()
162 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
163 self.assertRaises(RuntimeError, u.run, result)