Open storperf testcase to huawei-pod2
[yardstick.git] / tests / unit / benchmark / scenarios / networking / test_vsperf.py
1 #!/usr/bin/env python
2
3 # Copyright 2016 Intel Corporation.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf
18
19 from __future__ import absolute_import
20 try:
21     from unittest import mock
22 except ImportError:
23     import mock
24 import unittest
25
26 from yardstick.benchmark.scenarios.networking import vsperf
27
28
29 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
30 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
31 @mock.patch("yardstick.benchmark.scenarios.networking.vsperf.open",
32             mock.mock_open())
33 class VsperfTestCase(unittest.TestCase):
34
35     def setUp(self):
36         self.ctx = {
37             "host": {
38                 "ip": "10.229.47.137",
39                 "user": "ubuntu",
40                 "password": "ubuntu",
41             },
42         }
43         self.args = {
44             'options': {
45                 'testname': 'p2p_rfc2544_continuous',
46                 'traffic_type': 'continuous',
47                 'frame_size': '64',
48                 'bidirectional': 'True',
49                 'iload': 100,
50                 'trafficgen_port1': 'eth1',
51                 'trafficgen_port2': 'eth3',
52                 'external_bridge': 'br-ex',
53                 'conf_file': 'vsperf-yardstick.conf',
54                 'setup_script': 'setup_yardstick.sh',
55                 'test_params': 'TRAFFICGEN_DURATION=30;',
56             },
57             'sla': {
58                 'metrics': 'throughput_rx_fps',
59                 'throughput_rx_fps': 500000,
60                 'action': 'monitor',
61             }
62         }
63
64     def test_vsperf_setup(self, mock_ssh, mock_subprocess):
65         p = vsperf.Vsperf(self.args, self.ctx)
66         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
67         mock_subprocess.call().execute.return_value = None
68
69         p.setup()
70         self.assertIsNotNone(p.client)
71         self.assertEqual(p.setup_done, True)
72
73     def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
74         p = vsperf.Vsperf(self.args, self.ctx)
75
76         # setup() specific mocks
77         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
78         mock_subprocess.call().execute.return_value = None
79
80         p.setup()
81         self.assertIsNotNone(p.client)
82         self.assertEqual(p.setup_done, True)
83
84         p.teardown()
85         self.assertEqual(p.setup_done, False)
86
87     def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
88         p = vsperf.Vsperf(self.args, self.ctx)
89
90         # setup() specific mocks
91         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
92         mock_subprocess.call().execute.return_value = None
93
94         # run() specific mocks
95         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
96         mock_ssh.SSH.from_node().execute.return_value = (
97             0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
98
99         result = {}
100         p.run(result)
101
102         self.assertEqual(result['throughput_rx_fps'], '14797660.000')
103
104     def test_vsperf_run_falied_vsperf_execution(self, mock_ssh,
105                                                 mock_subprocess):
106         p = vsperf.Vsperf(self.args, self.ctx)
107
108         # setup() specific mocks
109         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
110         mock_subprocess.call().execute.return_value = None
111
112         # run() specific mocks
113         mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
114
115         result = {}
116         self.assertRaises(RuntimeError, p.run, result)
117
118     def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess):
119         p = vsperf.Vsperf(self.args, self.ctx)
120
121         # setup() specific mocks
122         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
123         mock_subprocess.call().execute.return_value = None
124
125         # run() specific mocks
126         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
127         mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
128
129         result = {}
130         self.assertRaises(RuntimeError, p.run, result)
131
132
133 def main():
134     unittest.main()
135
136
137 if __name__ == '__main__':
138     main()