Skip to content

Commit 0cba182

Browse files
authored
[tests/generic_config_updater] improve GCU portchannel test (#5802)
Summary: Improve GCU po test when the initial po interface ip are different What is the motivation for this PR? The test will fail on some t0-topo when the initial po interfaces are not the same as the assumed ones. How did you do it? Change to read po ip from the configuration. How did you verify/test it? Run kvm test.
1 parent f30abf2 commit 0cba182

1 file changed

Lines changed: 62 additions & 41 deletions

File tree

tests/generic_config_updater/test_portchannel_interface.py

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import pytest
3+
import ipaddress
34

45
from tests.common.helpers.assertions import pytest_assert
56
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_op_failure
@@ -29,34 +30,34 @@
2930

3031
logger = logging.getLogger(__name__)
3132

32-
T0_PORTCHANNEL_TABLE = {
33-
"PortChannel101": {
34-
"ip": "10.0.0.56/31",
35-
"ipv6": "fc00::71/126"
36-
},
37-
"PortChannel102": {
38-
"ip": "10.0.0.58/31",
39-
"ipv6": "fc00::75/126"
40-
},
41-
"PortChannel103": {
42-
"ip": "10.0.0.60/31",
43-
"ipv6": "fc00::79/126"
44-
},
45-
"PortChannel104": {
46-
"ip": "10.0.0.62/31",
47-
"ipv6": "fc00::7d/126"
48-
}
49-
}
50-
51-
def check_portchannel_table(duthost):
33+
34+
@pytest.fixture(scope="module")
35+
def portchannel_table(cfg_facts):
36+
def _is_ipv4_address(ip_addr):
37+
return ipaddress.ip_address(ip_addr).version == 4
38+
39+
portchannel_table = {}
40+
for portchannel, ip_addresses in cfg_facts["PORTCHANNEL_INTERFACE"].items():
41+
ips = {}
42+
for ip_address in ip_addresses:
43+
if _is_ipv4_address(ip_address.split("/")[0]):
44+
ips["ip"] = ip_address
45+
else:
46+
ips["ipv6"] = ip_address.lower()
47+
portchannel_table[portchannel] = ips
48+
49+
return portchannel_table
50+
51+
52+
def check_portchannel_table(duthost, portchannel_table):
5253
"""This is to check if portchannel interfaces are the same as t0 initial setup
5354
"""
54-
for portchannel_name, ips in T0_PORTCHANNEL_TABLE.items():
55+
for portchannel_name, ips in portchannel_table.items():
5556
check_show_ip_intf(duthost, portchannel_name, [ips['ip']], [], is_ipv4=True)
5657
check_show_ip_intf(duthost, portchannel_name, [ips['ipv6']], [], is_ipv4=False)
5758

5859
@pytest.fixture(autouse=True)
59-
def setup_env(duthosts, rand_one_dut_hostname):
60+
def setup_env(duthosts, rand_one_dut_hostname, portchannel_table):
6061
"""
6162
Setup/teardown fixture for portchannel interface config
6263
Args:
@@ -71,10 +72,11 @@ def setup_env(duthosts, rand_one_dut_hostname):
7172
try:
7273
logger.info("Rolled back to original checkpoint")
7374
rollback_or_reload(duthost)
74-
check_portchannel_table(duthost)
75+
check_portchannel_table(duthost, portchannel_table)
7576
finally:
7677
delete_checkpoint(duthost)
7778

79+
7880
def test_portchannel_interface_tc1_add_new_portchannel(duthost):
7981
""" Clean up original portchannel intf and apply-patch to default config
8082
@@ -130,18 +132,22 @@ def test_portchannel_interface_tc1_add_new_portchannel(duthost):
130132
finally:
131133
delete_tmpfile(duthost, tmpfile)
132134

133-
def test_portchannel_interface_tc2_add_duplicate(duthost):
135+
def test_portchannel_interface_tc2_add_duplicate(duthost, portchannel_table):
134136
""" Test adding duplicate portchannel interface
135137
"""
138+
dup_ip = portchannel_table["PortChannel101"]["ip"]
139+
dup_ipv6 = portchannel_table["PortChannel101"]["ipv6"]
136140
json_patch = [
137141
{
138142
"op": "add",
139-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|10.0.0.56/31"]),
143+
"path": create_path(["PORTCHANNEL_INTERFACE",
144+
"PortChannel101|{}".format(dup_ip)]),
140145
"value": {}
141146
},
142147
{
143148
"op": "add",
144-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|FC00::71/126"]),
149+
"path": create_path(["PORTCHANNEL_INTERFACE",
150+
"PortChannel101|{}".format(dup_ipv6.upper())]),
145151
"value": {}
146152
}
147153
]
@@ -155,11 +161,12 @@ def test_portchannel_interface_tc2_add_duplicate(duthost):
155161
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
156162
expect_op_success(duthost, output)
157163

158-
check_show_ip_intf(duthost, "PortChannel101", ["10.0.0.56/31"], [], is_ipv4=True)
159-
check_show_ip_intf(duthost, "PortChannel101", ["fc00::71/126"], [], is_ipv4=False)
164+
check_show_ip_intf(duthost, "PortChannel101", [dup_ip], [], is_ipv4=True)
165+
check_show_ip_intf(duthost, "PortChannel101", [dup_ipv6], [], is_ipv4=False)
160166
finally:
161167
delete_tmpfile(duthost, tmpfile)
162168

169+
163170
@pytest.mark.parametrize("op, name, dummy_portchannel_interface_v4, dummy_portchannel_interface_v6", [
164171
("add", "PortChannel101", "10.0.0.256/31", "FC00::71/126"),
165172
("add", "PortChannel101", "10.0.0.56/31", "FC00::xyz/126"),
@@ -200,26 +207,35 @@ def test_portchannel_interface_tc2_xfail(duthost, op, name,
200207
finally:
201208
delete_tmpfile(duthost, tmpfile)
202209

203-
def test_portchannel_interface_tc3_replace(duthost):
210+
211+
def test_portchannel_interface_tc3_replace(duthost, portchannel_table):
204212
""" Test portchannel interface replace ip address
205213
"""
214+
org_ip = portchannel_table["PortChannel101"]["ip"]
215+
org_ipv6 = portchannel_table["PortChannel101"]["ipv6"]
216+
rep_ip = "10.0.0.156/31"
217+
rep_ipv6 = "fc00::171/126"
206218
json_patch = [
207219
{
208220
"op": "remove",
209-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|FC00::71/126"]),
221+
"path": create_path(["PORTCHANNEL_INTERFACE",
222+
"PortChannel101|{}".format(org_ip)]),
210223
},
211224
{
212225
"op": "remove",
213-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|10.0.0.56/31"]),
226+
"path": create_path(["PORTCHANNEL_INTERFACE",
227+
"PortChannel101|{}".format(org_ipv6.upper())]),
214228
},
215229
{
216230
"op": "add",
217-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|10.0.0.156/31"]),
231+
"path": create_path(["PORTCHANNEL_INTERFACE",
232+
"PortChannel101|{}".format(rep_ip)]),
218233
"value": {}
219234
},
220235
{
221236
"op": "add",
222-
"path": create_path(["PORTCHANNEL_INTERFACE", "PortChannel101|FC00::171/126"]),
237+
"path": create_path(["PORTCHANNEL_INTERFACE",
238+
"PortChannel101|{}".format(rep_ipv6)]),
223239
"value": {}
224240
}
225241
]
@@ -233,12 +249,13 @@ def test_portchannel_interface_tc3_replace(duthost):
233249
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
234250
expect_op_success(duthost, output)
235251

236-
check_show_ip_intf(duthost, "PortChannel101", ["10.0.0.156/31"], ["10.0.0.56/31"], is_ipv4=True)
237-
check_show_ip_intf(duthost, "PortChannel101", ["fc00::171/126"], ["fc00::71/126"], is_ipv4=False)
252+
check_show_ip_intf(duthost, "PortChannel101", [rep_ip], [org_ip], is_ipv4=True)
253+
check_show_ip_intf(duthost, "PortChannel101", [rep_ipv6], [org_ipv6], is_ipv4=False)
238254
finally:
239255
delete_tmpfile(duthost, tmpfile)
240256

241-
def test_portchannel_interface_tc4_remove(duthost):
257+
258+
def test_portchannel_interface_tc4_remove(duthost, portchannel_table):
242259
""" Test remove all portchannel intf
243260
"""
244261
json_patch = [
@@ -255,14 +272,15 @@ def test_portchannel_interface_tc4_remove(duthost):
255272
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
256273
expect_op_success(duthost, output)
257274

258-
for portchannel_name, ips in T0_PORTCHANNEL_TABLE.items():
275+
for portchannel_name, ips in portchannel_table.items():
259276
check_show_ip_intf(duthost, portchannel_name, [], [ips['ip']], is_ipv4=True)
260277
check_show_ip_intf(duthost, portchannel_name, [], [ips['ipv6']], is_ipv4=False)
261278
finally:
262279
delete_tmpfile(duthost, tmpfile)
263280

264-
def verify_po_running(duthost):
265-
for portchannel_name in T0_PORTCHANNEL_TABLE:
281+
282+
def verify_po_running(duthost, portchannel_table):
283+
for portchannel_name in portchannel_table:
266284
cmds = 'teamdctl {} state dump | python -c "import sys, json; print(json.load(sys.stdin)[\'runner\'][\'active\'])"'.format(portchannel_name)
267285
output = duthost.shell(cmds, module_ignore_errors=True)
268286

@@ -271,6 +289,7 @@ def verify_po_running(duthost):
271289
"{} is not running correctly."
272290
)
273291

292+
274293
def verify_attr_change(duthost, name, attr, value):
275294
"""
276295
attr:
@@ -302,12 +321,13 @@ def verify_attr_change(duthost, name, attr, value):
302321
"{} {} change failed".format(name, attr)
303322
)
304323

324+
305325
@pytest.mark.parametrize("op, name, attr, value", [
306326
("replace", "PortChannel101", "mtu", "3324"),
307327
("replace", "PortChannel101", "min_links", "2"),
308328
("replace", "PortChannel101", "admin_status", "down")
309329
])
310-
def test_portchannel_interface_tc5_modify_attribute(duthost, op, name, attr, value):
330+
def test_portchannel_interface_tc5_modify_attribute(duthost, op, name, attr, value, portchannel_table):
311331
"""Test PortChannelXXXX attribute change
312332
313333
("replace", "PortChannel101", "mtu", "3324"), mtu change
@@ -331,11 +351,12 @@ def test_portchannel_interface_tc5_modify_attribute(duthost, op, name, attr, val
331351
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
332352
expect_op_success(duthost, output)
333353

334-
verify_po_running(duthost)
354+
verify_po_running(duthost, portchannel_table)
335355
verify_attr_change(duthost, name, attr, value)
336356
finally:
337357
delete_tmpfile(duthost, tmpfile)
338358

359+
339360
def test_portchannel_interface_tc6_incremental_change(duthost):
340361
"""Test PortChannelXXXX incremental change
341362
"""

0 commit comments

Comments
 (0)