c428e1fb80e2c7b329af393b311370e286c962c2
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / compute / test_spec_cpu_for_vm.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.SpecCPUforVM
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19
20 from yardstick.benchmark.scenarios.compute import spec_cpu_for_vm
21
22
23 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.ssh')
24 class SpecCPUforVMTestCase(unittest.TestCase):
25
26     def setUp(self):
27         self.ctx = {
28             'host': {
29                 'ip': '172.16.0.137',
30                 'user': 'root',
31                 'key_filename': "mykey.key"
32             }
33         }
34
35         self.result = {}
36
37     def test_spec_cpu_successful_setup(self, mock_ssh):
38
39         options = {
40             "SPECint_benchmark": "perlbench",
41             "runspec_tune": "all",
42             "output_format": "all",
43             "runspec_iterations": "1",
44             "runspec_size": "test"
45         }
46         args = {"options": options}
47         s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
48         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
49
50         s.setup()
51         self.assertIsNotNone(s.client)
52         self.assertTrue(s.setup_done, True)
53
54     def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
55
56         options = {
57             "SPECint_benchmark": "perlbench",
58             "runspec_tune": "all",
59             "output_format": "all"
60         }
61         args = {"options": options}
62         s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
63
64         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
65         mock_ssh.SSH.from_node().get.return_value = (0, '', '')
66         s.run(self.result)
67         expected_result = {'SPEC_CPU_result': ''}
68         self.assertEqual(self.result, expected_result)
69
70     def test_spec_cpu_unsuccessful_script_error(self, mock_ssh):
71         options = {
72             "benchmark_subset": "int"
73         }
74         args = {"options": options}
75         s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx)
76
77         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
78         self.assertRaises(RuntimeError, s.run, self.result)
79
80 def main():
81     unittest.main()
82
83 if __name__ == '__main__':
84     main()