Merge "Add a new runner to test end-to-end fast data path"
[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
13 # yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
14
15 from __future__ import absolute_import
16
17 import unittest
18
19 import mock
20 from oslo_serialization import jsonutils
21
22 from yardstick.benchmark.scenarios.compute import computecapacity
23
24 SAMPLE_OUTPUT = '{"Cpu_number": "2", "Core_number": "24",\
25  "Memory_size": "263753976 kB", "Thread_number": "48",\
26  "Cache_size": "30720 KB", "HT_Open": "0"}'
27
28
29 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
30 class ComputeCapacityTestCase(unittest.TestCase):
31
32     def setUp(self):
33         self.ctx = {
34             'nodes': {
35                 'host': {
36                     'ip': '172.16.0.137',
37                     'user': 'cirros',
38                     'key_filename': "mykey.key",
39                     'password': "root"
40                 },
41             }
42         }
43
44         self.result = {}
45
46     def test_capacity_successful_setup(self, mock_ssh):
47         c = computecapacity.ComputeCapacity({}, self.ctx)
48         mock_ssh.SSH().execute.return_value = (0, '', '')
49
50         c.setup()
51         self.assertIsNotNone(c.client)
52         self.assertTrue(c.setup_done)
53
54     def test_capacity_successful(self, mock_ssh):
55         c = computecapacity.ComputeCapacity({}, self.ctx)
56
57         mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
58         c.run(self.result)
59         expected_result = jsonutils.loads(SAMPLE_OUTPUT)
60         self.assertEqual(self.result, expected_result)
61
62     def test_capacity_unsuccessful_script_error(self, mock_ssh):
63         c = computecapacity.ComputeCapacity({}, self.ctx)
64
65         mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
66         self.assertRaises(RuntimeError, c.run, self.result)