Merge "Improve SampleVNF hugepages setup"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / networking / test_networkcapacity.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for
13 # yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
14
15 from __future__ import absolute_import
16
17 import unittest
18
19 import mock
20 from oslo_serialization import jsonutils
21
22 from yardstick.benchmark.scenarios.networking import networkcapacity
23
24 SAMPLE_OUTPUT = \
25     '{"Number of connections":"308","Number of frames received": "166503"}'
26
27
28 @mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
29 class NetworkCapacityTestCase(unittest.TestCase):
30
31     def setUp(self):
32         self.ctx = {
33             'host': {
34                 'ip': '172.16.0.137',
35                 'user': 'cirros',
36                 'password': "root"
37             },
38         }
39
40         self.result = {}
41
42     def test_capacity_successful_setup(self, mock_ssh):
43         c = networkcapacity.NetworkCapacity({}, self.ctx)
44         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
45         c.setup()
46         self.assertIsNotNone(c.client)
47         self.assertTrue(c.setup_done)
48
49     def test_capacity_successful(self, mock_ssh):
50         c = networkcapacity.NetworkCapacity({}, self.ctx)
51
52         mock_ssh.SSH.from_node().execute.return_value = (0, SAMPLE_OUTPUT, '')
53         c.run(self.result)
54         expected_result = jsonutils.loads(SAMPLE_OUTPUT)
55         self.assertEqual(self.result, expected_result)
56
57     def test_capacity_unsuccessful_script_error(self, mock_ssh):
58         c = networkcapacity.NetworkCapacity({}, self.ctx)
59
60         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
61         self.assertRaises(RuntimeError, c.run, self.result)