Remove main() and __main__ from tests.
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / compute / test_spec_cpu_for_vm.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_for_vm.SpecCPUforVM
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_for_vm
19
20
21 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.ssh')
22 class SpecCPUforVMTestCase(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             "runspec_tune": "all",
40             "output_format": "all",
41             "runspec_iterations": "1",
42             "runspec_size": "test"
43         }
44         args = {"options": options}
45         s = spec_cpu_for_vm.SpecCPUforVM(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_for_vm.SpecCPUforVM(args, self.ctx)
61
62         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
63         mock_ssh.SSH.from_node().get.return_value = (0, '', '')
64         s.run(self.result)
65         expected_result = {'SPEC_CPU_result': ''}
66         self.assertEqual(self.result, expected_result)
67
68     def test_spec_cpu_unsuccessful_script_error(self, mock_ssh):
69         options = {
70             "benchmark_subset": "int"
71         }
72         args = {"options": options}
73         s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
74
75         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
76         self.assertRaises(RuntimeError, s.run, self.result)