Skip to content

Commit

Permalink
Add CLI tests for osdmaptool and friends.
Browse files Browse the repository at this point in the history
Uses a python package "cram" as test runner.
Requires PIP (python-pip.deb) installed on the
build machine, to actually run these tests.

The cram application itself is included as a
tarball that gets installed in a virtualenv
when the tests are run. cram is GPL.
  • Loading branch information
Tommi Virtanen committed Jan 12, 2011
1 parent 9a5a7fe commit f4a0c2f
Show file tree
Hide file tree
Showing 38 changed files with 636 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ EXTRA_DIST = autogen.sh ceph.spec.in
SUBDIRS = . src man


# Build gtest before we build our own tests. Doing this instead of
# SUBDIRS gtest's own tests being run and slowing us down.
check-local:
# Build gtest before we build our own tests. Doing this
# instead of SUBDIRS gtest's own tests being run and slowing
# us down.
@echo "Making lib/libgtest.a lib/libgtest_main.a in src/gtest"
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la

# exercise cli tools
./src/test/run-cli-tests


# "make distclean" both runs this and recurses into src/gtest, if
# gtest is in DIST_SUBDIRS. Take extra care to not fail when
# effectively cleaned twice.
Expand Down
1 change: 1 addition & 0 deletions src/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/virtualenv
18 changes: 18 additions & 0 deletions src/test/cli/cauthtool/add-key-segv.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$ cauthtool kring --create-keyring
creating kring

# TODO fix me
$ cauthtool kring --add-key 'FAKEBASE64 foo'
*** Caught signal (Segmentation fault) ***
in thread [0-9a-f]{12} (re)
ceph version .* (re)
1: .* (re)
2: .* (re)
3: .* (re)
4: .* (re)
5: .* (re)
6: .* (re)
7: .* (re)
8: .* (re)
Segmentation fault
[139]
11 changes: 11 additions & 0 deletions src/test/cli/cauthtool/add-key.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ cauthtool kring --create-keyring
creating kring

$ cauthtool kring --add-key 'AQAK7yxNeF+nHBAA0SgSdbs8IkJrxroDeJ6SwQ== 18446744073709551615'
added entity client.admin auth auth(auid = 18446744073709551615 key=AQAK7yxNeF+nHBAA0SgSdbs8IkJrxroDeJ6SwQ== with 0 caps)

# cram makes matching escape-containing lines with regexps a bit ugly
$ cauthtool kring --list
client.admin
\\t key: AQAK7yxNeF\+nHBAA0SgSdbs8IkJrxroDeJ6SwQ== \(esc\) (re)
\\tauid: 18446744073709551615 \(esc\) (re)
12 changes: 12 additions & 0 deletions src/test/cli/cauthtool/cap-invalid.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ cauthtool kring --create-keyring --gen-key
creating kring

# TODO is this nice?
$ cauthtool --cap osd 'broken' kring
$ cauthtool kring --list|grep caps:
\tcaps: [osd] broken (esc)

# TODO is this nice?
$ cauthtool --cap xyzzy 'broken' kring
$ cauthtool kring --list|grep caps:
\tcaps: [xyzzy] broken (esc)
11 changes: 11 additions & 0 deletions src/test/cli/cauthtool/cap-overwrite.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ cauthtool kring --create-keyring --gen-key
creating kring

$ cauthtool --cap osd 'allow rx pool=swimming' kring
$ cauthtool kring --list|grep caps:
\tcaps: [osd] allow rx pool=swimming (esc)

# TODO it seems --cap overwrites all previous caps; is this wanted?
$ cauthtool --cap mds 'allow' kring
$ cauthtool kring --list|grep caps:
\tcaps: [mds] allow (esc)
6 changes: 6 additions & 0 deletions src/test/cli/cauthtool/cap.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ cauthtool kring --create-keyring --gen-key
creating kring

$ cauthtool --cap osd 'allow rx pool=swimming' kring
$ cauthtool kring --list|grep caps:
\tcaps: [osd] allow rx pool=swimming (esc)
18 changes: 18 additions & 0 deletions src/test/cli/cauthtool/create-gen-list.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$ cauthtool kring --create-keyring
creating kring

$ cauthtool kring --list

$ cauthtool kring --gen-key

# cram makes matching escape-containing lines with regexps a bit ugly
$ cauthtool kring --list
client.admin
\\t key: [a-zA-Z0-9+/]+=* \(esc\) (re)
\\tauid: [0-9]{20} \(esc\) (re)

# synonym
$ cauthtool kring -l
client.admin
\\t key: [a-zA-Z0-9+/]+=* \(esc\) (re)
\\tauid: [0-9]{20} \(esc\) (re)
5 changes: 5 additions & 0 deletions src/test/cli/cauthtool/help.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TODO synchronize with man page
$ cauthtool --help
no command specified
usage: [--create-keyring] [--gen-key] [--name=<name>] [--set-uid=uid] [--caps=<filename>] [--list] [--print-key] <filename>
[1]
9 changes: 9 additions & 0 deletions src/test/cli/cauthtool/list-empty.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ touch empty

$ cauthtool --list empty
error reading file empty
[1]

$ cauthtool -l empty
error reading file empty
[1]
7 changes: 7 additions & 0 deletions src/test/cli/cauthtool/list-nonexistent.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ cauthtool --list nonexistent
can't open nonexistent: No such file or directory
[1]

$ cauthtool -l nonexistent
can't open nonexistent: No such file or directory
[1]
32 changes: 32 additions & 0 deletions src/test/cli/cauthtool/manpage.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# demonstrate that manpage examples fail without config
# TODO fix the manpage
$ cauthtool -c -n client.foo --gen-key keyring.bin
error reading config file(s) /etc/ceph/ceph.conf, ~/.ceph/config, ceph.conf
[1]

# work around the above
$ touch ceph.conf

To create a new keyring containing a key for client.foo:

#TODO apparently -c is not enough for --create-keyring; fix manpage
$ cauthtool -c -n client.foo --gen-key keyring.bin
can't open keyring.bin: No such file or directory
[1]

$ cauthtool --create-keyring -n client.foo --gen-key keyring.bin
creating keyring.bin

To associate some capabilities with the key (namely, the ability to mount a Ceph filesystem):

$ cauthtool -n client.foo --cap mds 'allow' --cap osd 'allow rw pool=data' --cap mon 'allow r' keyring.bin

To display the contents of the keyring:

$ cauthtool -l keyring.bin
client.foo
\\t key: [a-zA-Z0-9+/]+=* \(esc\) (re)
\\tauid: [0-9]{20} \(esc\) (re)
\tcaps: [mds] allow (esc)
\tcaps: [mon] allow r (esc)
\tcaps: [osd] allow rw pool=data (esc)
4 changes: 4 additions & 0 deletions src/test/cli/cauthtool/simple.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$ cauthtool
cauthtool: must specify filename
usage: [--create-keyring] [--gen-key] [--name=<name>] [--set-uid=uid] [--caps=<filename>] [--list] [--print-key] <filename>
[1]
33 changes: 33 additions & 0 deletions src/test/cli/cconf/help.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#TODO
$ cconf --help
Parse error at argument: --help
Ceph configuration query tool

USAGE
cconf <flags> <action>

ACTIONS
-l|--list-sections <prefix> List sections in prefix

--lookup <key> [defval] Print a configuration setting to stdout.
\t\t\t\t If the setting is not defined, and the (esc)
\t\t\t\t optional argument defval is provide, it will (esc)
\t\t\t\t be printed instead. variables in defval are (esc)
\t\t\t\t interpolated. (esc)

FLAGS
-i id Set id
[-s <section>] Add to list of sections to search

If there is no action given, the action will default to --lookup.

EXAMPLES
[$] cconf -i cconf -c /etc/ceph/ceph\.conf -t mon -i 0 'mon addr' (re)
Find out if there is a 'mon addr' defined in /etc/ceph/ceph.conf

[$] cconf -l mon (re)
List sections beginning with 'mon'.

RETURN CODE
Return code will be 0 on success; error code otherwise.
[1]
22 changes: 22 additions & 0 deletions src/test/cli/cconf/invalid-args.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$ cat >test.conf <<EOF
> [bar]
> bar = green
> EOF

# TODO output an error
$ cconf -c test.conf broken
[1]

# TODO output an error (missing key)
$ cconf -c test.conf -s bar
*** Caught signal (Segmentation fault) ***
in thread [0-9a-f]{12} (re)
ceph version .* (re)
1: .* (re)
2: .* (re)
3: .* (re)
4: .* (re)
5: .* (re)
6: .* (re)
Segmentation fault
[139]
35 changes: 35 additions & 0 deletions src/test/cli/cconf/manpage.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# setup
$ cat >foo.conf <<'EOF'
> ; ---------------------
> [group cephnet]
> addr = 10.3.14.0/24
>
> [global]
> pid file = /home/sage/ceph/src/out/$name.pid
>
> [osd]
> osd data = /mnt/osd$id
> [osd3]
> host = cosd3
> EOF

To extract the value of the "osd data" option for the osd0 daemon,

# TODO shouldn't this say /mnt/osd0? is this the fault of cram?

$ cconf -c foo.conf "osd data" -i 0 -t osd
/mnt/osd0

This is equivalent to doing specifying sections [osd0], [osd.0],
[osd], or [global], in that order of preference:

# TODO the "admin" here seems like an actual bug

$ cconf -c foo.conf "osd data" -s osd0 -s osd.0 -s osd -s global
/mnt/osdadmin

To list all sections that begin with osd:

$ cconf -c foo.conf -l osd
osd
osd3
38 changes: 38 additions & 0 deletions src/test/cli/cconf/option.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$ cat >test.conf <<EOF
> [bar]
> bar = green
> [foo]
> bar = blue
> [baz]
> bar = yellow
> [thud]
> bar = red
> [nobar]
> other = 42
> EOF

$ cconf -c test.conf bar -s foo
blue

# TODO man page stops in the middle of a sentence

$ cconf -c test.conf bar -s xyzzy
[1]

$ cconf -c test.conf bar notfound -s xyzzy
notfound

$ cconf -c test.conf bar notfound -s xyzzy -s thud
red

$ cconf -c test.conf bar notfound -s nobar -s thud
red

$ cconf -c test.conf bar notfound -s thud -s baz
red

$ cconf -c test.conf bar notfound -s baz -s thud
yellow

$ cconf -c test.conf bar notfound -s xyzzy -s nobar -s thud -s baz
red
18 changes: 18 additions & 0 deletions src/test/cli/cconf/sections.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$ cat >test.conf <<EOF
> [bar]
> bar = green
> [foo]
> bar = blue
> [baz]
> bar = yellow
> [thud]
> bar = yellow
> EOF

$ cconf -c test.conf -l bar
bar

$ cconf -c test.conf -l b
bar
baz

13 changes: 13 additions & 0 deletions src/test/cli/cconf/simple.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#TODO
$ cconf
*** Caught signal (Segmentation fault) ***
in thread [0-9a-f]{12} (re)
ceph version .* (re)
1: .* (re)
2: .* (re)
3: .* (re)
4: .* (re)
5: .* (re)
6: .* (re)
Segmentation fault
[139]
28 changes: 28 additions & 0 deletions src/test/cli/monmaptool/add-exists.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$ monmaptool --create mymonmap
monmaptool: monmap file mymonmap
failed to open log file '/var/log/ceph/': error 21: Is a directory
\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]{12} can't open mymonmap: error 2: No such file or directory (re)
monmaptool: generated fsid [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (re)
monmaptool: writing epoch 1 to mymonmap (0 monitors)

$ ORIG_FSID="$(monmaptool --print mymonmap|grep ^fsid)"

$ monmaptool --add foo 2.3.4.5:6789 mymonmap
monmaptool: monmap file mymonmap
monmaptool: writing epoch 2 to mymonmap (1 monitors)
$ monmaptool --add foo 3.4.5.6:7890 mymonmap
monmaptool: monmap file mymonmap
monmaptool: map already contains mon.foo
usage: [--print] [--create [--clobber]] [--add name 1.2.3.4:567] [--rm name] <mapfilename>
[1]

$ monmaptool --print mymonmap
monmaptool: monmap file mymonmap
epoch 2
fsid [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (re)
last_changed \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ (re)
created \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ (re)
0: 2.3.4.5:6789/0 mon.foo

$ NEW_FSID="$(monmaptool --print mymonmap|grep ^fsid)"
$ [ "$ORIG_FSID" = "$NEW_FSID" ]
31 changes: 31 additions & 0 deletions src/test/cli/monmaptool/add-many.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$ monmaptool --create mymonmap
monmaptool: monmap file mymonmap
failed to open log file '/var/log/ceph/': error 21: Is a directory
\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]{12} can't open mymonmap: error 2: No such file or directory (re)
monmaptool: generated fsid [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (re)
monmaptool: writing epoch 1 to mymonmap (0 monitors)

$ ORIG_FSID="$(monmaptool --print mymonmap|grep ^fsid)"

$ monmaptool --add foo 2.3.4.5:6789 mymonmap
monmaptool: monmap file mymonmap
monmaptool: writing epoch 2 to mymonmap (1 monitors)
$ monmaptool --add bar 3.4.5.6:7890 mymonmap
monmaptool: monmap file mymonmap
monmaptool: writing epoch 3 to mymonmap (2 monitors)
$ monmaptool --add baz 4.5.6.7:8901 mymonmap
monmaptool: monmap file mymonmap
monmaptool: writing epoch 4 to mymonmap (3 monitors)

$ monmaptool --print mymonmap
monmaptool: monmap file mymonmap
epoch 4
fsid [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (re)
last_changed \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ (re)
created \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ (re)
0: 3.4.5.6:7890/0 mon.bar
1: 4.5.6.7:8901/0 mon.baz
2: 2.3.4.5:6789/0 mon.foo

$ NEW_FSID="$(monmaptool --print mymonmap|grep ^fsid)"
$ [ "$ORIG_FSID" = "$NEW_FSID" ]
Loading

0 comments on commit f4a0c2f

Please sign in to comment.