1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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.spec_cpu_for_vm.SpecCPUforVM
12 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.compute import spec_cpu_for_vm
21 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.ssh')
22 class SpecCPUforVMTestCase(unittest.TestCase):
29 'key_filename': "mykey.key"
35 def test_spec_cpu_successful_setup(self, mock_ssh):
38 "SPECint_benchmark": "perlbench",
39 "runspec_tune": "all",
40 "output_format": "all",
41 "runspec_iterations": "1",
42 "runspec_size": "test"
44 args = {"options": options}
45 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
46 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
49 self.assertIsNotNone(s.client)
50 self.assertTrue(s.setup_done, True)
52 def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
55 "SPECint_benchmark": "perlbench",
56 "runspec_tune": "all",
57 "output_format": "all"
59 args = {"options": options}
60 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
62 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
63 mock_ssh.SSH.from_node().get.return_value = (0, '', '')
65 expected_result = {'SPEC_CPU_result': ''}
66 self.assertEqual(self.result, expected_result)
68 def test_spec_cpu_unsuccessful_script_error(self, mock_ssh):
70 "benchmark_subset": "int"
72 args = {"options": options}
73 s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
75 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
76 self.assertRaises(RuntimeError, s.run, self.result)