gluster / gluster-health-report

Gluster Health Report Tool
GNU Lesser General Public License v3.0
23 stars 20 forks source link

modify coredump.py: subprocess returns binary string #39

Open ChengWu-NJ opened 5 years ago

ChengWu-NJ commented 5 years ago

Signed-off-by: root greatdolphin@gmail.com

There was a bug in ./glusterhealth/reports/coredump.py: line 21: subprocess returns bytes rather than a string.

ChengWu-NJ commented 5 years ago

found same kind of bugs with confusion of bytes and string in firewall-check

aravindavk commented 5 years ago

Please add universal_newlines=True to Popen in utils.py so that it works without adding b"".

index e227549..8efe000 100644
--- a/glusterhealth/reports/utils.py
+++ b/glusterhealth/reports/utils.py
@@ -34,7 +34,7 @@ class CommandError(Exception):

 def command_output(cmd):
     shell = True if isinstance(cmd, str) else False
-    p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell)
+    p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell, universal_newlines=True)
     out, err = p.communicate()
     if p.returncode != 0:
         raise CommandError((p.returncode, out.strip(), err.strip()))

Current change is not compatible in Python2.

ChengWu-NJ commented 5 years ago

It seems all report functions were coded to suppose command_output returning bytes. here is one of errors after modifying command_output to return str: ######################################### [2019-08-28 07:11:32.421141] E [utils:160:output_error] : [ ERROR] Report failure report=report_system_mounts_disk_usage [2019-08-28 07:11:32.421595] E [main:194:main] : Report failure report=report_system_mounts_disk_usage Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/gluster_health_report-0.7-py3.6.egg/glusterhealth/main.py", line 191, in main func(context) File "/usr/local/lib/python3.6/site-packages/gluster_health_report-0.7-py3.6.egg/glusterhealth/reports/disk_usage.py", line 30, in report_system_mounts_disk_usage check_disk_usage_percentage(ctx, "/", 90) File "/usr/local/lib/python3.6/site-packages/gluster_health_report-0.7-py3.6.egg/glusterhealth/reports/disk_usage.py", line 16, in check_disk_usage_percentage out = get_disk_usage_details(path, ctx) File "/usr/local/lib/python3.6/site-packages/gluster_health_report-0.7-py3.6.egg/glusterhealth/reports/utils.py", line 144, in get_disk_usage_details out.split(byteorstr("\n"))[1].split() TypeError: must be str or None, not bytes ############################################3