Skip to contentSkip to conversation

mountstats: Fix exit code handling

PATCH In review Scott Mayhew 2 participants 2 messages Mar 2, 2015 – Mar 4, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mountstats: Fix exit code handling

When I changed mountstats to use the argparse module, I neglected to make the subcommand functions return any values even though main() was looking for them. Also removed SystemExit from the except clause at the end of the program since it was causing the program to always exit with a status of 1.

---
 tools/mountstats/mountstats.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
tools/mountstats/mountstats.py +7 -4
index fd73feb..7f5dee1 100644
@@ -708,7 +708,7 @@ def mountstats_command(args):
                 mountpoints += [device]
     if len(mountpoints) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     if args.since:
         old_mountstats = parse_stats_file(args.since)
@@ -729,6 +729,7 @@ def mountstats_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 def nfsstat_command(args):
     """nfsstat-like command for NFS mount points
@@ -766,7 +767,7 @@ def nfsstat_command(args):
                 mountpoints += [device]
     if len(mountpoints) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     if args.since:
         old_mountstats = parse_stats_file(args.since)
@@ -803,6 +804,7 @@ def nfsstat_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 def print_iostat_summary(old, new, devices, time):
     for device in devices:
@@ -847,7 +849,7 @@ def iostat_command(args):
                 devices += [device]
     if len(devices) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     sample_time = 0
 
@@ -875,6 +877,7 @@ def iostat_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 class ICMAction(argparse.Action):
     """Custom action to deal with interval, count, and mountpoints.
@@ -986,7 +989,7 @@ try:
         sys.stdout.close()
         sys.stderr.close()
         sys.exit(res)
-except (SystemExit, KeyboardInterrupt, RuntimeError):
+except (KeyboardInterrupt, RuntimeError):
     sys.exit(1)
 except IOError:
     pass
Signature · 1 line
1.9.3
#1 lore raw
Quoted 7 lines · Scott Mayhew

When I changed mountstats to use the argparse module, I neglected to make the subcommand functions return any values even though main() was looking for them. Also removed SystemExit from the except clause at the end of the program since it was causing the program to always exit with a status of 1.

Committed...

steved.

Quoted 70 lines
---
 tools/mountstats/mountstats.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
tools/mountstats/mountstats.py +7 -5
index fd73feb..7f5dee1 100644
@@ -708,7 +708,7 @@ def mountstats_command(args):
                 mountpoints += [device]
     if len(mountpoints) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     if args.since:
         old_mountstats = parse_stats_file(args.since)
@@ -729,6 +729,7 @@ def mountstats_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 def nfsstat_command(args):
     """nfsstat-like command for NFS mount points
@@ -766,7 +767,7 @@ def nfsstat_command(args):
                 mountpoints += [device]
     if len(mountpoints) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     if args.since:
         old_mountstats = parse_stats_file(args.since)
@@ -803,6 +804,7 @@ def nfsstat_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 def print_iostat_summary(old, new, devices, time):
     for device in devices:
@@ -847,7 +849,7 @@ def iostat_command(args):
                 devices += [device]
     if len(devices) == 0:
         print('No NFS mount points were found')
-        return
+        return 1
 
     sample_time = 0
 
@@ -875,6 +877,7 @@ def iostat_command(args):
     args.infile.close()
     if args.since:
         args.since.close()
+    return 0
 
 class ICMAction(argparse.Action):
     """Custom action to deal with interval, count, and mountpoints.
@@ -986,7 +989,7 @@ try:
         sys.stdout.close()
         sys.stderr.close()
         sys.exit(res)
-except (SystemExit, KeyboardInterrupt, RuntimeError):
+except (KeyboardInterrupt, RuntimeError):
     sys.exit(1)
 except IOError:
     pass
-- 1.9.3