Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCU vlan interface test #4834

Merged
merged 4 commits into from
Dec 24, 2021
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
32 changes: 32 additions & 0 deletions tests/generic_config_updater/gu_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import pytest
from jsonpointer import JsonPointer
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until
from tests.common.config_reload import config_reload
Expand Down Expand Up @@ -238,3 +239,34 @@ def rollback_or_reload(duthost, cp=DEFAULT_CHECKPOINT_NAME):
if output['rc'] or "Config rolled back successfull" not in output['stdout']:
config_reload(duthost)
pytest.fail("config rollback failed. Restored by config_reload")

def create_path(tokens):
return JsonPointer.from_parts(tokens).path

def check_show_ip_intf(duthost, intf_name, expected_content_list, unexpected_content_list, is_ipv4=True):
"""Check lo interface status by show command

Sample output:
admin@vlab-01:~$ show ip interfaces | grep -w Vlan1000
Vlan1000 192.168.0.1/21 up/up N/A N/A
admin@vlab-01:~$ show ipv6 interfaces | grep -w Vlan1000
Vlan1000 fc02:1000::1/64 up/up N/A N/A
fe80::5054:ff:feda:c6af%Vlan1000/64 N/A N/A
"""
address_family = "ip" if is_ipv4 else "ipv6"
output = duthost.shell("show {} interfaces | grep -w {} || true".format(address_family, intf_name))

expect_res_success(duthost, output, expected_content_list, unexpected_content_list)

def check_vrf_route_for_intf(duthost, vrf_name, intf_name, is_ipv4=True):
"""Check ip route for specific vrf

Sample output:
admin@vlab-01:~$ show ip route vrf Vrf_01 | grep -w Loopback0
C>* 10.1.0.32/32 is directly connected, Loopback0, 00:00:13
"""
address_family = "ip" if is_ipv4 else "ipv6"
output = duthost.shell("show {} route vrf {} | grep -w {}".format(address_family, vrf_name, intf_name))

pytest_assert(not output['rc'],
"Route not found for {} in vrf {}".format(intf_name, vrf_name))
67 changes: 20 additions & 47 deletions tests/generic_config_updater/test_lo_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import pytest

from tests.common.helpers.assertions import pytest_assert
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure, expect_res_success
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure
from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile
from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload
from tests.generic_config_updater.gu_utils import check_show_ip_intf, check_vrf_route_for_intf

# Test on t0 topo to verify functionality and to choose predefined variable
# "LOOPBACK_INTERFACE": {
Expand Down Expand Up @@ -42,8 +43,8 @@ def setup_env(duthosts, rand_one_dut_hostname):
try:
logger.info("Rolled back to original checkpoint")
rollback_or_reload(duthost)
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32"], ["Vrf"], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128"], ["Vrf"], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], ["Vrf"], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], ["Vrf"], is_ipv4=False)
finally:
delete_checkpoint(duthost)

Expand All @@ -56,21 +57,6 @@ def cleanup_lo_interface_config(duthost, cfg_facts):
pytest_assert(not del_loopback_interface['rc'],
"Loopback interface '{}' is not deleted successfully".format(lo_interface))

def check_show_lo_intf(duthost, lo_intf_name, expected_content_list, unexpected_content_list, ipv4=True):
"""Check lo interface status by show command

Sample output:
admin@vlab-01:~$ show ip interfaces | grep Loopback0
Loopback0 10.1.0.32/32 up/up N/A N/A
admin@vlab-01:~$ show ipv6 interfaces | grep Loopback0
Loopback0 fc00:1::32/128 up/up N/A N/A
fe80::4a3:18ff:fec2:f9e3%Loopback0/64 N/A N/A
"""
address_family = "ip" if ipv4 else "ipv6"
output = duthost.shell("show {} interfaces | grep {} || true".format(address_family, lo_intf_name))

expect_res_success(duthost, output, expected_content_list, unexpected_content_list)

def test_lo_interface_tc1_add_init(duthost, cfg_facts):
""" Clean up orig lo interface and test initial addion of v4 and v6 lo intf

Expand Down Expand Up @@ -102,8 +88,8 @@ def test_lo_interface_tc1_add_init(duthost, cfg_facts):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], is_ipv4=False)

finally:
delete_tmpfile(duthost, tmpfile)
Expand Down Expand Up @@ -139,8 +125,8 @@ def test_lo_interface_tc2_add_duplicate(duthost):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], is_ipv4=False)
finally:
delete_tmpfile(duthost, tmpfile)

Expand Down Expand Up @@ -226,8 +212,8 @@ def test_lo_interface_tc4_replace(duthost):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", ["10.1.0.33/32"], ["10.1.0.32/32"], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::33/128"], ["fc00:1::32/128"], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.33/32"], ["10.1.0.32/32"], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::33/128"], ["fc00:1::32/128"], is_ipv4=False)
finally:
delete_tmpfile(duthost, tmpfile)

Expand All @@ -248,24 +234,11 @@ def test_lo_interface_tc5_remove(duthost):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", [], ["10.1.0.32/32"], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", [], ["fc00:1::32/128"], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", [], ["10.1.0.32/32"], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", [], ["fc00:1::32/128"], is_ipv4=False)
finally:
delete_tmpfile(duthost, tmpfile)

def check_vrf_route_for_lo_intf(duthost, vrf_name, lo_intf_name, ipv4=True):
"""Check ip route for specific vrf

Sample output:
admin@vlab-01:~$ show ip route vrf Vrf_01 | grep Loopback0
C>* 10.1.0.32/32 is directly connected, Loopback0, 00:00:13
"""
address_family = "ip" if ipv4 else "ipv6"
output = duthost.shell("show {} route vrf {} | grep {}".format(address_family, vrf_name, lo_intf_name))

pytest_assert(not output['rc'],
"Route not found for {} in vrf {}".format(lo_intf_name, vrf_name))

def setup_vrf_config(duthost):
"""Create two vrf and bind Loopback0 to Vrf_01

Expand Down Expand Up @@ -300,11 +273,11 @@ def setup_vrf_config(duthost):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_01"], [], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_01"], [], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_01"], [], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_01"], [], is_ipv4=False)

check_vrf_route_for_lo_intf(duthost, "Vrf_01", "Loopback0", ipv4=True)
check_vrf_route_for_lo_intf(duthost, "Vrf_01", "Loopback0", ipv4=False)
check_vrf_route_for_intf(duthost, "Vrf_01", "Loopback0", is_ipv4=True)
check_vrf_route_for_intf(duthost, "Vrf_01", "Loopback0", is_ipv4=False)
finally:
delete_tmpfile(duthost, tmpfile)

Expand Down Expand Up @@ -336,10 +309,10 @@ def test_lo_interface_tc6_vrf_change(duthost):
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
expect_op_success(duthost, output)

check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_02"], [], ipv4=True)
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_02"], [], ipv4=False)
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_02"], [], is_ipv4=True)
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_02"], [], is_ipv4=False)

check_vrf_route_for_lo_intf(duthost, "Vrf_02", "Loopback0", ipv4=True)
check_vrf_route_for_lo_intf(duthost, "Vrf_02", "Loopback0", ipv4=False)
check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=True)
check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=False)
finally:
delete_tmpfile(duthost, tmpfile)
Loading