Skip to content

Commit 832d317

Browse files
committed
move show_ip_intf and vrf_route to gu_util; add rollback for vlan intf test
1 parent e6349f7 commit 832d317

3 files changed

Lines changed: 77 additions & 52 deletions

File tree

tests/generic_config_updater/gu_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,31 @@ def rollback_or_reload(duthost, cp=DEFAULT_CHECKPOINT_NAME):
238238
if output['rc'] or "Config rolled back successfull" not in output['stdout']:
239239
config_reload(duthost)
240240
pytest.fail("config rollback failed. Restored by config_reload")
241+
242+
def check_show_ip_intf(duthost, intf_name, expected_content_list, unexpected_content_list, is_ipv4=True):
243+
"""Check lo interface status by show command
244+
245+
Sample output:
246+
admin@vlab-01:~$ show ip interfaces | grep Vlan1000
247+
Vlan1000 192.168.0.1/21 up/up N/A N/A
248+
admin@vlab-01:~$ show ipv6 interfaces | grep Vlan1000
249+
Vlan1000 fc02:1000::1/64 up/up N/A N/A
250+
fe80::5054:ff:feda:c6af%Vlan1000/64 N/A N/A
251+
"""
252+
address_family = "ip" if is_ipv4 else "ipv6"
253+
output = duthost.shell("show {} interfaces | grep {} || true".format(address_family, intf_name))
254+
255+
expect_res_success(duthost, output, expected_content_list, unexpected_content_list)
256+
257+
def check_vrf_route_for_intf(duthost, vrf_name, intf_name, is_ipv4=True):
258+
"""Check ip route for specific vrf
259+
260+
Sample output:
261+
admin@vlab-01:~$ show ip route vrf Vrf_01 | grep Loopback0
262+
C>* 10.1.0.32/32 is directly connected, Loopback0, 00:00:13
263+
"""
264+
address_family = "ip" if is_ipv4 else "ipv6"
265+
output = duthost.shell("show {} route vrf {} | grep {}".format(address_family, vrf_name, intf_name))
266+
267+
pytest_assert(not output['rc'],
268+
"Route not found for {} in vrf {}".format(intf_name, vrf_name))

tests/generic_config_updater/test_lo_interface.py

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import pytest
33

44
from tests.common.helpers.assertions import pytest_assert
5-
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure, expect_res_success
5+
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure
66
from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile
77
from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload
8+
from tests.generic_config_updater.gu_utils import check_show_ip_intf, check_vrf_route_for_intf
89

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

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

59-
def check_show_lo_intf(duthost, lo_intf_name, expected_content_list, unexpected_content_list, ipv4=True):
60-
"""Check lo interface status by show command
61-
62-
Sample output:
63-
admin@vlab-01:~$ show ip interfaces | grep Loopback0
64-
Loopback0 10.1.0.32/32 up/up N/A N/A
65-
admin@vlab-01:~$ show ipv6 interfaces | grep Loopback0
66-
Loopback0 fc00:1::32/128 up/up N/A N/A
67-
fe80::4a3:18ff:fec2:f9e3%Loopback0/64 N/A N/A
68-
"""
69-
address_family = "ip" if ipv4 else "ipv6"
70-
output = duthost.shell("show {} interfaces | grep {} || true".format(address_family, lo_intf_name))
71-
72-
expect_res_success(duthost, output, expected_content_list, unexpected_content_list)
73-
7460
def test_lo_interface_tc1_add_init(duthost, cfg_facts):
7561
""" Clean up orig lo interface and test initial addion of v4 and v6 lo intf
7662
@@ -102,8 +88,8 @@ def test_lo_interface_tc1_add_init(duthost, cfg_facts):
10288
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
10389
expect_op_success(duthost, output)
10490

105-
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], ipv4=True)
106-
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], ipv4=False)
91+
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], is_ipv4=True)
92+
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], is_ipv4=False)
10793

10894
finally:
10995
delete_tmpfile(duthost, tmpfile)
@@ -139,8 +125,8 @@ def test_lo_interface_tc2_add_duplicate(duthost):
139125
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
140126
expect_op_success(duthost, output)
141127

142-
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], ipv4=True)
143-
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], ipv4=False)
128+
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32"], [], is_ipv4=True)
129+
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128"], [], is_ipv4=False)
144130
finally:
145131
delete_tmpfile(duthost, tmpfile)
146132

@@ -226,8 +212,8 @@ def test_lo_interface_tc4_replace(duthost):
226212
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
227213
expect_op_success(duthost, output)
228214

229-
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.33/32"], ["10.1.0.32/32"], ipv4=True)
230-
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::33/128"], ["fc00:1::32/128"], ipv4=False)
215+
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.33/32"], ["10.1.0.32/32"], is_ipv4=True)
216+
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::33/128"], ["fc00:1::32/128"], is_ipv4=False)
231217
finally:
232218
delete_tmpfile(duthost, tmpfile)
233219

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

251-
check_show_lo_intf(duthost, "Loopback0", [], ["10.1.0.32/32"], ipv4=True)
252-
check_show_lo_intf(duthost, "Loopback0", [], ["fc00:1::32/128"], ipv4=False)
237+
check_show_ip_intf(duthost, "Loopback0", [], ["10.1.0.32/32"], is_ipv4=True)
238+
check_show_ip_intf(duthost, "Loopback0", [], ["fc00:1::32/128"], is_ipv4=False)
253239
finally:
254240
delete_tmpfile(duthost, tmpfile)
255241

256-
def check_vrf_route_for_lo_intf(duthost, vrf_name, lo_intf_name, ipv4=True):
257-
"""Check ip route for specific vrf
258-
259-
Sample output:
260-
admin@vlab-01:~$ show ip route vrf Vrf_01 | grep Loopback0
261-
C>* 10.1.0.32/32 is directly connected, Loopback0, 00:00:13
262-
"""
263-
address_family = "ip" if ipv4 else "ipv6"
264-
output = duthost.shell("show {} route vrf {} | grep {}".format(address_family, vrf_name, lo_intf_name))
265-
266-
pytest_assert(not output['rc'],
267-
"Route not found for {} in vrf {}".format(lo_intf_name, vrf_name))
268-
269242
def setup_vrf_config(duthost):
270243
"""Create two vrf and bind Loopback0 to Vrf_01
271244
@@ -300,11 +273,11 @@ def setup_vrf_config(duthost):
300273
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
301274
expect_op_success(duthost, output)
302275

303-
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_01"], [], ipv4=True)
304-
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_01"], [], ipv4=False)
276+
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_01"], [], is_ipv4=True)
277+
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_01"], [], is_ipv4=False)
305278

306-
check_vrf_route_for_lo_intf(duthost, "Vrf_01", "Loopback0", ipv4=True)
307-
check_vrf_route_for_lo_intf(duthost, "Vrf_01", "Loopback0", ipv4=False)
279+
check_vrf_route_for_intf(duthost, "Vrf_01", "Loopback0", is_ipv4=True)
280+
check_vrf_route_for_intf(duthost, "Vrf_01", "Loopback0", is_ipv4=False)
308281
finally:
309282
delete_tmpfile(duthost, tmpfile)
310283

@@ -336,10 +309,10 @@ def test_lo_interface_tc6_vrf_change(duthost):
336309
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
337310
expect_op_success(duthost, output)
338311

339-
check_show_lo_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_02"], [], ipv4=True)
340-
check_show_lo_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_02"], [], ipv4=False)
312+
check_show_ip_intf(duthost, "Loopback0", ["10.1.0.32/32", "Vrf_02"], [], is_ipv4=True)
313+
check_show_ip_intf(duthost, "Loopback0", ["fc00:1::32/128", "Vrf_02"], [], is_ipv4=False)
341314

342-
check_vrf_route_for_lo_intf(duthost, "Vrf_02", "Loopback0", ipv4=True)
343-
check_vrf_route_for_lo_intf(duthost, "Vrf_02", "Loopback0", ipv4=False)
315+
check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=True)
316+
check_vrf_route_for_intf(duthost, "Vrf_02", "Loopback0", is_ipv4=False)
344317
finally:
345318
delete_tmpfile(duthost, tmpfile)

tests/generic_config_updater/test_vlan_interface.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
22
import pytest
33

4-
from tests.common.helpers.assertions import pytest_assert
5-
from tests.common.config_reload import config_reload
64
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure
75
from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile
8-
6+
from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload
7+
from tests.generic_config_updater.gu_utils import check_show_ip_intf
98
# Test on t0 topo to verify functionality and to choose predefined variable
109
# "VLAN_INTERFACE": {
1110
# "Vlan1000": {},
@@ -27,11 +26,17 @@ def cleanup_test_env(duthosts, rand_one_dut_hostname):
2726
rand_selected_dut: The fixture returns a randomly selected DuT.
2827
"""
2928
duthost = duthosts[rand_one_dut_hostname]
29+
create_checkpoint(duthost)
3030

3131
yield
3232

33-
logger.info("Restoring config_db.json")
34-
config_reload(duthost)
33+
try:
34+
logger.info("Rolled back to original checkpoint")
35+
rollback_or_reload(duthost)
36+
check_show_ip_intf(duthost, "Vlan1000", ["192.168.0.1/21"], [], is_ipv4=True)
37+
check_show_ip_intf(duthost, "Vlan1000", ["fc02:1000::1/64"], [], is_ipv4=False)
38+
finally:
39+
delete_checkpoint(duthost)
3540

3641
def test_vlan_interface_tc1_add_duplicate(duthost):
3742
""" Add duplicate v4 and v6 lo intf to config
@@ -64,6 +69,9 @@ def test_vlan_interface_tc1_add_duplicate(duthost):
6469
try:
6570
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
6671
expect_op_success(duthost, output)
72+
73+
check_show_ip_intf(duthost, "Vlan1000", ["192.168.0.1/21"], [], is_ipv4=True)
74+
check_show_ip_intf(duthost, "Vlan1000", ["fc02:1000::1/64"], [], is_ipv4=False)
6775
finally:
6876
delete_tmpfile(duthost, tmpfile)
6977

@@ -133,6 +141,13 @@ def test_vlan_interface_tc3_add_new(duthost):
133141
"Vlan2000|192.168.8.1/21": {},
134142
"Vlan2000|fc02:2000::1/64": {}
135143
}
144+
145+
admin@vlab-01:~/vlan$ show ip interfaces | grep Vlan2000
146+
Vlan2000 192.168.8.1/21 up/up N/A N/A
147+
admin@vlab-01:~/vlan$ show ipv6 interfaces | grep Vlan2000
148+
Vlan2000 fc02:2000::1/64 up/up N/A N/A
149+
fe80::5054:ff:feda:c6af%Vlan2000/64 N/A N/A
150+
136151
"""
137152
json_patch = [
138153
{
@@ -165,6 +180,9 @@ def test_vlan_interface_tc3_add_new(duthost):
165180
try:
166181
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
167182
expect_op_success(duthost, output)
183+
184+
check_show_ip_intf(duthost, "Vlan2000", ["192.168.8.1/21"], [], is_ipv4=True)
185+
check_show_ip_intf(duthost, "Vlan2000", ["fc02:2000::1/64"], [], is_ipv4=False)
168186
finally:
169187
delete_tmpfile(duthost, tmpfile)
170188

@@ -205,6 +223,9 @@ def test_vlan_interface_tc4_replace(duthost):
205223
try:
206224
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
207225
expect_op_success(duthost, output)
226+
227+
check_show_ip_intf(duthost, "Vlan1000", ["192.168.0.2/21"], ["192.168.0.1/21"], is_ipv4=True)
228+
check_show_ip_intf(duthost, "Vlan1000", ["fc02:1000::2/64"], ["fc02:1000::1/64"], is_ipv4=False)
208229
finally:
209230
delete_tmpfile(duthost, tmpfile)
210231

@@ -224,6 +245,9 @@ def test_vlan_interface_tc5_remove(duthost):
224245
try:
225246
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
226247
expect_op_success(duthost, output)
248+
249+
check_show_ip_intf(duthost, "Vlan1000", [], ["192.168.0.1/21"], is_ipv4=True)
250+
check_show_ip_intf(duthost, "Vlan1000", [], ["fc02:1000::1/64"], is_ipv4=False)
227251
finally:
228252
delete_tmpfile(duthost, tmpfile)
229253

0 commit comments

Comments
 (0)