3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
13 # yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
15 from __future__ import absolute_import
20 from oslo_serialization import jsonutils
22 from yardstick.benchmark.scenarios.compute import computecapacity
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"}'
29 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
30 class ComputeCapacityTestCase(unittest.TestCase):
38 'key_filename': "mykey.key",
46 def test_capacity_successful_setup(self, mock_ssh):
47 c = computecapacity.ComputeCapacity({}, self.ctx)
48 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
51 self.assertIsNotNone(c.client)
52 self.assertTrue(c.setup_done)
54 def test_capacity_successful(self, mock_ssh):
55 c = computecapacity.ComputeCapacity({}, self.ctx)
57 mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '')
59 expected_result = jsonutils.loads(SAMPLE_OUTPUT)
60 self.assertEqual(self.result, expected_result)
62 def test_capacity_unsuccessful_script_error(self, mock_ssh):
63 c = computecapacity.ComputeCapacity({}, self.ctx)
65 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
66 self.assertRaises(RuntimeError, c.run, self.result)