Merge "Yardstick installation unified (pip/setup)"
[yardstick.git] / 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 yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
13
14 import mock
15 import unittest
16 import os
17 import json
18
19 from yardstick.benchmark.scenarios.networking import networkcapacity
20
21 SAMPLE_OUTPUT = '{"Number of connections":"308","Number of frames received": "166503"}'
22
23 @mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
24 class NetworkCapacityTestCase(unittest.TestCase):
25
26     def setUp(self):
27         self.ctx = {
28                 'host': {
29                     'ip': '172.16.0.137',
30                     'user': 'cirros',
31                     'password': "root"
32                 },
33         }
34
35         self.result = {}
36
37     def test_capacity_successful_setup(self, mock_ssh):
38         c = networkcapacity.NetworkCapacity({}, self.ctx)
39         mock_ssh.SSH().execute.return_value = (0, '', '')
40         c.setup()
41         self.assertIsNotNone(c.client)
42         self.assertTrue(c.setup_done)
43
44     def test_capacity_successful(self, mock_ssh):
45         c = networkcapacity.NetworkCapacity({}, self.ctx)
46
47         mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
48         c.run(self.result)
49         expected_result = json.loads(SAMPLE_OUTPUT)
50         self.assertEqual(self.result, expected_result)
51
52     def test_capacity_unsuccessful_script_error(self, mock_ssh):
53         c = networkcapacity.NetworkCapacity({}, self.ctx)
54
55         mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
56         self.assertRaises(RuntimeError, c.run, self.result)