-
Notifications
You must be signed in to change notification settings - Fork 732
/
test_iface_namingmode.py
1143 lines (955 loc) · 52.1 KB
/
test_iface_namingmode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import logging
import pytest
import re
import ipaddress
from tests.common.devices.base import AnsibleHostBase
from tests.common.utilities import wait, wait_until
from netaddr import IPAddress
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.sonic_db import redis_get_keys
pytestmark = [
pytest.mark.topology('any', 't1-multi-asic')
]
logger = logging.getLogger(__name__)
PORT_TOGGLE_TIMEOUT = 30
QUEUE_COUNTERS_RE_FMT = r'{}\s+[U|M]C|ALL\d\s+\S+\s+\S+\s+\S+\s+\S+'
def skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname):
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
if duthost.is_multi_asic:
pytest.skip('CLI command not supported')
@pytest.fixture(scope='module', autouse=True)
def setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, tbinfo):
"""
Sets up all the parameters needed for the interface naming mode tests
Args:
duthost: AnsiblecHost instance for DUT
Yields:
setup_info: dictionary containing port alias mappings, list of
working interfaces, minigraph facts
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
hwsku = duthost.facts['hwsku']
minigraph_facts = duthost.get_extended_minigraph_facts(tbinfo)
port_alias_facts = duthost.port_alias(hwsku=hwsku, include_internal=False)['ansible_facts']
up_ports = list(minigraph_facts['minigraph_ports'].keys())
default_interfaces = list(port_alias_facts['port_name_map'].keys())
minigraph_portchannels = minigraph_facts['minigraph_portchannels']
port_speed_facts = port_alias_facts['port_speed']
if not port_speed_facts:
all_vars = duthost.host.options['variable_manager'].get_vars()
iface_speed = all_vars['hostvars'][duthost.hostname]['iface_speed']
iface_speed = str(iface_speed)
port_speed_facts = {_: iface_speed for _ in
list(port_alias_facts['port_alias_map'].keys())}
port_alias = list()
port_name_map = dict()
port_alias_map = dict()
port_speed = dict()
# Change port alias names to make it common for all platforms
logger.info('Updating common port alias names in redis db')
for i, item in enumerate(default_interfaces):
port_alias_new = 'TestAlias{}'.format(i)
asic_index = duthost.get_port_asic_instance(item).asic_index
port_alias_old = port_alias_facts['port_name_map'][item]
port_alias.append(port_alias_new)
port_name_map[item] = port_alias_new
port_alias_map[port_alias_new] = item
port_speed[port_alias_new] = port_speed_facts[port_alias_old]
# sonic-db-cli command
db_cmd = 'sudo {} CONFIG_DB HSET "PORT|{}" alias {}'\
.format(duthost.asic_instance(asic_index).sonic_db_cli,
item,
port_alias_new)
# Update port alias name in redis db
duthost.command(db_cmd)
upport_alias_list = [port_name_map[item] for item in up_ports]
portchannel_members = [member for portchannel in list(minigraph_portchannels.values())
for member in portchannel['members']]
physical_interfaces = [item for item in up_ports if item not in portchannel_members]
setup_info = {
'default_interfaces': default_interfaces,
'minigraph_facts': minigraph_facts,
'physical_interfaces': physical_interfaces,
'port_alias': port_alias,
'port_name_map': port_name_map,
'port_alias_map': port_alias_map,
'port_speed': port_speed,
'up_ports': up_ports,
'upport_alias_list': upport_alias_list
}
yield setup_info
logger.info('Reverting the port alias name in redis db to the actual values')
for item in default_interfaces:
asic_index = duthost.get_port_asic_instance(item).asic_index
port_alias_old = port_alias_facts['port_name_map'][item]
db_cmd = 'sudo {} CONFIG_DB HSET "PORT|{}" alias {}'\
.format(duthost.asic_instance(asic_index).sonic_db_cli,
item,
port_alias_old)
duthost.command(db_cmd)
@pytest.fixture(scope='module', params=['alias', 'default'])
def setup_config_mode(ansible_adhoc, duthosts, enum_rand_one_per_hwsku_frontend_hostname, request):
"""
Creates a guest user and configures the interface naming mode
Args:
ansible_adhoc: Fixture provided by the pytest-ansible package
duthost: AnsibleHost instance for DUT
request: request parameters for setup_config_mode fixture
Yields:
dutHostGuest: AnsibleHost instance for DUT with user as 'guest'
mode: Interface naming mode to be configured
ifmode: Current interface naming mode present in the DUT
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
mode = request.param
logger.info('Creating a guest user')
duthost.user(name='guest', groups='sudo', state='present', shell='/bin/bash')
duthost.shell('echo guest:guest | sudo chpasswd')
logger.info('Configuring the interface naming mode as {} for the guest user'.format(mode))
dutHostGuest = AnsibleHostBase(ansible_adhoc, duthost.hostname, become_user='guest')
dutHostGuest.shell('sudo config interface_naming_mode {}'.format(mode))
ifmode = dutHostGuest.shell('cat /home/guest/.bashrc | grep SONIC_CLI_IFACE_MODE')['stdout'].split('=')[-1]
naming_mode = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show interfaces naming_mode'.format(ifmode))['stdout']
# If the correct mode is not set in .bashrc, all test cases will fail.
# So return Error from this fixture itself.
if (ifmode != mode) or (naming_mode != mode):
logger.info('Removing the created guest user')
duthost.user(name='guest', groups='sudo', state='absent', shell='/bin/bash', remove='yes')
pytest.fail('Interface naming mode in .bashrc "{}", returned by show interfaces naming_mode "{}" \
does not the match the configured naming mode "{}"'.format(ifmode, naming_mode, mode))
yield dutHostGuest, mode, ifmode
logger.info('Removing the created guest user')
duthost.user(name='guest', groups='sudo', state='absent', shell='/bin/bash', remove='yes')
@pytest.fixture(scope='module')
def sample_intf(setup, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
"""
Selects and returns the alias, name and native speed of the test interface
Args:
setup: Fixture defined in this module
Returns:
sample_intf: a dictionary containing the alias, name and native
speed of the test interface
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
minigraph_interfaces = setup['minigraph_facts']['minigraph_interfaces']
interface_info = dict()
interface_info['ip'] = None
if setup['physical_interfaces']:
interface = sorted(setup['physical_interfaces'])[0]
nvidia_platform_support_400G_and_above_list = ["x86_64-nvidia_sn5600-r0"]
if duthost.facts['platform'] in nvidia_platform_support_400G_and_above_list:
interface = select_interface_for_mellnaox_device(setup, duthost)
asic_index = duthost.get_port_asic_instance(interface).asic_index
interface_info['is_portchannel_member'] = False
for item in minigraph_interfaces:
if (item['attachto'] == interface) and (IPAddress(item['addr']).version == 4):
interface_info['ip'] = item['subnet']
break
else:
interface = sorted(setup['up_ports'])[0]
asic_index = duthost.get_port_asic_instance(interface).asic_index
interface_info['is_portchannel_member'] = True
interface_info['default'] = interface
interface_info['asic_index'] = asic_index
interface_info['alias'] = setup['port_name_map'][interface]
interface_info['native_speed'] = setup['port_speed'][interface_info['alias']]
interface_info['cli_ns_option'] = duthost.asic_instance(asic_index).cli_ns_option
return interface_info
def select_interface_for_mellnaox_device(setup, duthost):
"""
For nvidia device,the headroom size is related to the speed and cable length.
When platform is x86_64-nvidia_sn5600-r0 and above,we need to choose interface whose cable length is 40m not 300m.
Because this platform supports speeds of 400G and above, if we use 300m cable length
it will exceed the headroom limit and cause some log errors like below:
ERR syncd#SDK: [COS_SB.ERR] Failed to verify max headroom for port 0x100f1, error:No More Resources
ERR syncd#SDK: [COS_SB.ERR] Failed to verify validate of the required configuration, error: No More Resources
ERR syncd#SDK: [SAI_BUFFER.ERR] mlnx_sai_buffer.c[6161]- mlnx_sai_buffer_configure_reserved_buffers:
Failed to configure reserved buffers. logical port:100f1, number of items:1 sx_status:5, message No More Resources
ERR syncd#SDK: [SAI_BUFFER.ERR] mlnx_sai_buffer.c[4083]- mlnx_sai_buffer_apply_buffer_to_pg:
Error applying buffer settings to port
ERR syncd#SDK: [SAI_BUFFER.ERR] mlnx_sai_buffer.c[1318]- pg_profile_set:
Failed to apply buffer profile for port index 60 pg index 3
ERR syncd#SDK: [SAI_UTILS.ERR] mlnx_sai_utils.c[2130]- sai_set_attribute: Failed to set the attribute.
ERR syncd#SDK: :- sendApiResponse:
api SAI_COMMON_API_SET failed in syncd mode: SAI_STATUS_INSUFFICIENT_RESOURCES
ERR syncd#SDK: :- processQuadEvent: VID: oid:0x1a000000000266 RID: oid:0x3c0003001a
ERR syncd#SDK: :- processQuadEvent: attr: SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE: oid:0x19000000000b43
ERR swss#orchagent: :- processPriorityGroup: Failed to set port:Ethernet0 pg:3 buffer profile attribute, status:-4
"""
selected_interface = ''
interface_cable_length_list = duthost.shell('redis-cli -n 4 hgetall "CABLE_LENGTH|AZURE" ')['stdout_lines']
support_cable_length_list = ["40m", "5m"]
for intf in setup['physical_interfaces']:
if intf in interface_cable_length_list:
if interface_cable_length_list[interface_cable_length_list.index(intf) + 1] in support_cable_length_list:
selected_interface = intf
break
if not selected_interface:
pytest.skip("Skipping test due to not find interface with cable length is 40m or 5m")
return selected_interface
#############################################################
# START OF TESTS #
#############################################################
# Tests to be run in all topologies
class TestShowLLDP():
@pytest.fixture(scope="class")
def lldp_interfaces(self, setup):
"""
Returns the alias and names of the lldp interfaces
Args:
setup: Fixture defined in this module
Returns:
lldp_interfaces: dictionary containing lists of aliases and
names of the lldp interfaces
"""
minigraph_neighbors = setup['minigraph_facts']['minigraph_neighbors']
lldp_interfaces = dict()
lldp_interfaces['alias'] = list()
lldp_interfaces['interface'] = list()
for key, value in list(minigraph_neighbors.items()):
if 'server' not in value['name'].lower():
lldp_interfaces['alias'].append(setup['port_name_map'][key])
lldp_interfaces['interface'].append(key)
if len(lldp_interfaces['alias']) == 0:
pytest.skip('No lldp interfaces found')
return lldp_interfaces
def test_show_lldp_table(self, setup, setup_config_mode, lldp_interfaces):
"""
Checks whether 'show lldp table' lists the interface name as per
the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_neighbors = setup['minigraph_facts']['minigraph_neighbors']
lldp_table = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show lldp table'.format(ifmode))['stdout']
logger.info('lldp_table:\n{}'.format(lldp_table))
if mode == 'alias':
for alias in lldp_interfaces['alias']:
assert re.search(r'{}.*\s+{}'
.format(alias, minigraph_neighbors[setup['port_alias_map'][alias]]['name']),
lldp_table) is not None
elif mode == 'default':
for intf in lldp_interfaces['interface']:
assert re.search(r'{}.*\s+{}'.format(intf, minigraph_neighbors[intf]['name']),
lldp_table) is not None
def test_show_lldp_neighbor(self, setup, setup_config_mode, lldp_interfaces):
"""
Checks whether 'show lldp neighbor <port>' lists the lldp neighbor
information corresponding to the test interface when its interface
alias/name is provied according to the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = lldp_interfaces['alias'][0] if (mode == 'alias') else lldp_interfaces['interface'][0]
minigraph_neighbors = setup['minigraph_facts']['minigraph_neighbors']
lldp_neighbor = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show lldp neighbor {}'.format(ifmode, test_intf))['stdout']
logger.info('lldp_neighbor:\n{}'.format(lldp_neighbor))
if mode == 'alias':
assert re.search(r'Interface:\s+{},\svia:\sLLDP,'.format(test_intf), lldp_neighbor) is not None
assert re.search(r'SysName:\s+{}'.format(minigraph_neighbors[setup['port_alias_map'][test_intf]]['name']),
lldp_neighbor) is not None
elif mode == 'default':
assert re.search(r'Interface:\s+{},\svia:\sLLDP,'.format(test_intf), lldp_neighbor) is not None
assert re.search(r'SysName:\s+{}'.format(minigraph_neighbors[test_intf]['name']), lldp_neighbor) is not None
class TestShowInterfaces():
def test_show_interfaces_counter(self, setup, setup_config_mode):
"""
Checks whether 'show interfaces counter' lists the interface names
as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
regex_int = re.compile(r'(\S+)(\d+)')
interfaces = list()
show_intf_counter = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show interfaces counter'.format(ifmode))
logger.info('show_intf_counter:\n{}'.format(show_intf_counter['stdout']))
for line in show_intf_counter['stdout_lines']:
line = line.strip()
if regex_int.match(line):
interfaces.append(regex_int.match(line).group(0))
assert (len(interfaces) > 0)
for item in interfaces:
if mode == 'alias':
assert item in setup['port_alias']
elif mode == 'default':
assert item in setup['default_interfaces']
def test_show_interfaces_description(self, setup_config_mode, sample_intf):
"""
Checks whether 'show interfaces description <port>' lists the
information corresponding to the test interface when its interface
alias/name is provided according to the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
interface = sample_intf['default']
interface_alias = sample_intf['alias']
show_intf_desc = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show interfaces description {} \
| sed -n "/^ *Eth/ p"'.format(ifmode, test_intf))['stdout']
logger.info('show_intf_desc:\n{}'.format(show_intf_desc))
assert re.search(r'{}.*{}'.format(interface, interface_alias), show_intf_desc) is not None
def test_show_interfaces_status(self, setup_config_mode, sample_intf):
"""
Checks whether 'show interfaces status <port>' lists the information
corresponding to the test interface when its interface alias/name
is provided according to the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
interface = sample_intf['default']
interface_alias = sample_intf['alias']
regex_int = re.compile(r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+[\w\/]+\s+([\w\/]+)\s+(\w+)\s+(\w+)\s+(\w+)')
show_intf_status = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={0} show interfaces status {1} | grep -w {1}'
.format(ifmode, test_intf))
logger.info('show_intf_status:\n{}'.format(show_intf_status['stdout']))
line = show_intf_status['stdout'].strip()
if regex_int.match(line) and interface == regex_int.match(line).group(1):
name = regex_int.match(line).group(1)
alias = regex_int.match(line).group(4)
assert (name == interface) and (alias == interface_alias)
def test_show_interfaces_portchannel(self, setup, setup_config_mode):
"""
Checks whether 'show interfaces portchannel' lists the member
interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_portchannels = setup['minigraph_facts']['minigraph_portchannels']
if not minigraph_portchannels:
pytest.skip('No portchannels found')
int_po = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show interfaces portchannel'.format(ifmode))['stdout']
logger.info('int_po:\n{}'.format(int_po))
for key, value in list(minigraph_portchannels.items()):
if mode == 'alias':
assert re.search(r'{}\s+LACP\(A\)\(Up\).*{}'.format(key, setup['port_name_map'][value['members'][0]]),
int_po) is not None
elif mode == 'default':
assert re.search(r'{}\s+LACP\(A\)\(Up\).*{}'.format(key, value['members'][0]), int_po) is not None
def test_show_pfc_counters(setup, setup_config_mode):
"""
Checks whether 'show pfc counters' lists the interface names as
per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
pfc_rx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters | sed -n "/Port Rx/,/^$/p"'
.format(ifmode))['stdout']
pfc_tx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters | sed -n "/Port Tx/,/^$/p"'
.format(ifmode))['stdout']
logger.info('pfc_rx:\n{}'.format(pfc_rx))
logger.info('pfc_tx:\n{}'.format(pfc_tx))
pfc_rx_names = [x.strip().split(' ')[0] for x in pfc_rx.splitlines()]
pfc_tx_names = [x.strip().split(' ')[0] for x in pfc_tx.splitlines()]
logger.info('pfc_rx_names:\n{}'.format(pfc_rx_names))
logger.info('pfc_tx_names:\n{}'.format(pfc_tx_names))
if mode == 'alias':
for alias in setup['port_alias']:
assert (alias in pfc_rx_names) and (alias in pfc_tx_names)
assert (setup['port_alias_map'][alias] not in pfc_rx_names) and \
(setup['port_alias_map'][alias] not in pfc_tx_names)
elif mode == 'default':
for intf in setup['default_interfaces']:
assert (intf in pfc_rx_names) and (intf in pfc_tx_names)
assert (setup['port_name_map'][intf] not in pfc_rx_names) and \
(setup['port_name_map'][intf] not in pfc_tx_names)
class TestShowPriorityGroup():
@pytest.fixture(scope="class", autouse=True)
def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname)
def test_show_priority_group_persistent_watermark_headroom(self, setup, setup_config_mode):
"""
Checks whether 'show priority-group persistent-watermark headroom'
lists the interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_pg = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show priority-group persistent-watermark headroom'
.format(ifmode))['stdout']
logger.info('show_pg:\n{}'.format(show_pg))
if mode == 'alias':
for alias in setup['upport_alias_list']:
assert re.search(r'{}.*'.format(alias), show_pg) is not None
elif mode == 'default':
for intf in setup['up_ports']:
assert re.search(r'{}.*'.format(intf), show_pg) is not None
def test_show_priority_group_persistent_watermark_shared(self, setup, setup_config_mode):
"""
Checks whether 'show priority-group persistent-watermark shared'
lists the interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_pg = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show priority-group persistent-watermark shared'
.format(ifmode))['stdout']
logger.info('show_pg:\n{}'.format(show_pg))
if mode == 'alias':
for alias in setup['upport_alias_list']:
assert re.search(r'{}.*'.format(alias), show_pg) is not None
elif mode == 'default':
for intf in setup['up_ports']:
assert re.search(r'{}.*'.format(intf), show_pg) is not None
def test_show_priority_group_watermark_headroom(self, setup, setup_config_mode):
"""
Checks whether 'show priority-group watermark headroom' lists the
interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_pg = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show priority-group watermark headroom'
.format(ifmode))['stdout']
logger.info('show_pg:\n{}'.format(show_pg))
if mode == 'alias':
for alias in setup['upport_alias_list']:
assert re.search(r'{}.*'.format(alias), show_pg) is not None
elif mode == 'default':
for intf in setup['up_ports']:
assert re.search(r'{}.*'.format(intf), show_pg) is not None
def test_show_priority_group_watermark_shared(self, setup, setup_config_mode):
"""
Checks whether 'show priority-group watermark shared' lists the
interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_pg = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show priority-group watermark shared'
.format(ifmode))['stdout']
logger.info('show_pg:\n{}'.format(show_pg))
if mode == 'alias':
for alias in setup['upport_alias_list']:
assert re.search(r'{}.*'.format(alias), show_pg) is not None
elif mode == 'default':
for intf in setup['up_ports']:
assert re.search(r'{}.*'.format(intf), show_pg) is not None
class TestShowQueue():
@pytest.fixture(scope="class", autouse=True)
def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
skip_test_for_multi_asic(
duthosts, enum_rand_one_per_hwsku_frontend_hostname)
def test_show_queue_counters(self, setup, setup_config_mode, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
"""
Checks whether 'show queue counters' lists the interface names as
per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
queue_counter = dutHostGuest.shell(
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters | grep "UC\|MC\|ALL"'.format(ifmode))['stdout']
logger.info('queue_counter:\n{}'.format(queue_counter))
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
buffer_queue_keys = redis_get_keys(duthost, 'CONFIG_DB', 'BUFFER_QUEUE|*')
interfaces = set()
for key in buffer_queue_keys:
try:
fields = key.split("|")
# The format of BUFFER_QUEUE entries on VOQ chassis is
# 'BUFFER_QUEUE|<host name>|<asic-name>|Ethernet32|0-2'
# where 'host name' could be any host in the chassis, including those from other
# cards. This test only cares about local interfaces, so we can filter out the rest
if duthost.facts['switch_type'] == 'voq':
hostname = fields[1]
if hostname != duthost.hostname:
continue
# The interface name is always the last but one field in the BUFFER_QUEUE entry key
interfaces.add(fields[-2])
except IndexError:
pass
# For the test to be valid, we should have at least one interface selected
assert (len(interfaces) > 0)
intfsChecked = 0
if mode == 'alias':
for intf in interfaces:
alias = setup['port_name_map'][intf]
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(alias),
queue_counter) is not None) \
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_alias_map'][alias]),
queue_counter) is None)
intfsChecked += 1
elif mode == 'default':
for intf in interfaces:
if intf not in setup['port_name_map']:
continue
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(intf),
queue_counter) is not None) \
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_name_map'][intf]),
queue_counter) is None)
intfsChecked += 1
# At least one interface should have been checked to have a valid result
assert (intfsChecked > 0)
def test_show_queue_counters_interface(self, setup_config_mode, sample_intf):
"""
Check whether the interface name is present in output in the format
corresponding to the mode set
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
queue_counter_intf = dutHostGuest.shell(
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters {} | grep "UC\|MC\|ALL"'.format(ifmode, test_intf))
logger.info('queue_counter_intf:\n{}'.format(queue_counter_intf))
for i in range(len(queue_counter_intf['stdout_lines'])):
assert re.search(r'{}\s+[U|M]C|ALL{}\s+\S+\s+\S+\s+\S+\s+\S+'
.format(test_intf, i), queue_counter_intf['stdout']) is not None
def test_show_queue_persistent_watermark_multicast(self, setup, setup_config_mode):
"""
Checks whether 'show queue persistent-watermark multicast' lists
the interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_queue_wm_mcast = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show queue persistent-watermark multicast'.format(ifmode))['stdout']
logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast))
if show_queue_wm_mcast != "Object map from the COUNTERS_DB is empty "\
"because the multicast queues are not configured in the CONFIG_DB!":
if mode == 'alias':
for alias in setup['port_alias']:
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
elif mode == 'default':
for intf in setup['default_interfaces']:
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
def test_show_queue_persistent_watermark_unicast(self, setup, setup_config_mode):
"""
Checks whether 'show queue persistent-watermark unicast' lists
the interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_queue_wm_ucast = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show queue persistent-watermark unicast'.format(ifmode))['stdout']
logger.info('show_queue_wm_ucast:\n{}'.format(show_queue_wm_ucast))
if mode == 'alias':
for alias in setup['port_alias']:
assert re.search(r'{}'.format(alias), show_queue_wm_ucast) is not None
elif mode == 'default':
for intf in setup['default_interfaces']:
assert re.search(r'{}'.format(intf), show_queue_wm_ucast) is not None
def test_show_queue_watermark_multicast(self, setup, setup_config_mode):
"""
Checks whether 'show queue watermark multicast' lists the
interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_queue_wm_mcast = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show queue watermark multicast'.format(ifmode))['stdout']
logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast))
if show_queue_wm_mcast != ("Object map from the COUNTERS_DB is empty because the multicast queues "
"are not configured in the CONFIG_DB!"):
if mode == 'alias':
for alias in setup['port_alias']:
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
elif mode == 'default':
for intf in setup['default_interfaces']:
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
def test_show_queue_watermark_unicast(self, setup, setup_config_mode):
"""
Checks whether 'show queue watermark unicast' lists the
interface names as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
show_queue_wm_ucast = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show queue watermark unicast'.format(ifmode))['stdout']
logger.info('show_queue_wm_ucast:\n{}'.format(show_queue_wm_ucast))
if mode == 'alias':
for alias in setup['port_alias']:
assert re.search(r'{}'.format(alias), show_queue_wm_ucast) is not None
elif mode == 'default':
for intf in setup['default_interfaces']:
assert re.search(r'{}'.format(intf), show_queue_wm_ucast) is not None
# Tests to be run in t0/m0 topology
class TestShowVlan():
@pytest.fixture(scope="class", autouse=True)
def setup_check_topo(self, tbinfo):
if tbinfo['topo']['type'] not in ['t0', 'm0']:
pytest.skip('Unsupported topology')
@pytest.fixture()
def setup_vlan(self, setup_config_mode):
"""
Creates VLAN 100 for testing and cleans it up on completion
Args:
setup_config_mode: Fixture defined in this module
Yields:
None
"""
dutHostGuest, mode, ifmode = setup_config_mode
logger.info('Creating a test vlan 100')
res = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config vlan add 100'
.format(ifmode), module_ignore_errors=True)
if res["rc"] != 0 and "Restart service dhcp_relay failed with error" not in res["stderr"]:
pytest.fail("Add vlan failed in setup")
yield
logger.info('Cleaning up the test vlan 100')
res = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config vlan del 100'
.format(ifmode), module_ignore_errors=True)
if res["rc"] != 0 and "Restart service dhcp_relay failed with error" not in res["stderr"]:
pytest.fail("Del vlan failed in teardown")
def test_show_vlan_brief(self, setup, setup_config_mode):
"""
Checks whether 'show vlan brief' lists the interface names
as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_vlans = setup['minigraph_facts']['minigraph_vlans']
show_vlan_brief = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} sudo show vlan brief'.format(ifmode))['stdout']
logger.info('show_vlan_brief:\n{}'.format(show_vlan_brief))
vlan_type = minigraph_vlans['Vlan1000'].get('type', 'untagged').lower()
for item in minigraph_vlans['Vlan1000']['members']:
if mode == 'alias':
assert re.search(r'{}.*{}'
.format(setup['port_name_map'][item], vlan_type), show_vlan_brief) is not None
elif mode == 'default':
assert re.search(r'{}.*{}'.format(item, vlan_type), show_vlan_brief) is not None
@pytest.mark.usefixtures('setup_vlan')
def test_show_vlan_config(self, setup, setup_config_mode):
"""
Checks whether 'config vlan member add <vlan> <intf>' adds
the test interface when its interface alias/name is provided
as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_vlans = setup['minigraph_facts']['minigraph_vlans']
vlan_interface = minigraph_vlans[list(minigraph_vlans.keys())[0]]['members'][0]
vlan_interface_alias = setup['port_name_map'][vlan_interface]
v_intf = vlan_interface_alias if (mode == 'alias') else vlan_interface
dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} sudo config vlan member add 100 {}'.format(ifmode, v_intf))
show_vlan = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} sudo show vlan config | grep -w "Vlan100"'.format(ifmode))['stdout']
logger.info('show_vlan:\n{}'.format(show_vlan))
dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} sudo config vlan member del 100 {}'.format(ifmode, v_intf))
assert v_intf in show_vlan
# Tests to be run in t1 topology
class TestConfigInterface():
@pytest.fixture(scope="class", autouse=True)
def setup_check_topo(self, tbinfo):
if tbinfo['topo']['type'] not in ['t2', 't1']:
pytest.skip('Unsupported topology')
@pytest.fixture(scope='class', autouse=True)
def reset_config_interface(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, sample_intf):
"""
Resets the test interface's configurations on completion of
all tests in the enclosing test class.
Args:
duthost: AnsibleHost instance for DUT
test_intf: Fixture defined in this module
Yields:
None
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
interface = sample_intf['default']
interface_ip = sample_intf['ip']
native_speed = sample_intf['native_speed']
cli_ns_option = sample_intf['cli_ns_option']
yield
if interface_ip is not None:
duthost.shell('config interface {} ip add {} {}'.format(cli_ns_option, interface, interface_ip))
duthost.shell('config interface {} startup {}'.format(cli_ns_option, interface))
duthost.shell('config interface {} speed {} {}'.format(cli_ns_option, interface, native_speed))
def test_config_interface_ip(self, setup_config_mode, sample_intf):
"""
Checks whether 'config interface ip add/remove <intf> <ip>'
adds/removes the ip on the test interface when its interface
alias/name is provided as per the configured naming mode
"""
if sample_intf['ip'] is None:
pytest.skip('No L3 physical interface present')
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
test_intf_ip = sample_intf['ip']
cli_ns_option = sample_intf['cli_ns_option']
out = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config interface {} ip remove {} {}'.format(
ifmode, cli_ns_option, test_intf, test_intf_ip))
if out['rc'] != 0:
pytest.fail()
wait(3)
show_ip_intf = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show ip interface'.format(ifmode))['stdout']
logger.info('show_ip_intf:\n{}'.format(show_ip_intf))
assert re.search(r'{}\s+{}'.format(test_intf, test_intf_ip), show_ip_intf) is None
out = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config interface {} ip add {} {}'.format(
ifmode, cli_ns_option, test_intf, test_intf_ip))
if out['rc'] != 0:
pytest.fail()
wait(3)
show_ip_intf = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show ip interface'.format(ifmode))['stdout']
logger.info('show_ip_intf:\n{}'.format(show_ip_intf))
assert re.search(r'{}\s+{}'.format(test_intf, test_intf_ip), show_ip_intf) is not None
def test_config_interface_state(self, setup_config_mode, sample_intf):
"""
Checks whether 'config interface startup/shutdown <intf>'
changes the admin state of the test interface to up/down when
its interface alias/name is provided as per the configured
naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
interface = sample_intf['default']
cli_ns_option = sample_intf['cli_ns_option']
regex_int = re.compile(r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+[\w\/]+\s+([\w\/]+)\s+(\w+)\s+(\w+)\s+(\w+)')
def _port_status(expected_state):
admin_state = ""
show_intf_status = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={0} show interfaces status {1} | grep -w {1}'.format(ifmode, test_intf))
logger.info('show_intf_status:\n{}'.format(show_intf_status['stdout']))
line = show_intf_status['stdout'].strip()
if regex_int.match(line) and interface == regex_int.match(line).group(1):
admin_state = regex_int.match(line).group(7)
return admin_state == expected_state
out = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config interface {} shutdown {}'.format(
ifmode, cli_ns_option, test_intf))
if out['rc'] != 0:
pytest.fail()
pytest_assert(wait_until(PORT_TOGGLE_TIMEOUT, 2, 0, _port_status, 'down'),
"Interface {} should be admin down".format(test_intf))
out = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config interface {} startup {}'.format(
ifmode, cli_ns_option, test_intf))
if out['rc'] != 0:
pytest.fail()
pytest_assert(wait_until(PORT_TOGGLE_TIMEOUT, 2, 0, _port_status, 'up'),
"Interface {} should be admin up".format(test_intf))
def test_config_interface_speed(self, setup_config_mode, sample_intf,
duthosts, enum_rand_one_per_hwsku_frontend_hostname):
"""
Checks whether 'config interface speed <intf> <speed>' sets
speed of the test interface when its interface alias/name is
provided as per the configured naming mode
"""
dutHostGuest, mode, ifmode = setup_config_mode
test_intf = sample_intf[mode]
interface = sample_intf['default']
native_speed = sample_intf['native_speed']
cli_ns_option = sample_intf['cli_ns_option']
asic_index = sample_intf['asic_index']
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
# Get supported speeds for interface
supported_speeds = duthost.get_supported_speeds(interface)
# Remove native speed from supported speeds
if supported_speeds is not None:
supported_speeds.remove(native_speed)
# Set speed to configure
configure_speed = supported_speeds[0] if supported_speeds else native_speed
out = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} sudo config interface {} speed {} {}'
.format(ifmode, cli_ns_option, test_intf, configure_speed))
if out['rc'] != 0:
pytest.fail()
db_cmd = 'sudo {} CONFIG_DB HGET "PORT|{}" speed'\
.format(duthost.asic_instance(asic_index).sonic_db_cli,
interface)
speed = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} {}'.format(ifmode, db_cmd))['stdout']
logger.info('speed: {}'.format(speed))
assert speed == configure_speed
out = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo config interface {} speed {} {}'.format(
ifmode, cli_ns_option, test_intf, native_speed))
if out['rc'] != 0:
pytest.fail()
speed = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} {}'.format(ifmode, db_cmd))['stdout']
logger.info('speed: {}'.format(speed))
assert speed == native_speed
def test_show_acl_table(setup, setup_config_mode, tbinfo):
"""
Checks whether 'show acl table DATAACL' lists the interface names
as per the configured naming mode
"""
if tbinfo['topo']['type'] not in ['t1', 't2']:
pytest.skip('Unsupported topology')
if not setup['physical_interfaces']:
pytest.skip('No non-portchannel member interface present')
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_acls = setup['minigraph_facts']['minigraph_acls']
if 'DataAcl' not in minigraph_acls:
pytest.skip("Skipping test since DATAACL table is not supported on this platform")
acl_table = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show acl table DATAACL'.format(ifmode))['stdout']
logger.info('acl_table:\n{}'.format(acl_table))
for item in minigraph_acls['DataAcl']:
if item in setup['physical_interfaces']:
if mode == 'alias':
assert setup['port_name_map'][item] in acl_table
elif mode == 'default':
assert item in acl_table
def test_show_interfaces_neighbor_expected(setup, setup_config_mode, tbinfo, duthosts,
enum_rand_one_per_hwsku_frontend_hostname):
"""
Checks whether 'show interfaces neighbor expected' lists the
interface names as per the configured naming mode
"""
if tbinfo['topo']['type'] not in ['t1', 't2']:
pytest.skip('Unsupported topology')
skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname)
dutHostGuest, mode, ifmode = setup_config_mode
minigraph_neighbors = setup['minigraph_facts']['minigraph_neighbors']
show_int_neighbor = dutHostGuest.shell(
'SONIC_CLI_IFACE_MODE={} show interfaces neighbor expected'.format(ifmode))['stdout']
logger.info('show_int_neighbor:\n{}'.format(show_int_neighbor))
for key, value in list(minigraph_neighbors.items()):
if 'server' not in value['name'].lower():
if mode == 'alias':
assert re.search(r'{}\s+{}'
.format(setup['port_name_map'][key], value['name']), show_int_neighbor) is not None
elif mode == 'default':
assert re.search(r'{}\s+{}'.format(key, value['name']), show_int_neighbor) is not None
class TestNeighbors():
@pytest.fixture(scope="class", autouse=True)
def setup_check_topo(self, setup, tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
if tbinfo['topo']['type'] not in ['t2', 't1']:
pytest.skip('Unsupported topology')
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
if duthost.is_multi_asic:
pytest.skip("CLI not supported")
if not setup['physical_interfaces']:
pytest.skip('No non-portchannel member interface present')
def test_show_arp(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, setup, setup_config_mode):
"""
Checks whether 'show arp' lists the interface names as per the
configured naming mode
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
dutHostGuest, mode, ifmode = setup_config_mode
arptable = duthost.switch_arptable()['ansible_facts']['arptable']
minigraph_portchannels = setup['minigraph_facts']['minigraph_portchannels']
arp_output = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show arp'.format(ifmode))['stdout']
logger.info('arp_output:\n{}'.format(arp_output))
for item in arptable['v4']:
# To ignore Midplane interface, added check on what is being set in setup fixture
if (arptable['v4'][item]['interface'] in setup['port_name_map']) \
and (arptable['v4'][item]['interface'] not in minigraph_portchannels):
if mode == 'alias':
assert re.search(r'{}.*\s+{}'
.format(item, setup['port_name_map'][arptable['v4'][item]['interface']]),
arp_output) is not None
elif mode == 'default':
assert re.search(r'{}.*\s+{}'
.format(item, arptable['v4'][item]['interface']), arp_output) is not None
def test_show_ndp(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, setup, setup_config_mode):
"""
Checks whether 'show ndp' lists the interface names as per the
configured naming mode
"""
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
dutHostGuest, mode, ifmode = setup_config_mode
arptable = duthost.switch_arptable()['ansible_facts']['arptable']
minigraph_portchannels = setup['minigraph_facts']['minigraph_portchannels']
ndp_output = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show ndp'.format(ifmode))['stdout']
logger.info('ndp:\n{}'.format(ndp_output))
for addr, detail in list(arptable['v6'].items()):
if (
detail['macaddress'] != 'None' and
detail['interface'] in setup['port_name_map'] and
detail['interface'] not in minigraph_portchannels
):
if mode == 'alias':
assert re.search(r'{}.*\s+{}'
.format(addr, setup['port_name_map'][detail['interface']]),
ndp_output) is not None
elif mode == 'default':
assert re.search(r'{}.*\s+{}'.format(addr, detail['interface']), ndp_output) is not None