Skip to content

Commit 031510b

Browse files
[auto-ts] Updated regex in test_auto_techsupport (#5924)
Summary: In PR - 10433 were added changes that add automatic techsupport invocation in case memory usage is too high. After this PR output of Cli cmd's (show auto-techsupport global, show auto-techsupport-feature, show auto-techsupport history) changed and TC's are failing to parse the output on SONiC images SONiC.master.112803-dirty-20220621.160636 or higher. This PR updates the regex to properly parse the output in both cases (when TC will run on Sonic image that doesn't include changes in 10433 or in case when Sonic image have this changes SONiC.master.112803-dirty-20220621.160636 or higher) What is the motivation for this PR? Update the regex to properly parse the output of cli cmd's on newer SONiC images Signed-off-by: Andrii-Yosafat Lozovyi <[email protected]>
1 parent a6ecc5c commit 031510b

1 file changed

Lines changed: 46 additions & 51 deletions

File tree

tests/show_techsupport/test_auto_techsupport.py

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
import pytest
32
import time
43
import logging
@@ -522,82 +521,78 @@ def add_delete_auto_techsupport_feature(duthost, feature, action=None, state=DEF
522521
def parse_show_auto_techsupport_global(duthost):
523522
"""
524523
Parse output for cmd "show auto-techsupport global"
525-
STATE RATE LIMIT INTERVAL (sec) MAX TECHSUPPORT LIMIT (%) MAX CORE LIMIT (%) SINCE
526-
------- --------------------------- --------------------------- -------------------- ----------
527-
enabled 180 10 5 2 days ago
524+
STATE RATE LIMIT INTERVAL (sec) MAX TECHSUPPORT LIMIT (%) MAX CORE LIMIT (%) AVAILABLE MEM THRESHOLD (%) MIN AVAILABLE MEM (Kb) SINCE
525+
------- --------------------------- --------------------------- -------------------- --------------------------- ---------------------- ------------
526+
enabled 180 10 5 10 200 2 days ago
528527
:param duthost: duthost object
529528
:return: dictionary with parsed result, example: {'state': 'enabled', 'rate_limit_interval': '180',
530-
'max_techsupport_limit': '10', 'max_core_size': '5', 'since': '2 days ago'}
529+
'max_techsupport_limit': '10', 'max_core_size': '5', 'available_mem_thresh': '10',
530+
'min_available_mem': '200', 'since': '2 days ago'}
531531
"""
532532
with allure.step('Parsing "show auto-techsupport global" output'):
533-
regexp = r'(enabled|disabled)\s+(\d+)\s+(\d+.\d+|\d+)\s+(\d+.\d+|\d+)\s+(.*)'
534-
cmd_output = duthost.shell('show auto-techsupport global')['stdout']
535-
state, rate_limit_interval, max_techsupport_limit, max_core_size, since = re.search(regexp, cmd_output).groups()
536-
result_dict = {'state': state, 'rate_limit_interval': rate_limit_interval,
537-
'max_techsupport_limit': max_techsupport_limit, 'max_core_size': max_core_size, 'since': since}
533+
cmd_output = duthost.show_and_parse('show auto-techsupport global')[0]
534+
result_dict = {'state': cmd_output['state'], 'rate_limit_interval': cmd_output['rate limit interval (sec)'],
535+
'max_techsupport_limit': cmd_output['max techsupport limit (%)'], 'max_core_size': cmd_output['max core limit (%)'],
536+
'available_mem_thresh': cmd_output.get('available mem threshold (%)', None), 'min_available_mem': cmd_output.get('min available mem (kb)', None),
537+
'since': cmd_output['since']}
538538
return result_dict
539539

540540

541541
def parse_show_auto_techsupport_feature(duthost):
542542
"""
543543
Parse output for cmd "show auto-techsupport-feature"
544-
FEATURE NAME STATE RATE LIMIT INTERVAL (sec)
545-
-------------- ------- ---------------------------
546-
bgp enabled 600
547-
database enabled 600
548-
dhcp_relay enabled 600
549-
lldp enabled 600
550-
macsec enabled 600
551-
mgmt-framework enabled 600
552-
mux enabled 600
553-
nat enabled 600
554-
pmon enabled 600
555-
radv enabled 600
556-
sflow enabled 600
557-
snmp enabled 600
558-
swss enabled 600
559-
syncd enabled 600
560-
teamd enabled 600
561-
telemetry enabled 600
544+
FEATURE NAME STATE RATE LIMIT INTERVAL (sec) AVAILABLE MEM THRESHOLD (%)
545+
-------------- ------- --------------------------- ---------------------------
546+
bgp enabled 600 10.0
547+
database enabled 600 10.0
548+
dhcp_relay enabled 600 N/A
549+
lldp enabled 600 10.0
550+
macsec enabled 600 N/A
551+
mgmt-framework enabled 600 10.0
552+
mux enabled 600 10.0
553+
nat enabled 600 10.0
554+
pmon enabled 600 10.0
555+
radv enabled 600 10.0
556+
sflow enabled 600 10.0
557+
snmp enabled 600 10.0
558+
swss enabled 600 10.0
559+
syncd enabled 600 10.0
560+
teamd enabled 600 10.0
561+
telemetry enabled 600 10.0
562562
:param duthost: duthost object
563-
:return: dictionary with parsed result, example: {'bgp': {'status': 'enabled', 'rate_limit_interval': '600'},
563+
:return: dictionary with parsed result, example: {'bgp': {'status': 'enabled', 'rate_limit_interval': '600', 'available_mem_thresh': 10.0},
564564
'database': {'status': 'enabled', 'rate_limit_interval': '600'}, ...}
565565
"""
566566
with allure.step('Parsing "show auto-techsupport-feature" output'):
567567
result_dict = {}
568-
regexp = r'(\w+-\w+|\w+)\s+(enabled|disabled)\s+(\d+)'
569-
cmd_output = duthost.shell('show auto-techsupport-feature')['stdout']
570-
571-
name_index = 0
572-
state_index = 1
573-
rate_limit_index = 2
574-
for feature in re.findall(regexp, cmd_output):
575-
result_dict[feature[name_index]] = {'status': feature[state_index],
576-
'rate_limit_interval': feature[rate_limit_index]}
568+
cmd_output = duthost.show_and_parse('show auto-techsupport-feature')
569+
for feature in cmd_output:
570+
feature_name = feature['feature name']
571+
result_dict[feature_name] = {'status': feature['state'],
572+
'rate_limit_interval': feature['rate limit interval (sec)'],
573+
'available_mem_thresh': feature.get('available mem threshold (%)', None)}
577574
return result_dict
578575

579576

580577
def parse_show_auto_techsupport_history(duthost):
581578
"""
582579
Parse output for cmd "show auto-techsupport history"
583-
TECHSUPPORT DUMP TRIGGERED BY CORE DUMP
584-
---------------------------------------- -------------- -----------------------------
585-
sonic_dump_r-lionfish-16_20210901_221402 bgp bgpcfgd.1630534439.55.core.gz
580+
TECHSUPPORT DUMP TRIGGERED BY EVENT TYPE CORE DUMP
581+
---------------------------------------- -------------- ------------ ----------------
582+
sonic_dump_r-lionfish-16_20210901_221402 bgp core bgpcfgd.1630534439.55.core.gz
586583
:param duthost: duthost object
587584
:return: dictionary with parsed result, example: {'sonic_dump_r-lionfish-16_20210901_221402':
588-
{'triggered_by': 'bgp', 'core_dump': 'bgpcfgd.1630534439.55.core.gz'}, ...}
585+
{'triggered_by': 'bgp', 'event_type': 'core', 'core_dump': 'bgpcfgd.1630534439.55.core.gz'}, ...}
589586
"""
590587
with allure.step('Parsing "show auto-techsupport history" output'):
591588
result_dict = {}
592-
regexp = r'(sonic_dump_.*)\s+(\w+|\w+\W\w+)\s+(\w+\.\d+\.\d+\.core\.gz)'
593-
cmd_output = duthost.shell('show auto-techsupport history')['stdout']
594-
595-
dump_name_index = 0
596-
triggered_by_index = 1
597-
core_dump_index = 2
598-
for dump in re.findall(regexp, cmd_output):
599-
result_dict[dump[dump_name_index].strip()] = {'triggered_by': dump[triggered_by_index],
600-
'core_dump': dump[core_dump_index]}
589+
cmd_output = duthost.show_and_parse('show auto-techsupport history')
590+
if cmd_output:
591+
for dump in cmd_output:
592+
dump_name = dump['techsupport dump']
593+
result_dict[dump_name] = {'triggered_by': dump['triggered by'],
594+
'event_type': dump.get('event type', None),
595+
'core_dump': dump['core dump']}
601596
return result_dict
602597

603598

0 commit comments

Comments
 (0)