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 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
19 from yardstick.benchmark.scenarios.compute import computecapacity
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"}'
26 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
27 class ComputeCapacityTestCase(unittest.TestCase):
35 'key_filename': "mykey.key",
43 def test_capacity_successful_setup(self, mock_ssh):
44 c = computecapacity.ComputeCapacity({}, self.ctx)
45 mock_ssh.SSH().execute.return_value = (0, '', '')
48 self.assertIsNotNone(c.client)
49 self.assertTrue(c.setup_done)
51 def test_capacity_successful(self, mock_ssh):
52 c = computecapacity.ComputeCapacity({}, self.ctx)
54 mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
56 expected_result = json.loads(SAMPLE_OUTPUT)
57 self.assertEqual(self.result, expected_result)
59 def test_capacity_unsuccessful_script_error(self, mock_ssh):
60 c = computecapacity.ComputeCapacity({}, self.ctx)
62 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
63 self.assertRaises(RuntimeError, c.run, self.result)