]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: get_command_descriptions support program
authorLoic Dachary <loic@dachary.org>
Wed, 11 Sep 2013 16:26:21 +0000 (18:26 +0200)
committerLoic Dachary <loic@dachary.org>
Mon, 23 Sep 2013 21:46:43 +0000 (23:46 +0200)
The get_command_descriptions function is not designed to be tested in
C++ because all the validation happens in pybind/ceph_argparse.py. The
get_command_descriptions program is designed to be used by python unit
tests as a mean to get a JSON dump of the content of mon/MonCommands.h

      get_command_descriptions --all

      {"cmd000":{"sig":["pg","stat"],"help": ... "avail":"cli,rest"}}

It also provides a way to reproduce and keep track of past errors
( typos etc. ) to ensure the python validation keeps catching it.

      get_command_descriptions --pull585

Add /get_command_descriptions to .gitignore so that

      git ls-files --exclude-standard --others

does not see it which is required for
https://github.com/ceph/autobuild-ceph/blob/f018d220f2622a9fc8c86a31e1fa13263790c399/build-ceph.sh#L73

http://tracker.ceph.com/issues/6274 refs #6274

Reviewed-by: Joao Eduardo Luis <joao.luis@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
Signed-off-by: Loic Dachary <loic@dachary.org>
src/.gitignore
src/test/Makefile.am
src/test/common/get_command_descriptions.cc [new file with mode: 0644]

index 4c98529bd87d7b3c256f000402da2c1da329e080..6efe8dc6bc45a97cf84a1f1f57475f6bee63299e 100644 (file)
@@ -68,6 +68,7 @@ Makefile
 /test_*
 /cls_test_*
 /unittest_*
+/get_command_descriptions
 
 # old dir, may in use by older branches
 /leveldb
index e0ac1369568a9720f237741b79e2ef79ebd47f9a..6c127615b42742ffb3682d241ab63a438aedc9be 100644 (file)
@@ -65,6 +65,11 @@ endif
 
 bin_PROGRAMS += ceph-dencoder
 
+get_command_descriptions_SOURCES = test/common/get_command_descriptions.cc
+get_command_descriptions_CXXFLAGS = $(UNITTEST_CXXFLAGS)
+get_command_descriptions_LDADD = $(LIBMON) $(LIBCOMMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL)
+noinst_PROGRAMS += get_command_descriptions
+
 
 ## Build tests
 # These should all use explicit _CXXFLAGS so avoid basename conflicts
diff --git a/src/test/common/get_command_descriptions.cc b/src/test/common/get_command_descriptions.cc
new file mode 100644 (file)
index 0000000..afca825
--- /dev/null
@@ -0,0 +1,116 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library Public License for more details.
+ *
+ */
+
+#include <stdio.h>
+#include <signal.h>
+#include "mon/Monitor.h"
+#include "common/ceph_argparse.h"
+#include "global/global_init.h"
+#include "common/debug.h"
+
+#define dout_subsys ceph_subsys_mon
+
+static void usage(ostream &out)
+{
+  out << "usage: get_command_descriptions [options ...]" << std::endl;
+  out << "print on stdout the result of JSON formatted options\n";
+  out << "found in mon/MonCommands.h as produced by the\n";
+  out << "Monitor.cc::get_command_descriptions function.\n";
+  out << "Designed as a helper for ceph_argparse.py unit tests.\n";
+  out << "\n";
+  out << "  --all               all of mon/MonCommands.h \n";
+  out << "  --pull585           reproduce the bug fixed by #585\n";
+  out << "\n";
+  out << "Examples:\n";
+  out << "  get_command_descriptions --all\n";
+  out << "  get_command_descriptions --pull585\n";
+}
+
+static void json_print(const MonCommand *mon_commands, int size)
+{
+  bufferlist rdata;
+  Formatter *f = new_formatter("json");
+  get_command_descriptions(mon_commands, size, f, &rdata);
+  delete f;
+  string data(rdata.c_str());
+  dout(0) << data << dendl;
+}
+
+static void all()
+{
+#undef COMMAND
+  MonCommand mon_commands[] = {
+#define COMMAND(parsesig, helptext, modulename, req_perms, avail)      \
+    {parsesig, helptext, modulename, req_perms, avail},
+#include <mon/MonCommands.h>
+  };
+
+  json_print(mon_commands, ARRAY_SIZE(mon_commands));
+}
+
+// syntax error https://github.com/ceph/ceph/pull/585
+static void pull585()
+{
+  MonCommand mon_commands[] = {
+    { "osd pool create "                      
+      "name=pool,type=CephPoolname " 
+      "name=pg_num,type=CephInt,range=0 " 
+      "name=pgp_num,type=CephInt,range=0,req=false" // !!! missing trailing space
+      "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", 
+      "create pool", "osd", "rw", "cli,rest" }
+  };
+
+  json_print(mon_commands, ARRAY_SIZE(mon_commands));
+}
+
+int main(int argc, char **argv) {
+  vector<const char*> args;
+  argv_to_vec(argc, (const char **)argv, args);
+
+  global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+  common_init_finish(g_ceph_context);
+
+  if (args.empty()) {
+    usage(cerr);
+    exit(1);
+  }
+  for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ++i) {
+    string err;
+
+    if (*i == string("help") || *i == string("-h") || *i == string("--help")) {
+      usage(cout);
+      exit(0);
+    } else if (*i == string("--all")) {
+      all();
+    } else if (*i == string("--pull585")) {
+      pull585();
+    }
+  }  
+}
+
+/*
+ * Local Variables:
+ * compile-command: "cd ../.. ; 
+ *   make get_command_descriptions && 
+ *   ./get_command_descriptions --all --pull585"
+ * End:
+ */
+