1 # Copyright (c) 2016-2017 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.
16 import multiprocessing
22 from yardstick.network_services.vnf_generic.vnf import base
23 from yardstick.ssh import SSH
26 IP_PIPELINE_CFG_FILE_TPL = ("arp_route_tbl = ({port0_local_ip_hex},"
27 "{port0_netmask_hex},1,{port1_local_ip_hex}) "
28 "({port1_local_ip_hex},{port1_netmask_hex},0,"
29 "{port0_local_ip_hex})")
31 IP_PIPELINE_ND_CFG_FILE_TPL = """
32 nd_route_tbl = ({port1_dst_ip_hex6},"""
33 """{port1_dst_netmask_hex6},1,{port1_dst_ip_hex6})"""
35 _LOCAL_OBJECT = object()
38 'short-name': 'VpeVnf',
43 'network': '152.16.100.20',
44 'netmask': '255.255.255.0',
45 'gateway': '152.16.100.20',
49 'network': '152.16.40.20',
50 'netmask': '255.255.255.0',
51 'gateway': '152.16.40.20',
55 'description': 'VPE approximation using DPDK',
56 'name': 'vpevnf-baremetal',
59 'network': '0064:ff9b:0:0:0:0:9810:6414',
61 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
65 'network': '0064:ff9b:0:0:0:0:9810:2814',
67 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
71 'id': 'vpevnf-baremetal',
72 'external-interface': [
74 'virtual-interface': {
75 'dst_mac': '00:00:00:00:00:03',
76 'vpci': '0000:05:00.0',
77 'local_ip': '152.16.100.19',
78 'type': 'PCI-PASSTHROUGH',
79 'netmask': '255.255.255.0',
81 'bandwidth': '10 Gbps',
82 'dst_ip': '152.16.100.20',
83 'local_mac': '00:00:00:00:00:01'
85 'vnfd-connection-point-ref': 'xe0',
89 'virtual-interface': {
90 'dst_mac': '00:00:00:00:00:04',
91 'vpci': '0000:05:00.1',
92 'local_ip': '152.16.40.19',
93 'type': 'PCI-PASSTHROUGH',
94 'netmask': '255.255.255.0',
96 'bandwidth': '10 Gbps',
97 'dst_ip': '152.16.40.20',
98 'local_mac': '00:00:00:00:00:02'
100 'vnfd-connection-point-ref': 'xe1',
106 'description': 'Vpe approximation using DPDK',
108 'vdu-id': 'vpevnf-baremetal',
121 'connection-point': [
131 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'
135 'vnfd:vnfd-catalog': {
143 class FileAbsPath(object):
144 def __init__(self, module_file):
145 super(FileAbsPath, self).__init__()
146 self.module_path = os.path.dirname(os.path.abspath(module_file))
148 def get_path(self, filename):
149 file_path = os.path.join(self.module_path, filename)
153 def mock_ssh(mock_ssh_type, spec=None, exec_result=_LOCAL_OBJECT, run_result=_LOCAL_OBJECT):
157 if exec_result is _LOCAL_OBJECT:
158 exec_result = 0, "", ""
160 if run_result is _LOCAL_OBJECT:
161 run_result = 0, "", ""
163 mock_ssh_instance = mock.Mock(autospec=spec)
164 mock_ssh_instance._get_client.return_value = mock.Mock()
165 mock_ssh_instance.execute.return_value = exec_result
166 mock_ssh_instance.run.return_value = run_result
167 mock_ssh_type.from_node.return_value = mock_ssh_instance
168 return mock_ssh_instance
171 class TestQueueFileWrapper(unittest.TestCase):
173 self.prompt = "pipeline>"
174 self.q_in = multiprocessing.Queue()
175 self.q_out = multiprocessing.Queue()
177 def test___init__(self):
178 queue_file_wrapper = \
179 base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
180 self.assertEqual(queue_file_wrapper.prompt, self.prompt)
182 def test_clear(self):
183 queue_file_wrapper = \
184 base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
185 queue_file_wrapper.bufsize = 5
186 queue_file_wrapper.write("pipeline>")
187 queue_file_wrapper.close()
188 self.assertIsNone(queue_file_wrapper.clear())
189 self.assertIsNotNone(queue_file_wrapper.q_out.empty())
191 def test_close(self):
192 queue_file_wrapper = \
193 base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
194 self.assertIsNone(queue_file_wrapper.close())
197 queue_file_wrapper = \
198 base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
199 queue_file_wrapper.q_in.put("pipeline>")
200 self.assertEqual("pipeline>", queue_file_wrapper.read(20))
202 def test_write(self):
203 queue_file_wrapper = \
204 base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
205 queue_file_wrapper.write("pipeline>")
206 self.assertIsNotNone(queue_file_wrapper.q_out.empty())
209 class TestGenericVNF(unittest.TestCase):
211 def test_definition(self):
212 """Make sure that the abstract class cannot be instantiated"""
213 with self.assertRaises(TypeError) as exc:
214 # pylint: disable=abstract-class-instantiated
215 base.GenericVNF('vnf1', VNFD['vnfd:vnfd-catalog']['vnfd'][0])
217 msg = ("Can't instantiate abstract class GenericVNF with abstract methods "
218 "collect_kpi, instantiate, scale, start_collect, "
219 "stop_collect, terminate, wait_for_instantiate")
221 self.assertEqual(msg, str(exc.exception))
224 class TestGenericTrafficGen(unittest.TestCase):
226 def test_definition(self):
227 """Make sure that the abstract class cannot be instantiated"""
228 vnfd = VNFD['vnfd:vnfd-catalog']['vnfd'][0]
230 with self.assertRaises(TypeError) as exc:
231 # pylint: disable=abstract-class-instantiated
232 base.GenericTrafficGen(name, vnfd)
233 msg = ("Can't instantiate abstract class GenericTrafficGen with "
234 "abstract methods collect_kpi, instantiate, run_traffic, "
236 self.assertEqual(msg, str(exc.exception))