]> granicus.if.org Git - zfs/commitdiff
Handle invalid options in arc_summary
authorLOLi <loli10K@users.noreply.github.com>
Tue, 19 Dec 2017 21:02:40 +0000 (22:02 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 19 Dec 2017 21:02:40 +0000 (13:02 -0800)
If an invalid option is provided to arc_summary.py we handle any error
thrown from the getopt Python module and print the usage help message.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #6983

cmd/arc_summary/arc_summary.py
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh [new file with mode: 0755]

index 5da81347cc296490734fcda0ec20749ad51177da..2472f87eadf3ae0aa7a1b022ac6a124ffffd9a3b 100755 (executable)
@@ -977,9 +977,15 @@ def main():
     global show_tunable_descriptions
     global alternate_tunable_layout
 
-    opts, args = getopt.getopt(
-        sys.argv[1:], "adp:h", ["alternate", "description", "page=", "help"]
-    )
+    try:
+        opts, args = getopt.getopt(
+            sys.argv[1:],
+            "adp:h", ["alternate", "description", "page=", "help"]
+        )
+    except getopt.error as e:
+        sys.stderr.write("Error: %s\n" % e.msg)
+        usage()
+        sys.exit(1)
 
     args = {}
     for opt, arg in opts:
@@ -991,7 +997,7 @@ def main():
             args['p'] = arg
         if opt in ('-h', '--help'):
             usage()
-            sys.exit()
+            sys.exit(0)
 
     Kstat = get_Kstat()
 
@@ -1006,7 +1012,7 @@ def main():
         except IndexError:
             sys.stderr.write('the argument to -p must be between 1 and ' +
                              str(len(unSub)) + '\n')
-            sys.exit()
+            sys.exit(1)
     else:
         pages = unSub
 
index 0c8f298c6d494e5b64b3c9b79acb8736e472de5e..c4650ab41b0662a0cfc1bcc296850fa3b277b124 100644 (file)
@@ -408,7 +408,7 @@ tests = ['zdb_001_neg', 'zfs_001_neg', 'zfs_allow_001_neg',
     'zpool_offline_001_neg', 'zpool_online_001_neg', 'zpool_remove_001_neg',
     'zpool_replace_001_neg', 'zpool_scrub_001_neg', 'zpool_set_001_neg',
     'zpool_status_001_neg', 'zpool_upgrade_001_neg', 'arcstat_001_pos',
-    'arc_summary_001_pos', 'dbufstat_001_pos']
+    'arc_summary_001_pos', 'arc_summary_002_neg', 'dbufstat_001_pos']
 user =
 tags = ['functional', 'cli_user', 'misc']
 
index cf7502c27eac5f0b89063697b5bdcc5030f05a33..75a3d0886f36f44ad34b92782baebbb94271fd15 100644 (file)
@@ -46,4 +46,5 @@ dist_pkgdata_SCRIPTS = \
        zpool_upgrade_001_neg.ksh \
        arcstat_001_pos.ksh \
        arc_summary_001_pos.ksh \
+       arc_summary_002_neg.ksh \
        dbufstat_001_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/arc_summary_002_neg.ksh
new file mode 100755 (executable)
index 0000000..e63552f
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2015 by Lawrence Livermore National Security, LLC.
+# All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+typeset args=("-x" "-r" "-5" "-p 7" "--err" "-@")
+
+log_assert "arc_summary.py generates an error code with invalid options"
+
+for arg in "${args[@]}"; do
+        log_mustnot eval "arc_summary.py $arg > /dev/null"
+done
+
+log_pass "arc_summary.py generates an error code with invalid options"