From 70f6746f2ce6cadfbcd588cd1130dc93bd9c064d Mon Sep 17 00:00:00 2001 From: kerry-meyer Date: Fri, 14 May 2021 23:45:42 -0700 Subject: [PATCH 1/7] Provide initial files for SONiC Community mgmt-framework Showtech --- .../host_modules/showtech.py | 56 +++++++++++++++++++ src/sonic-mgmt-common | 2 +- src/sonic-mgmt-framework | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/sonic-host-services/host_modules/showtech.py diff --git a/src/sonic-host-services/host_modules/showtech.py b/src/sonic-host-services/host_modules/showtech.py new file mode 100644 index 00000000000..758034c7e9f --- /dev/null +++ b/src/sonic-host-services/host_modules/showtech.py @@ -0,0 +1,56 @@ +"""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'} + + print("Host side: Running show techsupport") + cmd = ['/usr/bin/generate_dump'] + if date: + cmd.append("-s") + cmd.append(date) + + try: + rc = 0 + output = subprocess.check_output(cmd) + + except subprocess.CalledProcessError as err: + rc = err.returncode + errmsg = err_dict.get(rc) + + if errmsg is None: + output = 'Error: Failure code {:-5}'.format(rc) + else: + output = errmsg + + print("%Error: Host side: Failed: " + str(rc)) + return rc, output + + output_string = output.decode("utf-8") + output_file_match = re.search('\/var\/.*dump.*\.gz', output_string) + if output_file_match is not None: + output_filename = output_file_match.group() + else: + output_filename = "" + return rc, output_filename + +def register(): + """Return the class name""" + return Showtech, MOD_NAME + diff --git a/src/sonic-mgmt-common b/src/sonic-mgmt-common index 86c11081258..6f643d54a4d 160000 --- a/src/sonic-mgmt-common +++ b/src/sonic-mgmt-common @@ -1 +1 @@ -Subproject commit 86c110812583d0132d6504a1e74eb0337f521fde +Subproject commit 6f643d54a4d4ed3b0c5f5ba0a47a717fb6256c12 diff --git a/src/sonic-mgmt-framework b/src/sonic-mgmt-framework index 3c3384cec8d..8e71331b34b 160000 --- a/src/sonic-mgmt-framework +++ b/src/sonic-mgmt-framework @@ -1 +1 @@ -Subproject commit 3c3384cec8d15e493e6889bff6361a5a280a8811 +Subproject commit 8e71331b34bd6ccc451df64e441a1ce5acfcee27 From 63b2ed063ce01128de1c3455b31f29511c8bad17 Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Mon, 7 Jun 2021 21:32:13 +0000 Subject: [PATCH 2/7] Showtech for SONiC Community Management Framework: Fix incompatibilities Provide changes needed for the Dell Enterprise version of this feature to make it compatible with the SONiC Community code base. --- rules/config | 2 +- src/sonic-host-services/host_modules/showtech.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rules/config b/rules/config index b45ce215280..4316076c204 100644 --- a/rules/config +++ b/rules/config @@ -131,7 +131,7 @@ INCLUDE_MGMT_FRAMEWORK = y # ENABLE_HOST_SERVICE_ON_START - enable sonic-host-server for mgmt-framework and/or # telemetry containers to access host functionality by default -ENABLE_HOST_SERVICE_ON_START = n +ENABLE_HOST_SERVICE_ON_START = y # INCLUDE_RESTAPI - build docker-sonic-restapi for configuring the switch using REST APIs INCLUDE_RESTAPI = n diff --git a/src/sonic-host-services/host_modules/showtech.py b/src/sonic-host-services/host_modules/showtech.py index 758034c7e9f..98399c34ccc 100644 --- a/src/sonic-host-services/host_modules/showtech.py +++ b/src/sonic-host-services/host_modules/showtech.py @@ -20,8 +20,7 @@ def info(self, date): ERROR_TAR_FAILED: 'Failure saving information into compressed output file', ERROR_PROCFS_SAVE_FAILED: 'Saving of process information failed'} - print("Host side: Running show techsupport") - cmd = ['/usr/bin/generate_dump'] + cmd = ['/usr/local/bin/generate_dump'] if date: cmd.append("-s") cmd.append(date) From 2a07cd805f96053af8beb692e7f29e2e00b86ca6 Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Wed, 9 Jun 2021 05:29:59 +0000 Subject: [PATCH 3/7] Showtech sonic mgmt framework: Code review changes Provide changes to address code review comments: - Invoke the generate_dump script using subprocess.run instead of subprocess.check_output. - Use output encoding in the subprocess.run call to eliminate post-execution decoding of text. - Delete unnecessary pattern matching of output for the "success" case. --- src/sonic-host-services/host_modules/showtech.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/sonic-host-services/host_modules/showtech.py b/src/sonic-host-services/host_modules/showtech.py index 98399c34ccc..39304bc4b2b 100644 --- a/src/sonic-host-services/host_modules/showtech.py +++ b/src/sonic-host-services/host_modules/showtech.py @@ -27,7 +27,8 @@ def info(self, date): try: rc = 0 - output = subprocess.check_output(cmd) + result = subprocess.run(cmd, capture_output=True, text=True, + check=True) except subprocess.CalledProcessError as err: rc = err.returncode @@ -41,13 +42,7 @@ def info(self, date): print("%Error: Host side: Failed: " + str(rc)) return rc, output - output_string = output.decode("utf-8") - output_file_match = re.search('\/var\/.*dump.*\.gz', output_string) - if output_file_match is not None: - output_filename = output_file_match.group() - else: - output_filename = "" - return rc, output_filename + return rc, result.stdout def register(): """Return the class name""" From aa13f7063719c0f31fd7367c70f4590b55ce8e3a Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Sat, 12 Jun 2021 00:07:26 +0000 Subject: [PATCH 4/7] Showtech sonic mgmt framework: Additional code review and REST fixes - Address a remaining PR code review comment by directly using the "returncode" value provided by "subprocess" execution. - Add filtering of output to extract only the output filename. (This eliminates extraneous output that could otherwise be seen in some non-error cases when invoking "show-techsupport" via the REST API or gNOI.) --- src/sonic-host-services/host_modules/showtech.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sonic-host-services/host_modules/showtech.py b/src/sonic-host-services/host_modules/showtech.py index 39304bc4b2b..2b603d4f52d 100644 --- a/src/sonic-host-services/host_modules/showtech.py +++ b/src/sonic-host-services/host_modules/showtech.py @@ -26,23 +26,23 @@ def info(self, date): cmd.append(date) try: - rc = 0 result = subprocess.run(cmd, capture_output=True, text=True, check=True) except subprocess.CalledProcessError as err: - rc = err.returncode - errmsg = err_dict.get(rc) + errmsg = err_dict.get(err.returncode) if errmsg is None: - output = 'Error: Failure code {:-5}'.format(rc) + output = 'Error: Failure code {:-5}'.format(err.returncode) else: output = errmsg - print("%Error: Host side: Failed: " + str(rc)) - return rc, output + print("%Error: Host side: Failed: " + str(err.returncode)) + return err.returncode, output - return rc, result.stdout + 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""" From 852c67ae8d9ed5f377d7bde831a0bf2f784a182d Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Fri, 18 Jun 2021 21:33:42 +0000 Subject: [PATCH 5/7] Resolve merge conflicts for merge to latest on 06/18/2021 --- src/sonic-frr/frr | 2 +- src/sonic-mgmt-common | 2 +- src/sonic-mgmt-framework | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-frr/frr b/src/sonic-frr/frr index df7ab485bde..88351c8f6df 160000 --- a/src/sonic-frr/frr +++ b/src/sonic-frr/frr @@ -1 +1 @@ -Subproject commit df7ab485bde1a511f131f7ad6b70cb43c48c8e6d +Subproject commit 88351c8f6df5450e9098f773813738f62abb2f5e diff --git a/src/sonic-mgmt-common b/src/sonic-mgmt-common index 6f643d54a4d..06a82da2764 160000 --- a/src/sonic-mgmt-common +++ b/src/sonic-mgmt-common @@ -1 +1 @@ -Subproject commit 6f643d54a4d4ed3b0c5f5ba0a47a717fb6256c12 +Subproject commit 06a82da27643b1dded1ec783aada549a64d27d1c diff --git a/src/sonic-mgmt-framework b/src/sonic-mgmt-framework index 8e71331b34b..879a1e9e91b 160000 --- a/src/sonic-mgmt-framework +++ b/src/sonic-mgmt-framework @@ -1 +1 @@ -Subproject commit 8e71331b34bd6ccc451df64e441a1ce5acfcee27 +Subproject commit 879a1e9e91b68abed68e77013b3797d6ec01842c From 5fd929238bfdbaa3cd9f07012bd837df13ec2463 Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Thu, 24 Jun 2021 21:16:40 +0000 Subject: [PATCH 6/7] Remove incorrect submodules from the PR The following submodules were inadvertently added to this PR and need to be removed from the PR: - src/sonic-mgmt-common and src/sonic-mgmt-framework: These submodules were added prematurely. A separate commit (or new PR) will need to be done for them after the pending PRs for both submodules have been merged to the Azure "master" branch. - src/sonic-frr/frr: Added accidentally; no relevance for this PR. --- src/sonic-frr/frr | 2 +- src/sonic-mgmt-common | 2 +- src/sonic-mgmt-framework | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-frr/frr b/src/sonic-frr/frr index 88351c8f6df..df7ab485bde 160000 --- a/src/sonic-frr/frr +++ b/src/sonic-frr/frr @@ -1 +1 @@ -Subproject commit 88351c8f6df5450e9098f773813738f62abb2f5e +Subproject commit df7ab485bde1a511f131f7ad6b70cb43c48c8e6d diff --git a/src/sonic-mgmt-common b/src/sonic-mgmt-common index 06a82da2764..86c11081258 160000 --- a/src/sonic-mgmt-common +++ b/src/sonic-mgmt-common @@ -1 +1 @@ -Subproject commit 06a82da27643b1dded1ec783aada549a64d27d1c +Subproject commit 86c110812583d0132d6504a1e74eb0337f521fde diff --git a/src/sonic-mgmt-framework b/src/sonic-mgmt-framework index 879a1e9e91b..3c3384cec8d 160000 --- a/src/sonic-mgmt-framework +++ b/src/sonic-mgmt-framework @@ -1 +1 @@ -Subproject commit 879a1e9e91b68abed68e77013b3797d6ec01842c +Subproject commit 3c3384cec8d15e493e6889bff6361a5a280a8811 From f9bf1bfdea6ad1e9721b8b22346a2d5069f10c94 Mon Sep 17 00:00:00 2001 From: Kerry Meyer Date: Thu, 18 Nov 2021 21:12:04 +0000 Subject: [PATCH 7/7] Revert the proposed change in the rules/config file Restore the setting of the "ENABLE_HOST_SERVICE_ON_START" flag to "n" to disable startup of the sonic-hostservices service during initialization. This change is being made in order to resolve the only remaining issue for the associated set of PRs. --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index e4a74f2061d..d8adb345e68 100644 --- a/rules/config +++ b/rules/config @@ -131,7 +131,7 @@ INCLUDE_MGMT_FRAMEWORK = y # ENABLE_HOST_SERVICE_ON_START - enable sonic-host-server for mgmt-framework and/or # telemetry containers to access host functionality by default -ENABLE_HOST_SERVICE_ON_START = y +ENABLE_HOST_SERVICE_ON_START = n # INCLUDE_RESTAPI - build docker-sonic-restapi for configuring the switch using REST APIs INCLUDE_RESTAPI = n