3 ##############################################################################
4 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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.spec_cpu_for_vm.SpecCPUforVM
14 from __future__ import absolute_import
20 from yardstick.benchmark.scenarios.compute import spec_cpu_for_vm
23 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.ssh')
24 class SpecCPUforVMTestCase(unittest.TestCase):
31 'key_filename': "mykey.key"
37 def test_spec_cpu_successful_setup(self, mock_ssh):
40 "SPECint_benchmark": "perlbench",
41 "runspec_tune": "all",
42 "output_format": "all",
43 "runspec_iterations": "1",
44 "runspec_size": "test"
46 args = {"options": options}
47 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
48 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
51 self.assertIsNotNone(s.client)
52 self.assertTrue(s.setup_done, True)
54 def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
57 "SPECint_benchmark": "perlbench",
58 "runspec_tune": "all",
59 "output_format": "all"
61 args = {"options": options}
62 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
64 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
65 mock_ssh.SSH.from_node().get.return_value = (0, '', '')
67 expected_result = {'SPEC_CPU_result': ''}
68 self.assertEqual(self.result, expected_result)
70 def test_spec_cpu_unsuccessful_script_error(self, mock_ssh):
72 "benchmark_subset": "int"
74 args = {"options": options}
75 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
77 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
78 self.assertRaises(RuntimeError, s.run, self.result)
83 if __name__ == '__main__':