1 # Copyright (c) 2018-2019 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from yardstick.common import constants
18 from yardstick.common import exceptions
19 from yardstick.network_services.vnf_generic.vnf import base as vnf_base
20 from yardstick.network_services.vnf_generic.vnf import tg_pktgen
21 from yardstick.tests.unit import base as ut_base
24 class PktgenTrafficGenTestCase(ut_base.BaseUnitTestCase):
26 SERVICE_PORTS = [{'port': constants.LUA_PORT,
27 'node_port': '34501'}]
28 VNFD = {'mgmt-interface': {'ip': '1.2.3.4',
29 'service_ports': SERVICE_PORTS},
30 'vdu': [{'external-interface': 'interface'}],
31 'benchmark': {'kpi': 'fake_kpi'}
35 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
36 self.assertTrue(isinstance(tg, vnf_base.GenericTrafficGen))
38 def test_run_traffic(self):
39 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
41 with mock.patch.object(tg, '_is_running', return_value=True):
42 tg.run_traffic(mock_tp)
44 mock_tp.init.assert_called_once_with(tg._node_ip, tg._lua_node_port)
46 def test__get_lua_node_port(self):
47 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
48 service_ports = [{'port': constants.LUA_PORT,
49 'node_port': '12345'}]
50 self.assertEqual(12345, tg._get_lua_node_port(service_ports))
52 def test__get_lua_node_port_no_lua_port(self):
53 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
54 service_ports = [{'port': '333'}]
55 self.assertIsNone(tg._get_lua_node_port(service_ports))
57 def test__is_running(self):
58 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
59 with mock.patch.object(tg, '_traffic_profile'):
60 self.assertTrue(tg._is_running())
62 def test__is_running_exception(self):
63 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD)
64 with mock.patch.object(tg, '_traffic_profile') as mock_tp:
65 mock_tp.help.side_effect = exceptions.PktgenActionError()
66 self.assertFalse(tg._is_running())