Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions smoketest/scripts/cli/base_vyostest_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,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 importlib.util
import os
import paramiko
import pprint
import re
import sys
import unittest

from time import sleep
Expand Down Expand Up @@ -56,17 +54,6 @@ def debug_on():

@classmethod
def setUpClass(cls):
# Import frr-reload.py functionality
file_path = '/usr/lib/frr/frr-reload.py'
module_name = 'frr_reload'

spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
Vtysh = getattr(module, 'Vtysh')
cls._vtysh = Vtysh(bindir='/usr/bin', confdir='/etc/frr')

cls._session = ConfigSession(os.getpid())
cls._session.save_config(save_config)
cls.debug = cls.debug_on()
Expand Down Expand Up @@ -140,25 +127,31 @@ def op_mode(self, path : list) -> None:
pprint.pprint(out)
return out

def getFRRconfig(self, start_section:str=None, stop_section='^!',
def getFRRconfig(self, start_section:str=None, end_marker='$', stop_section='^!',
start_subsection:str=None, stop_subsection='^ exit') -> str:
"""
Retrieve current "running configuration" from FRR

start_section: search for a specific start string in the configuration
end_marker: override default "line end $" marker to match on an
"open end" string
stop_section: end of the configuration
start_subsection: search section under the result found by string
stop_subsection: end of the subsection (usually something with "exit")
"""
frr_config = self._vtysh.mark_show_run()
from vyos.utils.process import rc_cmd

rc, frr_config = rc_cmd('vtysh -c "show running-config no-header"')
self.assertEqual(rc, 0)

if not start_section:
return frr_config

extracted = []
in_section = False
for line in frr_config.splitlines():
if not in_section:
if re.match(start_section, line):
if re.match(f'^{start_section}{end_marker}', line):
in_section = True
extracted.append(line)
else:
Expand Down
24 changes: 12 additions & 12 deletions smoketest/scripts/cli/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_access_list(self):

self.cli_commit()

config = self.getFRRconfig('access-list')
config = self.getFRRconfig('access-list', end_marker='')
for acl, acl_config in acls.items():
for rule, rule_config in acl_config['rule'].items():
tmp = f'access-list {acl} seq {rule}'
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_access_list6(self):

self.cli_commit()

config = self.getFRRconfig('ipv6 access-list')
config = self.getFRRconfig('ipv6 access-list', end_marker='')
for acl, acl_config in acls.items():
for rule, rule_config in acl_config['rule'].items():
tmp = f'ipv6 access-list {acl} seq {rule}'
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_as_path_list(self):

self.cli_commit()

config = self.getFRRconfig('bgp as-path access-list')
config = self.getFRRconfig('bgp as-path access-list', end_marker='')
for as_path, as_path_config in test_data.items():
if 'rule' not in as_path_config:
continue
Expand Down Expand Up @@ -370,7 +370,7 @@ def test_community_list(self):

self.cli_commit()

config = self.getFRRconfig('bgp community-list')
config = self.getFRRconfig('bgp community-list', end_marker='')
for comm_list, comm_list_config in test_data.items():
if 'rule' not in comm_list_config:
continue
Expand Down Expand Up @@ -428,7 +428,7 @@ def test_extended_community_list(self):

self.cli_commit()

config = self.getFRRconfig('bgp extcommunity-list')
config = self.getFRRconfig('bgp extcommunity-list', end_marker='')
for comm_list, comm_list_config in test_data.items():
if 'rule' not in comm_list_config:
continue
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_large_community_list(self):

self.cli_commit()

config = self.getFRRconfig('bgp large-community-list')
config = self.getFRRconfig('bgp large-community-list', end_marker='')
for comm_list, comm_list_config in test_data.items():
if 'rule' not in comm_list_config:
continue
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_prefix_list(self):

self.cli_commit()

config = self.getFRRconfig('ip prefix-list')
config = self.getFRRconfig('ip prefix-list', end_marker='')
for prefix_list, prefix_list_config in test_data.items():
if 'rule' not in prefix_list_config:
continue
Expand Down Expand Up @@ -654,7 +654,7 @@ def test_prefix_list6(self):

self.cli_commit()

config = self.getFRRconfig('ipv6 prefix-list')
config = self.getFRRconfig('ipv6 prefix-list', end_marker='')
for prefix_list, prefix_list_config in test_data.items():
if 'rule' not in prefix_list_config:
continue
Expand Down Expand Up @@ -705,7 +705,7 @@ def test_prefix_list_duplicates(self):

self.cli_commit()

config = self.getFRRconfig('ip prefix-list')
config = self.getFRRconfig('ip prefix-list', end_marker='')
for rule in test_range:
tmp = f'ip prefix-list {prefix_list} seq {rule} permit {prefix} le {rule}'
self.assertIn(tmp, config)
Expand Down Expand Up @@ -842,7 +842,7 @@ def test_route_map_community_set(self):
self.assertIn(name, config)

if 'set' in rule_config:
#Check community
# Check community
if 'community' in rule_config['set']:
if 'none' in rule_config['set']['community']:
tmp = f'set community none'
Expand All @@ -855,7 +855,7 @@ def test_route_map_community_set(self):
values = ' '.join(rule_config['set']['community']['add'])
tmp = f'set community {values} additive'
self.assertIn(tmp, config)
#Check large-community
# Check large-community
if 'large-community' in rule_config['set']:
if 'none' in rule_config['set']['large-community']:
tmp = f'set large-community none'
Expand All @@ -868,7 +868,7 @@ def test_route_map_community_set(self):
values = ' '.join(rule_config['set']['large-community']['add'])
tmp = f'set large-community {values} additive'
self.assertIn(tmp, config)
#Check extcommunity
# Check extcommunity
if 'extcommunity' in rule_config['set']:
if 'none' in rule_config['set']['extcommunity']:
tmp = 'set extcommunity none'
Expand Down
17 changes: 7 additions & 10 deletions smoketest/scripts/cli/test_protocols_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_01_static(self):
self.cli_commit()

# Verify FRR bgpd configuration
frrconfig = self.getFRRconfig('ip route')
frrconfig = self.getFRRconfig('ip route', end_marker='')

# Verify routes
for route, route_config in routes.items():
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_02_static_table(self):
self.cli_commit()

# Verify FRR bgpd configuration
frrconfig = self.getFRRconfig('ip route')
frrconfig = self.getFRRconfig('ip route', end_marker='')

for table in tables:
# Verify routes
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_04_static_multicast(self):
self.cli_commit()

# Verify FRR configuration
frrconfig = self.getFRRconfig('ip mroute')
frrconfig = self.getFRRconfig('ip mroute', end_marker='')
for route, route_config in multicast_routes.items():
if 'next_hop' in route_config:
for next_hop, next_hop_config in route_config['next_hop'].items():
Expand Down Expand Up @@ -712,15 +712,12 @@ def test_07_dhcp_interface_static_routes(self):
self.assertIsNotNone(router, 'DHCP router should be available')

# Verify FRR configuration contains the static routes with DHCP router
frrconfig = self.getFRRconfig('ip route')
frrconfig = self.getFRRconfig('ip route', end_marker='')

for route in dhcp_routes.keys():
expected_route = f'ip route {route} {router} {dhcp_interface}'
self.assertIn(
expected_route,
frrconfig,
f'Static route {route} with dhcp-interface should be in FRR config',
)
self.assertIn(expected_route, frrconfig, f'Static route {route} '\
'with dhcp-interface should be in FRR config')

# Test table-based routes with dhcp-interface
table_id = '100'
Expand All @@ -730,7 +727,7 @@ def test_07_dhcp_interface_static_routes(self):
self.cli_commit()

# Verify table route in FRR config
frrconfig = self.getFRRconfig('ip route')
frrconfig = self.getFRRconfig('ip route', end_marker='')
expected_table_route = (
f'ip route {table_route} {router} {dhcp_interface} table {table_id}'
)
Expand Down
6 changes: 4 additions & 2 deletions smoketest/scripts/cli/test_system_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ def test_system_ip_protocol_route_map(self):
protocols = ['any', 'babel', 'bgp', 'connected', 'eigrp', 'isis',
'kernel', 'ospf', 'rip', 'static', 'table']

rule_num = '10'

for protocol in protocols:
self.cli_set(['policy', 'route-map', f'route-map-{protocol}', 'rule', '10', 'action', 'permit'])
self.cli_set(['policy', 'route-map', f'route-map-{protocol}', 'rule', rule_num, 'action', 'permit'])
self.cli_set(base_path + ['protocol', protocol, 'route-map', f'route-map-{protocol}'])

self.cli_commit()

# Verify route-map properly applied to FRR
frrconfig = self.getFRRconfig('ip protocol', stop_section='^end')
frrconfig = self.getFRRconfig('ip protocol', end_marker='', stop_section='^end')
for protocol in protocols:
self.assertIn(f'ip protocol {protocol} route-map route-map-{protocol}', frrconfig)

Expand Down
2 changes: 1 addition & 1 deletion smoketest/scripts/cli/test_system_ipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_system_ipv6_protocol_route_map(self):
self.cli_commit()

# Verify route-map properly applied to FRR
frrconfig = self.getFRRconfig('ipv6 protocol', stop_section='^end')
frrconfig = self.getFRRconfig('ipv6 protocol', end_marker='', stop_section='^end')
for protocol in protocols:
# VyOS and FRR use a different name for OSPFv3 (IPv6)
if protocol == 'ospfv3':
Expand Down
27 changes: 15 additions & 12 deletions smoketest/scripts/cli/test_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

from json import loads
from jmespath import search
from time import sleep

from base_vyostest_shim import VyOSUnitTestSHIM

from vyos.configsession import ConfigSessionError
from vyos.ifconfig import Interface
from vyos.ifconfig import Section
from vyos.utils.file import read_file
from vyos.utils.misc import wait_for
from vyos.utils.network import get_interface_config
from vyos.utils.network import get_vrf_tableid
from vyos.utils.network import is_intf_addr_assigned
Expand Down Expand Up @@ -783,8 +783,7 @@ def test_dhcp_single_pool(self):
def test_dhcp_vrf_default_route(self):
# T7927 - when retrieving a default route via DHCP, check that additional
# calls into FRRender() keep the DHCP route in place

vrf_name = 'red15'
vrf_name = 'red-16'
default_gateway = '192.0.2.1'
dhcp_if_server = 'veth0'
dhcp_if_client = 'veth1'
Expand Down Expand Up @@ -816,25 +815,29 @@ def test_dhcp_vrf_default_route(self):
self.cli_set(['interfaces', 'virtual-ethernet', dhcp_if_client, 'address', 'dhcp'])
self.cli_commit()

# We need to wait until DHCP client has started and an IP address has been received
sleep(8)
# define helper for the string we are looking for in FRR configuration
# the leading whitespace is required as this lives under a VRF context!
test_ok_string = f' ip route 0.0.0.0/0 {default_gateway} {dhcp_if_client}'\
f' tag 210 {default_distance}'

frrconfig = self.getFRRconfig('^vrf red', stop_section='^exit-vrf')
self.assertIn(f' ip route 0.0.0.0/0 {default_gateway} {dhcp_if_client} '\
f'tag 210 {default_distance}', frrconfig)
def test_callback(self, vrf_name, string) -> bool:
tmp = self.getFRRconfig(f'^vrf {vrf_name}', stop_section='^exit-vrf')
return bool(string in tmp)

# We need to wait until DHCP client has started and an IP address has been received
tmp = wait_for(test_callback, self, vrf_name, test_ok_string, timeout=20.0)
self.assertTrue(tmp)

# Change anything in FRR to re-trigger config generation. DHCP route
# must still be present
self.cli_set(['protocols', 'static', 'route', '10.0.0.0/24', 'blackhole'])
self.cli_commit()

frrconfig = self.getFRRconfig('^vrf red', stop_section='^exit-vrf')
self.assertIn(f' ip route 0.0.0.0/0 {default_gateway} {dhcp_if_client} '\
f'tag 210 {default_distance}', frrconfig)
frrconfig = self.getFRRconfig(f'^vrf {vrf_name}', stop_section='^exit-vrf')
self.assertIn(test_ok_string, frrconfig)

self.cli_delete(['interfaces', 'virtual-ethernet'])
self.cli_delete(['service', 'dhcp-server'])
self.cli_delete(['vrf', 'name', vrf_name])

def test_dhcpv6_single_pool(self):
# Prepare the vrf and other options
Expand Down
Loading