Merge "Added NSB descriptors for vCMTS testcase"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / vpp_helpers.py
1 # Copyright (c) 2019 Viosoft Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import logging
16
17 from yardstick.network_services.vnf_generic.vnf.sample_vnf import \
18     DpdkVnfSetupEnvHelper
19
20 LOG = logging.getLogger(__name__)
21
22
23 class VppSetupEnvHelper(DpdkVnfSetupEnvHelper):
24     APP_NAME = "vpp"
25     CFG_CONFIG = "/etc/vpp/startup.conf"
26     CFG_SCRIPT = ""
27     PIPELINE_COMMAND = ""
28     VNF_TYPE = "IPSEC"
29     VAT_BIN_NAME = 'vpp_api_test'
30
31     def __init__(self, vnfd_helper, ssh_helper, scenario_helper):
32         super(VppSetupEnvHelper, self).__init__(vnfd_helper, ssh_helper,
33                                                 scenario_helper)
34
35     def kill_vnf(self):
36         ret_code, _, _ = \
37             self.ssh_helper.execute(
38                 'service {name} stop'.format(name=self.APP_NAME))
39         if int(ret_code):
40             raise RuntimeError(
41                 'Failed to stop service {name}'.format(name=self.APP_NAME))
42
43     def tear_down(self):
44         pass
45
46     def start_vpp_service(self):
47         ret_code, _, _ = \
48             self.ssh_helper.execute(
49                 'service {name} restart'.format(name=self.APP_NAME))
50         if int(ret_code):
51             raise RuntimeError(
52                 'Failed to start service {name}'.format(name=self.APP_NAME))
53
54     def _update_vnfd_helper(self, additional_data, iface_key=None):
55         for k, v in additional_data.items():
56             if iface_key is None:
57                 if isinstance(v, dict) and k in self.vnfd_helper:
58                     self.vnfd_helper[k].update(v)
59                 else:
60                     self.vnfd_helper[k] = v
61             else:
62                 if isinstance(v,
63                               dict) and k in self.vnfd_helper.find_virtual_interface(
64                     ifname=iface_key):
65                     self.vnfd_helper.find_virtual_interface(ifname=iface_key)[
66                         k].update(v)
67                 else:
68                     self.vnfd_helper.find_virtual_interface(ifname=iface_key)[
69                         k] = v
70
71     def get_value_by_interface_key(self, interface, key):
72         try:
73             return self.vnfd_helper.find_virtual_interface(
74                 ifname=interface).get(key)
75         except (KeyError, ValueError):
76             return None