Fix warnings reported by gen_doc.sh
[csit.git] / resources / libraries / python / VPPUtil.py
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """VPP util library"""
15 from resources.libraries.python.ssh import SSH
16
17
18 class VPPUtil(object):
19     """General class for any VPP related methods/functions."""
20
21     @staticmethod
22     def show_vpp_settings(node, *additional_cmds):
23         """Print default VPP settings. In case others are needed, can be
24         accepted as next parameters (each setting one parameter), preferably
25         in form of a string.
26
27         :param node: VPP node.
28         :param additional_cmds: Additional commands that the vpp should print
29             settings for.
30         :type node: dict
31         :type additional_cmds: tuple
32         """
33         def_setting_tb_displayed = {
34             'IPv6 FIB': 'ip6 fib',
35             'IPv4 FIB': 'ip fib',
36             'Interface IP': 'int addr',
37             'Interfaces': 'int',
38             'ARP': 'ip arp',
39             'Errors': 'err'
40         }
41
42         if additional_cmds:
43             for cmd in additional_cmds:
44                 def_setting_tb_displayed['Custom Setting: {}'.format(cmd)] = cmd
45         ssh = SSH()
46         ssh.connect(node)
47         for _, value in def_setting_tb_displayed.items():
48             ssh.exec_command_sudo('vppctl sh {}'.format(value))
49
50     @staticmethod
51     def stop_vpp_service(node):
52         """Stop VPP service on the specified node.
53
54         :param node: VPP node.
55         :type node: dict
56         :raises RuntimeError: If VPP fails to stop.
57         """
58
59         ssh = SSH()
60         ssh.connect(node)
61         cmd = "service vpp stop"
62         ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=80)
63         if int(ret_code) != 0:
64             raise RuntimeError("VPP service did not shut down gracefully.")
65
66     @staticmethod
67     def start_vpp_service(node):
68         """start VPP service on the specified node.
69
70         :param node: VPP node.
71         :type node: dict
72         :raises RuntimeError: If VPP fails to start.
73         """
74
75         ssh = SSH()
76         ssh.connect(node)
77         cmd = "service vpp start"
78         ret_code, _, _ = ssh.exec_command_sudo(cmd)
79         if int(ret_code) != 0:
80             raise RuntimeError("VPP service did not start.")