1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
11 # yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
13 from __future__ import absolute_import
18 from oslo_serialization import jsonutils
20 from yardstick.benchmark.scenarios.compute import computecapacity
22 SAMPLE_OUTPUT = '{"Cpu_number": "2", "Core_number": "24",\
23 "Memory_size": "263753976 kB", "Thread_number": "48",\
24 "Cache_size": "30720 KB", "HT_Open": "0"}'
27 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
28 class ComputeCapacityTestCase(unittest.TestCase):
36 'key_filename': "mykey.key",
44 def test_capacity_successful_setup(self, mock_ssh):
45 c = computecapacity.ComputeCapacity({}, self.ctx)
46 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
49 self.assertIsNotNone(c.client)
50 self.assertTrue(c.setup_done)
52 def test_capacity_successful(self, mock_ssh):
53 c = computecapacity.ComputeCapacity({}, self.ctx)
55 mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '')
57 expected_result = jsonutils.loads(SAMPLE_OUTPUT)
58 self.assertEqual(self.result, expected_result)
60 def test_capacity_unsuccessful_script_error(self, mock_ssh):
61 c = computecapacity.ComputeCapacity({}, self.ctx)
63 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
64 self.assertRaises(RuntimeError, c.run, self.result)