diff options
-rw-r--r-- | interface-definitions/dhcp-server.xml.in | 1 | ||||
-rw-r--r-- | python/vyos/ifconfig/tunnel.py | 2 | ||||
-rw-r--r-- | python/vyos/template.py | 4 | ||||
-rw-r--r-- | python/vyos/util.py | 71 | ||||
-rwxr-xr-x | src/conf_mode/vpn_l2tp.py | 5 | ||||
-rw-r--r-- | src/tests/helper.py | 3 | ||||
-rw-r--r-- | src/tests/test_config_parser.py | 4 | ||||
-rwxr-xr-x | src/tests/test_find_device_file.py | 35 | ||||
-rw-r--r-- | src/tests/test_template.py | 31 | ||||
-rw-r--r-- | src/tests/test_util.py | 6 | ||||
-rw-r--r-- | src/tests/test_vyos_dict_search.py | 2 |
11 files changed, 76 insertions, 88 deletions
diff --git a/interface-definitions/dhcp-server.xml.in b/interface-definitions/dhcp-server.xml.in index ca8abc036..978118b31 100644 --- a/interface-definitions/dhcp-server.xml.in +++ b/interface-definitions/dhcp-server.xml.in @@ -87,6 +87,7 @@ <constraint> <validator name="ipv4-prefix"/> </constraint> + <constraintErrorMessage>Invalid IPv4 subnet definition</constraintErrorMessage> </properties> <children> <leafNode name="bootfile-name"> diff --git a/python/vyos/ifconfig/tunnel.py b/python/vyos/ifconfig/tunnel.py index 964ffe383..4122d1a2f 100644 --- a/python/vyos/ifconfig/tunnel.py +++ b/python/vyos/ifconfig/tunnel.py @@ -179,7 +179,7 @@ class GRETapIf(_Tunnel): default = {'type': 'gretap'} required = ['local', ] - options = ['local', 'remote', ] + options = ['local', 'remote', 'ttl',] updates = ['mtu', ] create = 'ip link add {ifname} type {type}' diff --git a/python/vyos/template.py b/python/vyos/template.py index c88ab04a0..1f1ddc000 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -131,7 +131,7 @@ def vyos_address_from_cidr(text): Example: 192.0.2.0/24 -> 192.0.2.0, 2001:db8::/48 -> 2001:db8:: """ - return ip_network(text).network_address + return str(ip_network(text).network_address) @register_filter("netmask_from_cidr") @@ -140,4 +140,4 @@ def vyos_netmask_from_cidr(text): Example: 192.0.2.0/24 -> 255.255.255.0, 2001:db8::/48 -> ffff:ffff:ffff:: """ - return ip_network(text).netmask + return str(ip_network(text).netmask) diff --git a/python/vyos/util.py b/python/vyos/util.py index b5f0ea36e..e3e389baf 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -581,77 +581,6 @@ def get_half_cpus(): cpu /= 2 return int(cpu) -def ifname_from_config(conf): - """ - Gets interface name with VLANs from current config level. - Level must be at the interface whose name we want. - - Example: - >>> from vyos.util import ifname_from_config - >>> from vyos.config import Config - >>> conf = Config() - >>> conf.set_level('interfaces ethernet eth0 vif-s 1 vif-c 2') - >>> ifname_from_config(conf) - 'eth0.1.2' - """ - level = conf.get_level() - - # vlans - if level[-2] == 'vif' or level[-2] == 'vif-s': - return level[-3] + '.' + level[-1] - if level[-2] == 'vif-c': - return level[-5] + '.' + level[-3] + '.' + level[-1] - - # no vlans - return level[-1] - -def get_bridge_member_config(conf, br, intf): - """ - Gets bridge port (member) configuration - - Arguments: - conf: Config - br: bridge name - intf: interface name - - Returns: - dict with the configuration - False if bridge or bridge port doesn't exist - """ - old_level = conf.get_level() - conf.set_level([]) - - bridge = f'interfaces bridge {br}' - member = f'{bridge} member interface {intf}' - if not ( conf.exists(bridge) and conf.exists(member) ): - return False - - # default bridge port configuration - # cost and priority initialized with linux defaults - # by reading /sys/devices/virtual/net/br0/brif/eth2/{path_cost,priority} - # after adding interface to bridge after reboot - memberconf = { - 'cost': 100, - 'priority': 32, - 'arp_cache_tmo': 30, - 'disable_link_detect': 1, - } - - if conf.exists(f'{member} cost'): - memberconf['cost'] = int(conf.return_value(f'{member} cost')) - - if conf.exists(f'{member} priority'): - memberconf['priority'] = int(conf.return_value(f'{member} priority')) - - if conf.exists(f'{bridge} ip arp-cache-timeout'): - memberconf['arp_cache_tmo'] = int(conf.return_value(f'{bridge} ip arp-cache-timeout')) - - if conf.exists(f'{bridge} disable-link-detect'): - memberconf['disable_link_detect'] = 2 - - conf.set_level(old_level) - return memberconf - def check_kmod(k_mod): """ Common utility function to load required kernel modules on demand """ from vyos import ConfigError diff --git a/src/conf_mode/vpn_l2tp.py b/src/conf_mode/vpn_l2tp.py index 4d82a9400..465986d5b 100755 --- a/src/conf_mode/vpn_l2tp.py +++ b/src/conf_mode/vpn_l2tp.py @@ -100,7 +100,8 @@ def get_config(config=None): if conf.exists(['authentication', 'mode']): l2tp['auth_mode'] = conf.return_value(['authentication', 'mode']) - if conf.exists(['authentication', 'protocols']): + if conf.exists(['authentication', 'require']): + l2tp['auth_proto'] = [] auth_mods = { 'pap': 'auth_pap', 'chap': 'auth_chap_md5', @@ -108,7 +109,7 @@ def get_config(config=None): 'mschap-v2': 'auth_mschap_v2' } - for proto in conf.return_values(['authentication', 'protocols']): + for proto in conf.return_values(['authentication', 'require']): l2tp['auth_proto'].append(auth_mods[proto]) if conf.exists(['authentication', 'mppe']): diff --git a/src/tests/helper.py b/src/tests/helper.py index a7e4f201c..f7033148a 100644 --- a/src/tests/helper.py +++ b/src/tests/helper.py @@ -13,13 +13,10 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# import sys import importlib.util - def prepare_module(file_path='', module_name=''): spec = importlib.util.spec_from_file_location(module_name, file_path) module = importlib.util.module_from_spec(spec) diff --git a/src/tests/test_config_parser.py b/src/tests/test_config_parser.py index 5b922e2dd..6e0a071f8 100644 --- a/src/tests/test_config_parser.py +++ b/src/tests/test_config_parser.py @@ -15,11 +15,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os -import tempfile -import unittest +import vyos.configtree from unittest import TestCase -import vyos.configtree class TestConfigParser(TestCase): def setUp(self): diff --git a/src/tests/test_find_device_file.py b/src/tests/test_find_device_file.py new file mode 100755 index 000000000..43c80dc76 --- /dev/null +++ b/src/tests/test_find_device_file.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from unittest import TestCase +from vyos.util import find_device_file + +class TestDeviceFile(TestCase): + """ used to find USB devices on target """ + def setUp(self): + pass + + def test_null(self): + self.assertEqual(find_device_file('null'), '/dev/null') + + def test_zero(self): + self.assertEqual(find_device_file('zero'), '/dev/zero') + + def test_input_event(self): + self.assertEqual(find_device_file('event0'), '/dev/input/event0') + + def test_non_existing(self): + self.assertFalse(find_device_file('vyos')) diff --git a/src/tests/test_template.py b/src/tests/test_template.py new file mode 100644 index 000000000..0b9f2c3b8 --- /dev/null +++ b/src/tests/test_template.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from unittest import TestCase + +from vyos.template import vyos_address_from_cidr +from vyos.template import vyos_netmask_from_cidr + + +class TestTeamplteHelpers(TestCase): + def setUp(self): + pass + + def test_helpers_from_cidr(self): + network = '192.0.2.0/26' + self.assertEqual(vyos_address_from_cidr(network), '192.0.2.0') + self.assertEqual(vyos_netmask_from_cidr(network), '255.255.255.192') + diff --git a/src/tests/test_util.py b/src/tests/test_util.py index 09bf947b8..f7405cbde 100644 --- a/src/tests/test_util.py +++ b/src/tests/test_util.py @@ -14,10 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import unittest from unittest import TestCase - -import vyos.util +from vyos.util import mangle_dict_keys class TestVyOSUtil(TestCase): @@ -27,6 +25,6 @@ class TestVyOSUtil(TestCase): def test_key_mangline(self): data = {"foo-bar": {"baz-quux": None}} expected_data = {"foo_bar": {"baz_quux": None}} - new_data = vyos.util.mangle_dict_keys(data, '-', '_') + new_data = mangle_dict_keys(data, '-', '_') self.assertEqual(new_data, expected_data) diff --git a/src/tests/test_vyos_dict_search.py b/src/tests/test_vyos_dict_search.py index ef338d46f..cba6562da 100644 --- a/src/tests/test_vyos_dict_search.py +++ b/src/tests/test_vyos_dict_search.py @@ -14,9 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import unittest from unittest import TestCase - from vyos.util import vyos_dict_search data = { |