diff options
author | Sage Weil <sage@redhat.com> | 2018-03-08 23:36:57 +0100 |
---|---|---|
committer | Sage Weil <sage@redhat.com> | 2018-03-15 21:51:55 +0100 |
commit | 6972273d53dc2fcbe9c65d70a4e0f2af6270194e (patch) | |
tree | 418ef0c29a4d89bf91c31ad05cd2221e5fee1441 /src/test | |
parent | Merge pull request #20769 from oritwas/wip-rgw-20448 (diff) | |
download | ceph-6972273d53dc2fcbe9c65d70a4e0f2af6270194e.tar.xz ceph-6972273d53dc2fcbe9c65d70a4e0f2af6270194e.zip |
global: output usage on -h, --help, or no args before contacting mons
- when there are no arguments, print a short invitation to stderr to
use -h or --help and exit with an error.
- if we get -h or --help, print usage to stdout, and exit with success.
- do the above *before* making any contact with the cluster. we should
not fail to explain usage because the mons are down.
- if there is some other error with the arguments, print an error message,
but do not spam the user with usage. Try to use cerr instead of derr.
Signed-off-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/TestSignalHandlers.cc | 24 | ||||
-rw-r--r-- | src/test/cli/ceph-authtool/help.t | 1 | ||||
-rw-r--r-- | src/test/cli/ceph-authtool/manpage.t | 24 | ||||
-rw-r--r-- | src/test/cli/ceph-authtool/simple.t | 24 | ||||
-rw-r--r-- | src/test/cli/ceph-kvstore-tool/help.t | 1 | ||||
-rw-r--r-- | src/test/cli/monmaptool/simple.t | 8 | ||||
-rw-r--r-- | src/test/cli/osdmaptool/missing-argument.t | 25 | ||||
-rw-r--r-- | src/test/cli/radosgw-admin/help.t | 1 | ||||
-rw-r--r-- | src/test/objectstore_bench.cc | 10 | ||||
-rw-r--r-- | src/test/rbd_mirror/random_write.cc | 15 | ||||
-rw-r--r-- | src/test/xattr_bench.cc | 8 |
11 files changed, 40 insertions, 101 deletions
diff --git a/src/test/TestSignalHandlers.cc b/src/test/TestSignalHandlers.cc index 1f24c8f9640..74f819675e6 100644 --- a/src/test/TestSignalHandlers.cc +++ b/src/test/TestSignalHandlers.cc @@ -66,10 +66,10 @@ static void infinite_recursion_test() static void usage() { - cerr << "usage: TestSignalHandlers [test]" << std::endl; - cerr << "--simple_segv: run simple_segv test" << std::endl; - cerr << "--infinite_recursion: run infinite_recursion test" << std::endl; - generic_client_usage(); // Will exit() + cout << "usage: TestSignalHandlers [test]" << std::endl; + cout << "--simple_segv: run simple_segv test" << std::endl; + cout << "--infinite_recursion: run infinite_recursion test" << std::endl; + generic_client_usage(); } typedef void (*test_fn_t)(void); @@ -78,6 +78,14 @@ int main(int argc, const char **argv) { vector<const char*> args; argv_to_vec(argc, argv, args); + if (args.empty()) { + cerr << argv[0] << ": -h or --help for usage" << std::endl; + exit(1); + } + if (ceph_argparse_need_usage(args)) { + usage(); + exit(0); + } auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, @@ -88,20 +96,18 @@ int main(int argc, const char **argv) for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) { break; - } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { - usage(); } else if (ceph_argparse_flag(args, i, "--infinite_recursion", (char*)NULL)) { fn = infinite_recursion_test; } else if (ceph_argparse_flag(args, i, "-s", "--simple_segv", (char*)NULL)) { fn = simple_segv_test; } else { - cerr << "Garbage at end of command line." << std::endl; - usage(); + cerr << "unrecognized argument: " << *i << std::endl; + exit(1); } } if (!fn) { std::cerr << "Please select a test to run. Type -h for help." << std::endl; - usage(); + exit(1); } fn(); return 0; diff --git a/src/test/cli/ceph-authtool/help.t b/src/test/cli/ceph-authtool/help.t index 9a6c88357f7..77174b835ac 100644 --- a/src/test/cli/ceph-authtool/help.t +++ b/src/test/cli/ceph-authtool/help.t @@ -1,6 +1,5 @@ # TODO synchronize with man page $ ceph-authtool --help - no command specified usage: ceph-authtool keyringfile [OPTIONS]... where the options are: -l, --list will list all keys and capabilities present in diff --git a/src/test/cli/ceph-authtool/manpage.t b/src/test/cli/ceph-authtool/manpage.t index f84b79457a1..3201aa37b2a 100644 --- a/src/test/cli/ceph-authtool/manpage.t +++ b/src/test/cli/ceph-authtool/manpage.t @@ -1,27 +1,5 @@ $ ceph-authtool - ceph-authtool: must specify filename - usage: ceph-authtool keyringfile [OPTIONS]... - where the options are: - -l, --list will list all keys and capabilities present in - the keyring - -p, --print-key will print an encoded key for the specified - entityname. This is suitable for the - 'mount -o secret=..' argument - -C, --create-keyring will create a new keyring, overwriting any - existing keyringfile - -g, --gen-key will generate a new secret key for the - specified entityname - --gen-print-key will generate a new secret key without set it - to the keyringfile, prints the secret to stdout - --import-keyring FILE will import the content of a given keyring - into the keyringfile - -n NAME, --name NAME specify entityname to operate on - -u AUID, --set-uid AUID sets the auid (authenticated user id) for the - specified entityname - -a BASE64, --add-key BASE64 will add an encoded key to the keyring - --cap SUBSYSTEM CAPABILITY will set the capability for given subsystem - --caps CAPSFILE will set all of capabilities associated with a - given key, for all subsystems + ceph-authtool: -h or --help for usage [1] # demonstrate that manpage examples fail without config diff --git a/src/test/cli/ceph-authtool/simple.t b/src/test/cli/ceph-authtool/simple.t index 35905ad0726..bf3fc103614 100644 --- a/src/test/cli/ceph-authtool/simple.t +++ b/src/test/cli/ceph-authtool/simple.t @@ -1,25 +1,3 @@ $ ceph-authtool - ceph-authtool: must specify filename - usage: ceph-authtool keyringfile [OPTIONS]... - where the options are: - -l, --list will list all keys and capabilities present in - the keyring - -p, --print-key will print an encoded key for the specified - entityname. This is suitable for the - 'mount -o secret=..' argument - -C, --create-keyring will create a new keyring, overwriting any - existing keyringfile - -g, --gen-key will generate a new secret key for the - specified entityname - --gen-print-key will generate a new secret key without set it - to the keyringfile, prints the secret to stdout - --import-keyring FILE will import the content of a given keyring - into the keyringfile - -n NAME, --name NAME specify entityname to operate on - -u AUID, --set-uid AUID sets the auid (authenticated user id) for the - specified entityname - -a BASE64, --add-key BASE64 will add an encoded key to the keyring - --cap SUBSYSTEM CAPABILITY will set the capability for given subsystem - --caps CAPSFILE will set all of capabilities associated with a - given key, for all subsystems + ceph-authtool: -h or --help for usage [1] diff --git a/src/test/cli/ceph-kvstore-tool/help.t b/src/test/cli/ceph-kvstore-tool/help.t index 9fb3e1de9d8..eab57fdb5bc 100644 --- a/src/test/cli/ceph-kvstore-tool/help.t +++ b/src/test/cli/ceph-kvstore-tool/help.t @@ -18,4 +18,3 @@ compact-range <prefix> <start> <end> repair - [1] diff --git a/src/test/cli/monmaptool/simple.t b/src/test/cli/monmaptool/simple.t index cee2ab56767..48c56911739 100644 --- a/src/test/cli/monmaptool/simple.t +++ b/src/test/cli/monmaptool/simple.t @@ -1,9 +1,3 @@ $ monmaptool - monmaptool: must specify monmap filename - usage: [--print] [--create [--clobber][--fsid uuid]] - [--generate] [--set-initial-members] - [--add name 1.2.3.4:567] [--rm name] - [--feature-list [plain|parseable]] - [--feature-set <value> [--optional|--persistent]] - [--feature-unset <value> [--optional|--persistent]] <mapfilename> + monmaptool: -h or --help for usage [1] diff --git a/src/test/cli/osdmaptool/missing-argument.t b/src/test/cli/osdmaptool/missing-argument.t index db1745bd857..de9b8007323 100644 --- a/src/test/cli/osdmaptool/missing-argument.t +++ b/src/test/cli/osdmaptool/missing-argument.t @@ -1,26 +1,3 @@ $ osdmaptool - osdmaptool: must specify osdmap filename - usage: [--print] [--createsimple <numosd> [--clobber] [--pg_bits <bitsperosd>]] <mapfilename> - --export-crush <file> write osdmap's crush map to <file> - --import-crush <file> replace osdmap's crush map with <file> - --test-map-pgs [--pool <poolid>] [--pg_num <pg_num>] map all pgs - --test-map-pgs-dump [--pool <poolid>] map all pgs - --test-map-pgs-dump-all [--pool <poolid>] map all pgs to osds - --health dump health checks - --mark-up-in mark osds up and in (but do not persist) - --mark-out <osdid> mark an osd as out (but do not persist) - --with-default-pool include default pool when creating map - --clear-temp clear pg_temp and primary_temp - --test-random do random placements - --test-map-pg <pgid> map a pgid to osds - --test-map-object <objectname> [--pool <poolid>] map an object to osds - --upmap-cleanup <file> clean up pg_upmap[_items] entries, writing - commands to <file> [default: - for stdout] - --upmap <file> calculate pg upmap entries to balance pg layout - writing commands to <file> [default: - for stdout] - --upmap-max <max-count> set max upmap entries to calculate [default: 100] - --upmap-deviation <max-deviation> - max deviation from target [default: .01] - --upmap-pool <poolname> restrict upmap balancing to 1 or more pools - --upmap-save write modified OSDMap with upmap changes + osdmaptool: -h or --help for usage [1] diff --git a/src/test/cli/radosgw-admin/help.t b/src/test/cli/radosgw-admin/help.t index a7a388e14ea..9fd46c4d0ca 100644 --- a/src/test/cli/radosgw-admin/help.t +++ b/src/test/cli/radosgw-admin/help.t @@ -294,6 +294,5 @@ --setgroup GROUP set gid to group or gid --version show version and quit - [1] diff --git a/src/test/objectstore_bench.cc b/src/test/objectstore_bench.cc index 406dce3a75e..7b67cba724b 100644 --- a/src/test/objectstore_bench.cc +++ b/src/test/objectstore_bench.cc @@ -20,7 +20,7 @@ static void usage() { - derr << "usage: ceph_objectstore_bench [flags]\n" + cout << "usage: ceph_objectstore_bench [flags]\n" " --size\n" " total size in bytes\n" " --block-size\n" @@ -30,7 +30,7 @@ static void usage() " --threads\n" " number of threads to carry out this workload\n" " --multi-object\n" - " have each thread write to a separate object\n" << dendl; + " have each thread write to a separate object\n" << std::endl; generic_server_usage(); } @@ -167,13 +167,13 @@ int main(int argc, const char *argv[]) std::string err; if (!cfg.size.parse(val, &err)) { derr << "error parsing size: " << err << dendl; - usage(); + exit(1); } } else if (ceph_argparse_witharg(args, i, &val, "--block-size", (char*)nullptr)) { std::string err; if (!cfg.block_size.parse(val, &err)) { derr << "error parsing block-size: " << err << dendl; - usage(); + exit(1); } } else if (ceph_argparse_witharg(args, i, &val, "--repeats", (char*)nullptr)) { cfg.repeats = atoi(val.c_str()); @@ -183,7 +183,7 @@ int main(int argc, const char *argv[]) cfg.multi_object = true; } else { derr << "Error: can't understand argument: " << *i << "\n" << dendl; - usage(); + exit(1); } } diff --git a/src/test/rbd_mirror/random_write.cc b/src/test/rbd_mirror/random_write.cc index 4b41ef044f1..2d89924d8ea 100644 --- a/src/test/rbd_mirror/random_write.cc +++ b/src/test/rbd_mirror/random_write.cc @@ -154,18 +154,19 @@ int main(int argc, const char **argv) { std::vector<const char*> args; argv_to_vec(argc, argv, args); + if (args.empty()) { + cerr << argv[0] << ": -h or --help for usage" << std::endl; + exit(1); + } + if (ceph_argparse_need_usage(args)) { + usage(); + exit(0); + } auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); - for (auto i = args.begin(); i != args.end(); ++i) { - if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { - usage(); - return EXIT_SUCCESS; - } - } - if (args.size() < 2) { usage(); return EXIT_FAILURE; diff --git a/src/test/xattr_bench.cc b/src/test/xattr_bench.cc index 23b7fd44307..b5a2aded78f 100644 --- a/src/test/xattr_bench.cc +++ b/src/test/xattr_bench.cc @@ -151,6 +151,14 @@ uint64_t do_run(ObjectStore *store, int attrsize, int numattrs, int main(int argc, char **argv) { vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); + if (args.empty()) { + cerr << argv[0] << ": -h or --help for usage" << std::endl; + exit(1); + } + if (ceph_argparse_need_usage(args)) { + usage(argv[0]); + exit(0); + } auto cct = global_init(0, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, |