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.networking.networkcapacity.NetworkCapacity
19 from yardstick.benchmark.scenarios.networking import networkcapacity
21 SAMPLE_OUTPUT = '{"Number of connections":"308","Number of frames received": "166503"}'
23 @mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
24 class NetworkCapacityTestCase(unittest.TestCase):
37 def test_capacity_successful_setup(self, mock_ssh):
38 c = networkcapacity.NetworkCapacity({}, self.ctx)
39 mock_ssh.SSH().execute.return_value = (0, '', '')
41 self.assertIsNotNone(c.client)
42 self.assertTrue(c.setup_done)
44 def test_capacity_successful(self, mock_ssh):
45 c = networkcapacity.NetworkCapacity({}, self.ctx)
47 mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
49 expected_result = json.loads(SAMPLE_OUTPUT)
50 self.assertEqual(self.result, expected_result)
52 def test_capacity_unsuccessful_script_error(self, mock_ssh):
53 c = networkcapacity.NetworkCapacity({}, self.ctx)
55 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
56 self.assertRaises(RuntimeError, c.run, self.result)