1 # Copyright (c) 2018 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.
19 from yardstick.common import constants
20 from yardstick.common import exceptions
21 from yardstick.network_services.vnf_generic.vnf import base as vnf_base
22 from yardstick.network_services.vnf_generic.vnf import tg_pktgen
23 from yardstick.tests.unit import base as ut_base
26 class PktgenTrafficGenTestCase(ut_base.BaseUnitTestCase):
28 SERVICE_PORTS = [{'port': constants.LUA_PORT,
29 'node_port': '34501'}]
30 VNFD = {'mgmt-interface': {'ip': '1.2.3.4',
31 'service_ports': SERVICE_PORTS},
32 'vdu': [{'external-interface': 'interface'}],
33 'benchmark': {'kpi': 'fake_kpi'}
37 self._id = uuid.uuid1().int
38 self._mock_vnf_consumer = mock.patch.object(vnf_base,
40 self.mock_vnf_consumer = self._mock_vnf_consumer.start()
41 self.addCleanup(self._stop_mock)
44 self._mock_vnf_consumer.stop()
47 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
48 self.assertTrue(isinstance(tg, (vnf_base.GenericTrafficGen,
49 vnf_base.GenericVNFEndpoint)))
51 def test_run_traffic(self):
52 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
54 with mock.patch.object(tg, '_is_running', return_value=True):
55 tg.run_traffic(mock_tp)
57 mock_tp.init.assert_called_once_with(tg._node_ip, tg._lua_node_port)
59 def test__get_lua_node_port(self):
60 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
61 service_ports = [{'port': constants.LUA_PORT,
62 'node_port': '12345'}]
63 self.assertEqual(12345, tg._get_lua_node_port(service_ports))
65 def test__get_lua_node_port_no_lua_port(self):
66 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
67 service_ports = [{'port': '333'}]
68 self.assertIsNone(tg._get_lua_node_port(service_ports))
70 def test__is_running(self):
71 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
72 with mock.patch.object(tg, '_traffic_profile'):
73 self.assertTrue(tg._is_running())
75 def test__is_running_exception(self):
76 tg = tg_pktgen.PktgenTrafficGen('name1', self.VNFD, self._id)
77 with mock.patch.object(tg, '_traffic_profile') as mock_tp:
78 mock_tp.help.side_effect = exceptions.PktgenActionError()
79 self.assertFalse(tg._is_running())