Replace nova delete keypair with shade client.
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / compute / test_computecapacity.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 # Unittest for
11 # yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
12
13 from __future__ import absolute_import
14
15 import unittest
16
17 import mock
18 from oslo_serialization import jsonutils
19
20 from yardstick.benchmark.scenarios.compute import computecapacity
21
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"}'
25
26
27 @mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
28 class ComputeCapacityTestCase(unittest.TestCase):
29
30     def setUp(self):
31         self.ctx = {
32             'nodes': {
33                 'host': {
34                     'ip': '172.16.0.137',
35                     'user': 'cirros',
36                     'key_filename': "mykey.key",
37                     'password': "root"
38                 },
39             }
40         }
41
42         self.result = {}
43
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, '', '')
47
48         c.setup()
49         self.assertIsNotNone(c.client)
50         self.assertTrue(c.setup_done)
51
52     def test_capacity_successful(self, mock_ssh):
53         c = computecapacity.ComputeCapacity({}, self.ctx)
54
55         mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '')
56         c.run(self.result)
57         expected_result = jsonutils.loads(SAMPLE_OUTPUT)
58         self.assertEqual(self.result, expected_result)
59
60     def test_capacity_unsuccessful_script_error(self, mock_ssh):
61         c = computecapacity.ComputeCapacity({}, self.ctx)
62
63         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
64         self.assertRaises(RuntimeError, c.run, self.result)