From 6962bc53fa246f3e5c081ffec5f996fcb821273b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 13 Nov 2020 14:50:09 +0100 Subject: vyos.template: provide general is_ip(v4|v6) helpers We had two places were the is_ip, is_ipv4 and is_ipv6 helpers had been defined. All places now have been converged into vyos.template as they are used both in the Jinja2 templates and also in our scripts. --- smoketest/scripts/cli/base_accel_ppp_test.py | 2 +- smoketest/scripts/cli/base_interfaces_test.py | 3 ++- smoketest/scripts/cli/test_interfaces_openvpn.py | 26 +++++++++++------------ smoketest/scripts/cli/test_service_snmp.py | 2 +- smoketest/scripts/cli/test_service_tftp-server.py | 2 +- smoketest/scripts/cli/test_system_ntp.py | 8 +++---- 6 files changed, 22 insertions(+), 21 deletions(-) (limited to 'smoketest/scripts') diff --git a/smoketest/scripts/cli/base_accel_ppp_test.py b/smoketest/scripts/cli/base_accel_ppp_test.py index e3e5071c1..e46a16137 100644 --- a/smoketest/scripts/cli/base_accel_ppp_test.py +++ b/smoketest/scripts/cli/base_accel_ppp_test.py @@ -20,10 +20,10 @@ from configparser import ConfigParser from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError +from vyos.template import is_ipv4 from vyos.util import cmd from vyos.util import get_half_cpus from vyos.util import process_named_running -from vyos.validate import is_ipv4 class BasicAccelPPPTest: class BaseTest(unittest.TestCase): diff --git a/smoketest/scripts/cli/base_interfaces_test.py b/smoketest/scripts/cli/base_interfaces_test.py index 653cc91f9..e02424073 100644 --- a/smoketest/scripts/cli/base_interfaces_test.py +++ b/smoketest/scripts/cli/base_interfaces_test.py @@ -23,7 +23,8 @@ from vyos.ifconfig import Interface from vyos.util import read_file from vyos.util import cmd from vyos.util import dict_search -from vyos.validate import is_intf_addr_assigned, is_ipv6_link_local +from vyos.validate import is_intf_addr_assigned +from vyos.validate import is_ipv6_link_local class BasicInterfaceTest: class BaseTest(unittest.TestCase): diff --git a/smoketest/scripts/cli/test_interfaces_openvpn.py b/smoketest/scripts/cli/test_interfaces_openvpn.py index 63deef5c2..4f2526977 100755 --- a/smoketest/scripts/cli/test_interfaces_openvpn.py +++ b/smoketest/scripts/cli/test_interfaces_openvpn.py @@ -26,11 +26,11 @@ from vyos.configsession import ConfigSessionError from vyos.util import cmd from vyos.util import process_named_running from vyos.util import read_file -from vyos.template import vyos_inc_ip -from vyos.template import vyos_address_from_cidr -from vyos.template import vyos_netmask_from_cidr -from vyos.template import vyos_last_host_address -from vyos.template import vyos_inc_ip +from vyos.template import inc_ip +from vyos.template import address_from_cidr +from vyos.template import netmask_from_cidr +from vyos.template import last_host_address +from vyos.template import inc_ip PROCESS_NAME = 'openvpn' @@ -319,7 +319,7 @@ class TestInterfacesOpenVPN(unittest.TestCase): for ii in num_range: interface = f'vtun{ii}' subnet = f'192.0.{ii}.0/24' - client_ip = vyos_inc_ip(subnet, '5') + client_ip = inc_ip(subnet, '5') path = base_path + [interface] port = str(2000 + ii) @@ -349,11 +349,11 @@ class TestInterfacesOpenVPN(unittest.TestCase): interface = f'vtun{ii}' subnet = f'192.0.{ii}.0/24' - start_addr = vyos_inc_ip(subnet, '2') - stop_addr = vyos_last_host_address(subnet) + start_addr = inc_ip(subnet, '2') + stop_addr = last_host_address(subnet) - client_ip = vyos_inc_ip(subnet, '5') - client_netmask = vyos_netmask_from_cidr(subnet) + client_ip = inc_ip(subnet, '5') + client_netmask = netmask_from_cidr(subnet) port = str(2000 + ii) @@ -387,7 +387,7 @@ class TestInterfacesOpenVPN(unittest.TestCase): self.assertIn(f'ifconfig-push {client_ip} {client_netmask}', client_config) for route in client1_routes: - self.assertIn('iroute {} {}'.format(vyos_address_from_cidr(route), vyos_netmask_from_cidr(route)), client_config) + self.assertIn('iroute {} {}'.format(address_from_cidr(route), netmask_from_cidr(route)), client_config) self.assertTrue(process_named_running(PROCESS_NAME)) self.assertEqual(get_vrf(interface), vrf_name) @@ -434,8 +434,8 @@ class TestInterfacesOpenVPN(unittest.TestCase): for ii in num_range: interface = f'vtun{ii}' subnet = f'192.0.{ii}.0/24' - start_addr = vyos_inc_ip(subnet, '4') - stop_addr = vyos_last_host_address(subnet) + start_addr = inc_ip(subnet, '4') + stop_addr = last_host_address(subnet) port = str(2000 + ii) config_file = f'/run/openvpn/{interface}.conf' diff --git a/smoketest/scripts/cli/test_service_snmp.py b/smoketest/scripts/cli/test_service_snmp.py index 067a3c76b..2c2e2181b 100755 --- a/smoketest/scripts/cli/test_service_snmp.py +++ b/smoketest/scripts/cli/test_service_snmp.py @@ -18,10 +18,10 @@ import os import re import unittest -from vyos.validate import is_ipv4 from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError +from vyos.template import is_ipv4 from vyos.util import read_file from vyos.util import process_named_running diff --git a/smoketest/scripts/cli/test_service_tftp-server.py b/smoketest/scripts/cli/test_service_tftp-server.py index 92333392a..3210e622f 100755 --- a/smoketest/scripts/cli/test_service_tftp-server.py +++ b/smoketest/scripts/cli/test_service_tftp-server.py @@ -24,7 +24,7 @@ from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError from vyos.util import read_file from vyos.util import process_named_running -from vyos.validate import is_ipv6 +from vyos.template import is_ipv6 PROCESS_NAME = 'in.tftpd' base_path = ['service', 'tftp-server'] diff --git a/smoketest/scripts/cli/test_system_ntp.py b/smoketest/scripts/cli/test_system_ntp.py index 4f62b62d5..822a9aff2 100755 --- a/smoketest/scripts/cli/test_system_ntp.py +++ b/smoketest/scripts/cli/test_system_ntp.py @@ -20,8 +20,8 @@ import unittest from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError -from vyos.template import vyos_address_from_cidr -from vyos.template import vyos_netmask_from_cidr +from vyos.template import address_from_cidr +from vyos.template import netmask_from_cidr from vyos.util import read_file from vyos.util import process_named_running @@ -86,8 +86,8 @@ class TestSystemNTP(unittest.TestCase): # Check generated client address configuration for network in networks: - network_address = vyos_address_from_cidr(network) - network_netmask = vyos_netmask_from_cidr(network) + network_address = address_from_cidr(network) + network_netmask = netmask_from_cidr(network) tmp = get_config_value(f'restrict {network_address}')[0] test = f'mask {network_netmask} nomodify notrap nopeer' -- cgit v1.2.3