Merge "Update the dummy-scenario-heat-context testcase"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / compute / test_spec_cpu.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 # Unittest for yardstick.benchmark.scenarios.compute.spec_cpu.SpecCPU
11
12 from __future__ import absolute_import
13
14 import unittest
15
16 import mock
17
18 from yardstick.benchmark.scenarios.compute import spec_cpu
19
20
21 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu.ssh')
22 class SpecCPUTestCase(unittest.TestCase):
23
24     def setUp(self):
25         self.ctx = {
26             'host': {
27                 'ip': '172.16.0.137',
28                 'user': 'root',
29                 'key_filename': "mykey.key"
30             }
31         }
32
33         self.result = {}
34
35     def test_spec_cpu_successful_setup(self, mock_ssh):
36
37         options = {
38             "SPECint_benchmark": "perlbench",
39             "output_format": "all",
40             "runspec_iterations": "1",
41             "runspec_tune": "base",
42             "runspec_size": "test"
43         }
44         args = {"options": options}
45         s = spec_cpu.SpecCPU(args, self.ctx)
46         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
47
48         s.setup()
49         self.assertIsNotNone(s.client)
50         self.assertTrue(s.setup_done, True)
51
52     def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
53
54         options = {
55             "SPECint_benchmark": "perlbench",
56             "runspec_tune": "all",
57             "output_format": "all"
58         }
59         args = {"options": options}
60         s = spec_cpu.SpecCPU(args, self.ctx)
61
62         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
63         s.run(self.result)
64         expected_result = {}
65         self.assertEqual(self.result, expected_result)
66
67     def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
68         options = {
69             "benchmark_subset": "int"
70         }
71         args = {"options": options}
72         s = spec_cpu.SpecCPU(args, self.ctx)
73
74         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
75         self.assertRaises(RuntimeError, s.run, self.result)