Skip to content

Commit

Permalink
Showtech sonic mgmt framework: Add Management Framework functionality…
Browse files Browse the repository at this point in the history
… for "show tech-support" (#7816)

Provide the changes required for supporting the "show-techsupport" command via the SONiC Management Framework front end mechanisms (CLI, REST, and gNOI). The Management Framework functionality implemented by this PR improves on the the capabilities currently provided by the SONiC Click CLI interface via the "show techsupport" command by providing the following additional features:

- User-friendly "help" information describing command syntax details for CLI invocation.
- Ability to invoke the command via REST and gNOI mechanisms.

Unit test results are attached to this PR.
  • Loading branch information
kerry-meyer authored Jan 10, 2022
1 parent 8e6b194 commit 9b795db
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/sonic-host-services/host_modules/showtech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Show techsupport command handler"""

import host_service
import subprocess
import re

MOD_NAME = 'showtech'

class Showtech(host_service.HostModule):
"""DBus endpoint that executes the "show techsupport" command
"""
@host_service.method(host_service.bus_name(MOD_NAME), in_signature='s', out_signature='is')
def info(self, date):

ERROR_TAR_FAILED = 5
ERROR_PROCFS_SAVE_FAILED = 6
ERROR_INVALID_ARGUMENT = 10

err_dict = {ERROR_INVALID_ARGUMENT: 'Invalid input: Incorrect DateTime format',
ERROR_TAR_FAILED: 'Failure saving information into compressed output file',
ERROR_PROCFS_SAVE_FAILED: 'Saving of process information failed'}

cmd = ['/usr/local/bin/generate_dump']
if date:
cmd.append("-s")
cmd.append(date)

try:
result = subprocess.run(cmd, capture_output=True, text=True,
check=True)

except subprocess.CalledProcessError as err:
errmsg = err_dict.get(err.returncode)

if errmsg is None:
output = 'Error: Failure code {:-5}'.format(err.returncode)
else:
output = errmsg

print("%Error: Host side: Failed: " + str(err.returncode))
return err.returncode, output

output_file_match = re.search('\/var\/.*dump.*\.gz', result.stdout)
output_filename = output_file_match.group()
return result.returncode, output_filename

def register():
"""Return the class name"""
return Showtech, MOD_NAME

0 comments on commit 9b795db

Please sign in to comment.