compute capacity description adjustment and HT check added
[yardstick.git] / tests / unit / benchmark / scenarios / compute / test_computecapacity.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 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.computecapacity.ComputeCapacity
13
14 import mock
15 import unittest
16 import os
17 import json
18
19 from yardstick.benchmark.scenarios.compute import computecapacity
20
21 SAMPLE_OUTPUT = '{"Cpu_number": "2", "Core_number": "24",\
22  "Memory_size": "263753976 kB", "Thread_number": "48",\
23  "Cache_size": "30720 KB", "HT_Open": "0"}'
24
25
26 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
27 class ComputeCapacityTestCase(unittest.TestCase):
28
29     def setUp(self):
30         self.ctx = {
31             'nodes': {
32                 'host': {
33                     'ip': '172.16.0.137',
34                     'user': 'cirros',
35                     'key_filename': "mykey.key",
36                     'password': "root"
37                 },
38             }
39         }
40
41         self.result = {}
42
43     def test_capacity_successful_setup(self, mock_ssh):
44         c = computecapacity.ComputeCapacity({}, self.ctx)
45         mock_ssh.SSH().execute.return_value = (0, '', '')
46
47         c.setup()
48         self.assertIsNotNone(c.client)
49         self.assertTrue(c.setup_done)
50
51     def test_capacity_successful(self, mock_ssh):
52         c = computecapacity.ComputeCapacity({}, self.ctx)
53
54         mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
55         c.run(self.result)
56         expected_result = json.loads(SAMPLE_OUTPUT)
57         self.assertEqual(self.result, expected_result)
58
59     def test_capacity_unsuccessful_script_error(self, mock_ssh):
60         c = computecapacity.ComputeCapacity({}, self.ctx)
61
62         mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
63         self.assertRaises(RuntimeError, c.run, self.result)