fix(vlan): do not apply strip offload
[csit.git] / resources / libraries / python / SysctlUtil.py
1 # Copyright (c) 2021 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 """Linux sysctl library."""
15
16 from resources.libraries.python.ssh import exec_cmd_no_error
17
18 __all__ = [u"SysctlUtil"]
19
20
21 class SysctlUtil:
22     """Class contains methods for getting or setting sysctl settings."""
23
24     @staticmethod
25     def get_sysctl_value(node, key):
26         """Get sysctl key.
27
28         :param node: Node in the topology.
29         :param key: Key that will be set.
30         :type node: dict
31         :type key: str
32         """
33         command = f"sysctl {key}"
34         message = f"Node {node[u'host']} failed to run: {command}"
35
36         exec_cmd_no_error(node, command, sudo=True, message=message)
37
38     @staticmethod
39     def set_sysctl_value(node, key, value):
40         """Set sysctl key to specific value.
41
42         :param node: Node in the topology.
43         :param key: Key that will be set.
44         :param value: Value to set.
45         :type node: dict
46         :type key: str
47         :type value: str
48         """
49         command = f"sysctl -w {key}={value}"
50         message = f"Node {node[u'host']} failed to run: {command}"
51
52         exec_cmd_no_error(node, command, sudo=True, message=message)