summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Dachary <loic@dachary.org>2013-09-11 18:33:52 +0200
committerLoic Dachary <loic@dachary.org>2013-09-23 23:46:43 +0200
commit8f0bb2f02fa7c6acd7ee624f13ce6f172e3d68b0 (patch)
tree1740c13e6a6bd96968203abac5ced1813b3bb259
parent96067e07844a6fb9392595616cebad3f372153cb (diff)
downloadceph-8f0bb2f02fa7c6acd7ee624f13ce6f172e3d68b0.tar.gz
pybind: unit tests for ceph_argparse::parse_json_funcsigs
Run parse_json_funcsigs against the builtin commands found in mon/MonCommands.h. Although it does not provide for a full validation, it will detect some degenerate cases. It is expected to raise if a space is missing at the end of an option specification ( see https://github.com/ceph/ceph/pull/585 ) and this case is tested. New tests of the same kind can be added whenever an undetected error is found. Ideally a validation function is implemented and it would be updated ( with an associated test ) when a new pathological case is found. The json string given to parse_json_funcsigs is obtained from the support program get_command_descriptions. The python-nose dependencies are added to the build requirements in debian/control and ceph.spec.in because make check should always be run at built time. http://tracker.ceph.com/issues/6274 refs #6274 Reviewed-by: Dan Mick <dan.mick@inktank.com> Reviewed-by: Joao Eduardo Luis <joao.luis@inktank.com> Signed-off-by: Loic Dachary <loic@dachary.org>
-rw-r--r--ceph.spec.in1
-rw-r--r--debian/control1
-rw-r--r--src/test/Makefile.am2
-rwxr-xr-xsrc/test/pybind/test_ceph_argparse.py43
4 files changed, 47 insertions, 0 deletions
diff --git a/ceph.spec.in b/ceph.spec.in
index 851ee7acfd5..a60d87ad814 100644
--- a/ceph.spec.in
+++ b/ceph.spec.in
@@ -37,6 +37,7 @@ BuildRequires: perl
BuildRequires: gdbm
BuildRequires: pkgconfig
BuildRequires: python
+BuildRequires: python-nose
BuildRequires: libaio-devel
BuildRequires: libcurl-devel
BuildRequires: libxml2-devel
diff --git a/debian/control b/debian/control
index 44ee725efd4..1aec592c9f8 100644
--- a/debian/control
+++ b/debian/control
@@ -34,6 +34,7 @@ Build-Depends: autoconf,
libxml2-dev,
pkg-config,
python (>= 2.6.6-3~),
+ python-nose,
uuid-dev,
yasm
Standards-Version: 3.9.3
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 6c127615b42..5b709d248a8 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -546,6 +546,8 @@ unittest_texttable_LDADD = $(LIBCOMMON) $(UNITTEST_LDADD)
unittest_texttable_CXXFLAGS = $(UNITTEST_CXXFLAGS)
check_PROGRAMS += unittest_texttable
+check_SCRIPTS += test/pybind/test_ceph_argparse.py
+
if WITH_RADOSGW
ceph_test_cors_SOURCES = test/test_cors.cc
ceph_test_cors_LDADD = \
diff --git a/src/test/pybind/test_ceph_argparse.py b/src/test/pybind/test_ceph_argparse.py
new file mode 100755
index 00000000000..4e091da3d9f
--- /dev/null
+++ b/src/test/pybind/test_ceph_argparse.py
@@ -0,0 +1,43 @@
+#!/usr/bin/nosetests --nocapture
+# -*- mode:python; tab-width:4; indent-tabs-mode:t -*-
+# vim: ts=4 sw=4 smarttab expandtab
+#
+# Ceph - scalable distributed file system
+#
+# Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+#
+# Author: Loic Dachary <loic@dachary.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+
+from nose.tools import eq_ as eq
+from nose.tools import *
+
+from ceph_argparse import validate_command, parse_json_funcsigs
+
+import os
+import re
+import json
+
+def get_command_descriptions(what):
+ buffer = os.popen("./get_command_descriptions " + "--" + what
+ + " 2>&1 | grep cmd000").read()
+ return re.sub(r'^.*?(\{.*\})', '\g<1>', buffer)
+
+def test_parse_json_funcsigs():
+ commands = get_command_descriptions("all")
+ cmd_json = parse_json_funcsigs(commands, 'cli')
+
+ # syntax error https://github.com/ceph/ceph/pull/585
+ commands = get_command_descriptions("pull585")
+ assert_raises(TypeError, parse_json_funcsigs, commands, 'cli')
+
+# Local Variables:
+# compile-command: "cd ../.. ; make -j4 &&
+# PYTHONPATH=pybind nosetests --stop \
+# test/pybind/test_ceph_argparse.py # test_ceph_argparse.py:TestOSD.test_rm"
+# End: