From: Sage Weil Date: Mon, 10 Aug 2015 17:50:36 +0000 (-0400) Subject: ceph_test_libcephfs: skeleton for access tests X-Git-Tag: v10.0.0~123^2~40 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aea8a0e1419d1a4edfffa1165f6acac73d6ae661;p=ceph.git ceph_test_libcephfs: skeleton for access tests Signed-off-by: Sage Weil --- diff --git a/src/test/Makefile-client.am b/src/test/Makefile-client.am index 83d7cce360e7..614b54346ea7 100644 --- a/src/test/Makefile-client.am +++ b/src/test/Makefile-client.am @@ -450,12 +450,13 @@ ceph_test_libcephfs_SOURCES = \ test/libcephfs/test.cc \ test/libcephfs/readdir_r_cb.cc \ test/libcephfs/caps.cc \ - test/libcephfs/multiclient.cc + test/libcephfs/multiclient.cc \ + test/libcephfs/access.cc if LINUX ceph_test_libcephfs_SOURCES += test/libcephfs/flock.cc endif # LINUX -ceph_test_libcephfs_LDADD = $(LIBCEPHFS) $(UNITTEST_LDADD) +ceph_test_libcephfs_LDADD = $(LIBRADOS) $(LIBCEPHFS) $(LIBCOMMON) $(UNITTEST_LDADD) ceph_test_libcephfs_CXXFLAGS = $(UNITTEST_CXXFLAGS) bin_DEBUGPROGRAMS += ceph_test_libcephfs diff --git a/src/test/libcephfs/access.cc b/src/test/libcephfs/access.cc new file mode 100644 index 000000000000..ce8ee098d8fc --- /dev/null +++ b/src/test/libcephfs/access.cc @@ -0,0 +1,106 @@ +// -*- 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) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "gtest/gtest.h" +#include "include/buffer.h" +#include "include/cephfs/libcephfs.h" +#include "include/rados/librados.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/ceph_argparse.h" +#include "json_spirit/json_spirit.h" + +#ifdef __linux__ +#include +#endif + + +rados_t cluster; + +string key; + +int do_mon_command(const char *s, string *key) +{ + char *outs, *outbuf; + size_t outs_len, outbuf_len; + int r = rados_mon_command(cluster, (const char **)&s, 1, + 0, 0, + &outbuf, &outbuf_len, + &outs, &outs_len); + if (outbuf_len) { + string s(outbuf, outbuf_len); + std::cout << "out: " << s << std::endl; + + // parse out the key + json_spirit::mValue v, k; + json_spirit::read_or_throw(s, v); + k = v.get_array()[0].get_obj().find("key")->second; + *key = k.get_str(); + std::cout << "key: " << *key << std::endl; + free(outbuf); + } else { + return -EINVAL; + } + if (outs_len) { + string s(outs, outs_len); + std::cout << "outs: " << s << std::endl; + free(outs); + } + return r; +} + +TEST(AccessTest, Foo) { + // create access key + string key; + ASSERT_EQ(0, do_mon_command( + "{\"prefix\": \"auth get-or-create\", \"entity\": \"client.foo\", " + "\"caps\": [\"mon\", \"allow *\", \"osd\", \"allow rw\", " + "\"mds\", \"allow rw\"" + "], \"format\": \"json\"}", &key)); + + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, "foo")); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_set(cmount, "key", key.c_str())); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + ceph_shutdown(cmount); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + rados_create(&cluster, NULL); + rados_conf_read_file(cluster, NULL); + rados_conf_parse_env(cluster, NULL); + int r = rados_connect(cluster); + if (r < 0) + exit(1); + + r = RUN_ALL_TESTS(); + + rados_shutdown(cluster); + + return r; +}