Skip to content

Commit 7e0d56a

Browse files
[Sub-ports] Code base refactoring of sub-port TCs (sonic-net#7522)
Summary: Changed the scope of TCs' setup and TCs' teardown Moved stress and negative TCs to new test classes Changed approach to running command on the DUT and PTF during setup and teardown of TCs Optimized functions from the helpers module Changed code formatting according to requirements of pre-commit checker What is the motivation for this PR? Reduce execution time of sub_ports TCs How did you do it? Codebase refactoring of sub-port TCs How did you verify/test it? Run sub_port_interfaces tests. Test passed. TCs time duration: ~3000 seconds Any platform specific information? SONiC Software Version: SONiC.master.204903-dirty-20230118.163740 Distribution: Debian 11.6 Kernel: 5.10.0-18-2-amd64 Build commit: d55913a Build date: Wed Jan 18 16:43:37 UTC 2023 ASIC: barefoot Signed-off-by: Oleksandr Kozodoi <oleksandrx.kozodoi@intel.com>
1 parent ad49120 commit 7e0d56a

File tree

6 files changed

+320
-191
lines changed

6 files changed

+320
-191
lines changed

tests/common/plugins/conditional_mark/tests_mark_conditions.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,22 @@ sub_port_interfaces/test_sub_port_interfaces.py::TestSubPorts::test_tunneling_be
916916
conditions:
917917
- "asic_type=='cisco-8000'"
918918

919+
sub_port_interfaces/test_show_subinterface.py::test_subinterface_status[port_in_lag]:
920+
skip:
921+
reason: "Not supported port type"
922+
923+
sub_port_interfaces/test_sub_port_interfaces.py::TestSubPorts::test_untagged_packet_not_routed[port_in_lag] :
924+
skip:
925+
reason: "Not supported port type"
926+
927+
sub_port_interfaces/test_sub_port_interfaces.py::TestSubPorts::test_routing_between_sub_ports_unaffected_by_sub_ports_removal[port_in_lag:
928+
skip:
929+
reason: "Not supported port type"
930+
931+
sub_port_interfaces/test_sub_port_l2_forwarding.py::test_sub_port_l2_forwarding[port_in_lag]:
932+
skip:
933+
reason: "Not supported port type"
934+
919935
#######################################
920936
##### syslog #####
921937
#######################################

tests/sub_port_interfaces/conftest.py

+72-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import sys
34
import ipaddress
45
import time
56
import random
@@ -45,6 +46,10 @@
4546

4647
logger = logging.getLogger(__name__)
4748

49+
if sys.version_info[0] >= 3:
50+
unicode = str
51+
52+
4853
def pytest_addoption(parser):
4954
"""
5055
Adds options to pytest that are used by the sub-ports tests.
@@ -57,31 +62,39 @@ def pytest_addoption(parser):
5762
help="Max numbers of sub-ports for test_max_numbers_of_sub_ports test case",
5863
)
5964

60-
@pytest.fixture(params=['port', 'port_in_lag'])
65+
66+
@pytest.fixture(params=['port', 'port_in_lag'], scope='module')
6167
def port_type(request):
6268
"""Port type to test, could be either port or port-channel."""
6369
return request.param
6470

65-
@pytest.fixture
71+
72+
@pytest.fixture(scope='module')
6673
def acl_rule_cleanup(duthost, tbinfo):
67-
"""Cleanup all the existing DATAACL rules"""
74+
"""
75+
Cleanup all the existing DATAACL rules
76+
"""
6877
if "t0-backend" in tbinfo["topo"]["name"]:
6978
duthost.shell('acl-loader delete')
7079

7180
yield
7281

73-
@pytest.fixture
82+
83+
@pytest.fixture(scope='module')
7484
def modify_acl_table(duthost, tbinfo, port_type, acl_rule_cleanup):
75-
""" Remove the DATAACL table prior to the test and recreate it at the end"""
76-
if "t0-backend" in tbinfo["topo"]["name"] and 'lag' in port_type:
77-
duthost.command('config acl remove table DATAACL')
85+
"""
86+
Remove the DATAACL table prior to the test and recreate it at the end
87+
"""
88+
if "t0-backend" in tbinfo["topo"]["name"] and 'lag' in port_type:
89+
duthost.command('config acl remove table DATAACL')
7890

79-
yield
91+
yield
92+
93+
if "t0-backend" in tbinfo["topo"]["name"] and 'lag' in port_type:
94+
bind_acl_table(duthost, tbinfo)
8095

81-
if "t0-backend" in tbinfo["topo"]["name"] and 'lag' in port_type:
82-
bind_acl_table(duthost, tbinfo)
8396

84-
@pytest.fixture
97+
@pytest.fixture(scope='class')
8598
def define_sub_ports_configuration(request, duthost, ptfhost, ptfadapter, port_type, tbinfo):
8699
"""
87100
Define configuration of sub-ports for TC run
@@ -118,10 +131,10 @@ def define_sub_ports_configuration(request, duthost, ptfhost, ptfadapter, port_t
118131
vlan_ranges_dut = range(20, 60, 10)
119132
vlan_ranges_ptf = range(20, 60, 10)
120133

121-
if 'invalid' in request.node.name:
134+
if 'invalid' in request._pyfuncitem.name:
122135
vlan_ranges_ptf = range(21, 41, 10)
123136

124-
if 'max_numbers' in request.node.name:
137+
if 'max_numbers' in request._pyfuncitem.name:
125138
vlan_ranges_dut = range(11, max_numbers_of_sub_ports + 11)
126139
vlan_ranges_ptf = range(11, max_numbers_of_sub_ports + 11)
127140

@@ -142,7 +155,8 @@ def define_sub_ports_configuration(request, duthost, ptfhost, ptfadapter, port_t
142155
# for normal t0, get_port tries to retrieve test ports from vlan members
143156
# let's enforce same behavior for t0-backend
144157
if "t0-backend" in tbinfo["topo"]["name"]:
145-
config_port_indices, ptf_ports = get_port(duthost, ptfhost, interface_num, port_type, exclude_sub_interface_ports=True)
158+
config_port_indices, ptf_ports = get_port(duthost, ptfhost, interface_num, port_type,
159+
exclude_sub_interface_ports=True)
146160
else:
147161
config_port_indices, ptf_ports = get_port(duthost, ptfhost, interface_num, port_type)
148162

@@ -167,7 +181,7 @@ def define_sub_ports_configuration(request, duthost, ptfhost, ptfadapter, port_t
167181
}
168182

169183

170-
@pytest.fixture
184+
@pytest.fixture(scope='class')
171185
def apply_config_on_the_dut(define_sub_ports_configuration, duthost, reload_dut_config, modify_acl_table):
172186
"""
173187
Apply Sub-ports configuration on the DUT and remove after tests
@@ -202,7 +216,7 @@ def apply_config_on_the_dut(define_sub_ports_configuration, duthost, reload_dut_
202216
yield sub_ports_vars
203217

204218

205-
@pytest.fixture
219+
@pytest.fixture(scope='class')
206220
def apply_config_on_the_ptf(define_sub_ports_configuration, ptfhost, reload_ptf_config):
207221
"""
208222
Apply Sub-ports configuration on the PTF and remove after tests
@@ -219,7 +233,8 @@ def apply_config_on_the_ptf(define_sub_ports_configuration, ptfhost, reload_ptf_
219233

220234

221235
@pytest.fixture(params=['same', 'different'])
222-
def apply_route_config(request, tbinfo, duthost, ptfhost, port_type, define_sub_ports_configuration, apply_config_on_the_dut, apply_config_on_the_ptf):
236+
def apply_route_config(request, tbinfo, duthost, ptfhost, port_type, define_sub_ports_configuration,
237+
apply_config_on_the_dut, apply_config_on_the_ptf):
223238
"""
224239
Apply route configuration on the PTF and remove after tests
225240
@@ -237,6 +252,7 @@ def apply_route_config(request, tbinfo, duthost, ptfhost, port_type, define_sub_
237252
sub_ports = define_sub_ports_configuration['sub_ports']
238253
dut_ports = define_sub_ports_configuration['dut_ports']
239254
sub_ports_keys = sub_ports.copy()
255+
namespaces = {}
240256

241257
for port in dut_ports.values():
242258
if 'same' in request.param:
@@ -262,8 +278,12 @@ def apply_route_config(request, tbinfo, duthost, ptfhost, port_type, define_sub_
262278
sub_ports[next_hop_sub_port]['neighbor_port'],
263279
sub_ports[next_hop_sub_port]['neighbor_ip'])
264280

265-
if 'tunneling' not in request.node.name:
266-
add_static_route_to_ptf(ptfhost, src_port_network, sub_ports[next_hop_sub_port]['ip'], name_of_namespace)
281+
namespaces[name_of_namespace] = (sub_ports[next_hop_sub_port]['neighbor_port'],
282+
sub_ports[next_hop_sub_port]['neighbor_ip'])
283+
284+
if 'tunneling' not in request._pyfuncitem.name:
285+
add_static_route_to_ptf(ptfhost, src_port_network, sub_ports[next_hop_sub_port]['ip'],
286+
name_of_namespace)
267287
add_static_route_to_ptf(ptfhost, dst_port_network, sub_ports[src_port]['ip'])
268288

269289
new_sub_ports[src_port].append((next_hop_sub_port, name_of_namespace))
@@ -284,15 +304,17 @@ def apply_route_config(request, tbinfo, duthost, ptfhost, port_type, define_sub_
284304
sub_port, name_of_namespace = next_hop_sub_port
285305
dst_port_network = ipaddress.ip_network(unicode(sub_ports[sub_port]['ip']), strict=False)
286306

287-
if 'tunneling' not in request.node.name:
307+
if 'tunneling' not in request._pyfuncitem.name:
288308
remove_static_route_from_ptf(ptfhost, src_port_network, sub_ports[sub_port]['ip'], name_of_namespace)
289309
remove_static_route_from_ptf(ptfhost, dst_port_network, sub_ports[src_port]['ip'])
290310

291-
remove_namespace(ptfhost, name_of_namespace)
311+
namespace_member, namespace_member_ip = namespaces[name_of_namespace]
312+
remove_namespace(ptfhost, name_of_namespace, namespace_member, namespace_member_ip)
292313

293314

294315
@pytest.fixture(params=['svi', 'l3'])
295-
def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, define_sub_ports_configuration, apply_config_on_the_dut, apply_config_on_the_ptf):
316+
def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, define_sub_ports_configuration,
317+
apply_config_on_the_dut, apply_config_on_the_ptf):
296318
"""
297319
Apply route configuration on the PTF and remove after tests
298320
@@ -314,13 +336,15 @@ def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, de
314336
dut_ports = define_sub_ports_configuration['dut_ports']
315337
port_type = define_sub_ports_configuration['port_type']
316338
subnet = define_sub_ports_configuration['subnet']
339+
namespaces = {}
317340

318341
# Get additional port for configuration of SVI port or L3 RIF
319342
if 'svi' in request.param:
320343
interface_num = 1
321344
else:
322345
interface_num = 2
323-
dut_ports, ptf_ports = get_port(duthost, ptfhost, interface_num, port_type, dut_ports.values(), exclude_sub_interface_ports=True)
346+
dut_ports, ptf_ports = get_port(duthost, ptfhost, interface_num, port_type, dut_ports.values(),
347+
exclude_sub_interface_ports=True)
324348

325349
# Get additional IP addresses for configuration of RIF on the DUT and PTF
326350
subnet = ipaddress.ip_network(str(subnet.broadcast_address + 1) + u'/24')
@@ -350,16 +374,16 @@ def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, de
350374
add_ip_to_ptf_port(ptfhost, ptf_port, ptf_port_ip)
351375

352376
# Get two random sub-ports which are not part of the selected DUT interface
353-
sub_ports_on_port = random.sample([sub_port for sub_port in sub_ports_keys if dut_port + '.' not in sub_port], 2)
377+
sub_ports_on_port = random.sample([sub_port for sub_port in sub_ports_keys
378+
if dut_port + '.' not in sub_port], 2)
354379

355380
for sub_port in sub_ports_on_port:
356381
sub_ports_keys.pop(sub_port)
357382

358383
port_map[ptf_port] = {'dut_port': dut_port,
359384
'ip': ptf_port_ip,
360385
'neighbor_ip': dut_port_ip,
361-
'dst_ports': []
362-
}
386+
'dst_ports': []}
363387

364388
# Configure static route between selected sub-ports and selected interfaces on the PTF
365389
for next_hop_sub_port in sub_ports_on_port:
@@ -372,6 +396,9 @@ def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, de
372396
sub_ports[next_hop_sub_port]['neighbor_port'],
373397
sub_ports[next_hop_sub_port]['neighbor_ip'])
374398

399+
namespaces[name_of_namespace] = (sub_ports[next_hop_sub_port]['neighbor_port'],
400+
sub_ports[next_hop_sub_port]['neighbor_ip'])
401+
375402
# Add static route from sub-port to selected interface on the PTF
376403
add_static_route_to_ptf(ptfhost, subnet, sub_ports[next_hop_sub_port]['ip'], name_of_namespace)
377404
# Add static route from selected interface to sub-port on the PTF
@@ -398,7 +425,9 @@ def apply_route_config_for_port(request, tbinfo, duthost, ptfhost, port_type, de
398425
dst_port_network = ipaddress.ip_network(unicode(sub_ports[sub_port]['ip']), strict=False)
399426
remove_static_route_from_ptf(ptfhost, src_port_network, sub_ports[sub_port]['ip'], name_of_namespace)
400427
remove_static_route_from_ptf(ptfhost, dst_port_network, next_hop_sub_ports['neighbor_ip'])
401-
remove_namespace(ptfhost, name_of_namespace)
428+
429+
namespace_member, namespace_member_ip = namespaces[name_of_namespace]
430+
remove_namespace(ptfhost, name_of_namespace, namespace_member, namespace_member_ip)
402431

403432
if 'svi' in request.param:
404433
# Remove SVI port from the DUT
@@ -465,7 +494,8 @@ def apply_tunnel_table_to_dut(duthost, apply_route_config):
465494

466495

467496
@pytest.fixture()
468-
def apply_balancing_config(duthost, ptfhost, ptfadapter, define_sub_ports_configuration, apply_config_on_the_dut, apply_config_on_the_ptf, tbinfo):
497+
def apply_balancing_config(duthost, ptfhost, ptfadapter, define_sub_ports_configuration, apply_config_on_the_dut,
498+
apply_config_on_the_ptf, tbinfo):
469499
"""
470500
Apply balancing configuration on the DUT and remove after tests
471501
Args:
@@ -494,7 +524,8 @@ def apply_balancing_config(duthost, ptfhost, ptfadapter, define_sub_ports_config
494524
sub_intf_name = vlan_sub_interface['attachto']
495525
port = sub_intf_name.split(constants.VLAN_SUB_INTERFACE_SEPARATOR)[0]
496526
vlan_id = vlan_sub_interface['vlan']
497-
src_ports.add("eth" + str(mg_facts['minigraph_ptf_indices'][port]) + constants.VLAN_SUB_INTERFACE_SEPARATOR + str(vlan_id))
527+
src_ports.add("eth" + str(mg_facts['minigraph_ptf_indices'][port])
528+
+ constants.VLAN_SUB_INTERFACE_SEPARATOR + str(vlan_id))
498529
src_ports = tuple(src_ports)
499530
else:
500531
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
@@ -532,8 +563,8 @@ def apply_balancing_config(duthost, ptfhost, ptfadapter, define_sub_ports_config
532563
remove_static_route_from_dut(duthost, str(subnet), sub_ports[next_hop_sub_port]['neighbor_ip'])
533564

534565

535-
@pytest.fixture
536-
def reload_dut_config(request, duthost, define_sub_ports_configuration, loganalyzer):
566+
@pytest.fixture(scope='class')
567+
def reload_dut_config(request, duthost, define_sub_ports_configuration, port_type):
537568
"""
538569
DUT's configuration reload on teardown
539570
@@ -543,8 +574,6 @@ def reload_dut_config(request, duthost, define_sub_ports_configuration, loganaly
543574
define_sub_ports_configuration: Dictonary of parameters for configuration DUT
544575
"""
545576
yield
546-
if loganalyzer and loganalyzer[duthost.hostname]:
547-
loganalyzer[duthost.hostname].add_start_ignore_mark()
548577

549578
sub_ports = define_sub_ports_configuration['sub_ports']
550579
dut_ports = define_sub_ports_configuration['dut_ports']
@@ -556,24 +585,24 @@ def reload_dut_config(request, duthost, define_sub_ports_configuration, loganaly
556585

557586
py_assert(check_sub_port(duthost, sub_ports.keys(), True), "Some sub-port were not deleted")
558587

559-
if 'port_in_lag' in request.node.name:
588+
if 'port_in_lag' in port_type:
560589
for lag_port in dut_ports.values():
561590
remove_lag_port(duthost, cfg_facts, lag_port)
562591

563592
duthost.shell('sudo config load -y /etc/sonic/config_db.json')
564593
wait_critical_processes(duthost)
565-
if loganalyzer and loganalyzer[duthost.hostname]:
566-
loganalyzer[duthost.hostname].add_end_ignore_mark()
567594

568-
@pytest.fixture
569-
def reload_ptf_config(request, ptfhost, define_sub_ports_configuration):
595+
596+
@pytest.fixture(scope='class')
597+
def reload_ptf_config(request, ptfhost, define_sub_ports_configuration, port_type):
570598
"""
571599
PTF's configuration reload on teardown
572600
573601
Args:
574602
request: pytest request object
575603
ptfhost: PTF host object
576604
define_sub_ports_configuration: Dictonary of parameters for configuration DUT
605+
port_type: Type of port
577606
"""
578607
yield
579608
sub_ports = define_sub_ports_configuration['sub_ports']
@@ -583,7 +612,7 @@ def reload_ptf_config(request, ptfhost, define_sub_ports_configuration):
583612
if sub_port_info['neighbor_port'] in ptf_port_list:
584613
remove_sub_port_from_ptf(ptfhost, sub_port_info['neighbor_port'], sub_port_info['neighbor_ip'])
585614

586-
if 'port_in_lag' in request.node.name:
615+
if 'port_in_lag' in port_type:
587616
ptf_ports = define_sub_ports_configuration['ptf_ports']
588617
for bond_port, port_name in ptf_ports.items():
589618
if bond_port in ptf_port_list:
@@ -593,7 +622,7 @@ def reload_ptf_config(request, ptfhost, define_sub_ports_configuration):
593622
time.sleep(5)
594623

595624

596-
@pytest.fixture(scope="module", autouse=True)
625+
@pytest.fixture(scope="package", autouse=True)
597626
def teardown_test_class(duthost):
598627
"""
599628
Reload DUT configuration after running of test suite
@@ -604,11 +633,12 @@ def teardown_test_class(duthost):
604633
yield
605634
config_reload(duthost)
606635

636+
607637
@pytest.fixture(autouse=True)
608638
def ignore_expected_loganalyzer_exception(duthost, loganalyzer):
609639
if loganalyzer and loganalyzer[duthost.hostname]:
610640
ignore_regex_list = [
611-
".*ERR teamd[0-9]*#tlm_teamd.*process_add_queue: Can't connect to teamd after.*attempts. LAG 'PortChannel.*'",
612-
".*ERR swss[0-9]*#orchagent.*update: Failed to get port by bridge port ID.*"
641+
".*ERR teamd[0-9]*#tlm_teamd.*process_add_queue: Can't connect to teamd after.*attempts. LAG 'PortChannel.*'",
642+
".*ERR swss[0-9]*#orchagent.*update: Failed to get port by bridge port ID.*"
613643
]
614644
loganalyzer[duthost.hostname].ignore_regex.extend(ignore_regex_list)

0 commit comments

Comments
 (0)