Merge "VNF interfaces are sorted by "vpci" address before being populated"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / networking / test_networkcapacity.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.networking.networkcapacity.NetworkCapacity
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.networking import networkcapacity
21
22 SAMPLE_OUTPUT = \
23     '{"Number of connections":"308","Number of frames received": "166503"}'
24
25
26 @mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
27 class NetworkCapacityTestCase(unittest.TestCase):
28
29     def setUp(self):
30         self.ctx = {
31             'host': {
32                 'ip': '172.16.0.137',
33                 'user': 'cirros',
34                 'password': "root"
35             },
36         }
37
38         self.result = {}
39
40     def test_capacity_successful_setup(self, mock_ssh):
41         c = networkcapacity.NetworkCapacity({}, self.ctx)
42         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
43         c.setup()
44         self.assertIsNotNone(c.client)
45         self.assertTrue(c.setup_done)
46
47     def test_capacity_successful(self, mock_ssh):
48         c = networkcapacity.NetworkCapacity({}, self.ctx)
49
50         mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '')
51         c.run(self.result)
52         expected_result = jsonutils.loads(SAMPLE_OUTPUT)
53         self.assertEqual(self.result, expected_result)
54
55     def test_capacity_unsuccessful_script_error(self, mock_ssh):
56         c = networkcapacity.NetworkCapacity({}, self.ctx)
57
58         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
59         self.assertRaises(RuntimeError, c.run, self.result)