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