]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librados/service_cxx.cc
import quincy 17.2.0
[ceph.git] / ceph / src / test / librados / service_cxx.cc
CommitLineData
11fdf7f2
TL
1#include <algorithm>
2#include <thread>
3#include <errno.h>
4#include "gtest/gtest.h"
5
6#include "include/rados/librados.hpp"
7#include "include/stringify.h"
8#include "common/config_proxy.h"
9#include "test/librados/test_cxx.h"
10#include "test/librados/testcase_cxx.h"
11#include "test/unit.cc"
12
20effc67 13using namespace std;
11fdf7f2
TL
14using namespace librados;
15
16TEST(LibRadosServicePP, RegisterEarly) {
17 Rados cluster;
18 cluster.init("admin");
19 ASSERT_EQ(0, cluster.conf_read_file(NULL));
20 cluster.conf_parse_env(NULL);
21 string name = string("pid") + stringify(getpid());
22 ASSERT_EQ(0, cluster.service_daemon_register(
23 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
24 ASSERT_EQ(-EEXIST, cluster.service_daemon_register(
25 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
26 ASSERT_EQ(0, cluster.connect());
27 sleep(5);
28 cluster.shutdown();
29}
30
31TEST(LibRadosServicePP, RegisterLate) {
32 Rados cluster;
33 cluster.init("admin");
34 ASSERT_EQ(0, cluster.conf_read_file(NULL));
35 cluster.conf_parse_env(NULL);
36 ASSERT_EQ("", connect_cluster_pp(cluster));
37 string name = string("pid") + stringify(getpid());
38 ASSERT_EQ(0, cluster.service_daemon_register(
39 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
40}
41
42TEST(LibRadosServicePP, Status) {
43 Rados cluster;
44 cluster.init("admin");
45 ASSERT_EQ(0, cluster.conf_read_file(NULL));
46 cluster.conf_parse_env(NULL);
47 string name = string("pid") + stringify(getpid());
48 ASSERT_EQ(-ENOTCONN, cluster.service_daemon_update_status(
49 {{"testing", "starting"}}));
50 ASSERT_EQ(0, cluster.connect());
51 ASSERT_EQ(0, cluster.service_daemon_register(
52 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
53 for (int i=0; i<20; ++i) {
54 ASSERT_EQ(0, cluster.service_daemon_update_status({
55 {"testing", "running"},
56 {"count", stringify(i)}
57 }));
58 sleep(1);
59 }
60 cluster.shutdown();
61}
62
63TEST(LibRadosServicePP, Close) {
64 int tries = 20;
65 string name = string("close-test-pid") + stringify(getpid());
66 int i;
67 for (i = 0; i < tries; ++i) {
68 cout << "attempt " << i << " of " << tries << std::endl;
69 {
70 Rados cluster;
71 cluster.init("admin");
72 ASSERT_EQ(0, cluster.conf_read_file(NULL));
73 cluster.conf_parse_env(NULL);
74 ASSERT_EQ(0, cluster.connect());
75 ASSERT_EQ(0, cluster.service_daemon_register(
76 "laundry", name, {{"foo", "bar"}, {"this", "that"}}));
77 sleep(3); // let it register
78 cluster.shutdown();
79 }
80 // mgr updates servicemap every tick
81 //sleep(g_conf().get_val<int64_t>("mgr_tick_period"));
82 std::this_thread::sleep_for(g_conf().get_val<std::chrono::seconds>(
83 "mgr_tick_period"));
84 // make sure we are deregistered
85 {
86 Rados cluster;
87 cluster.init("admin");
88 ASSERT_EQ(0, cluster.conf_read_file(NULL));
89 cluster.conf_parse_env(NULL);
90 ASSERT_EQ(0, cluster.connect());
91 bufferlist inbl, outbl;
92 ASSERT_EQ(0, cluster.mon_command("{\"prefix\": \"service dump\"}",
93 inbl, &outbl, NULL));
94 string s = outbl.to_str();
95 cluster.shutdown();
96
97 if (s.find(name) != string::npos) {
98 cout << " failed to deregister:\n" << s << std::endl;
99 } else {
100 break;
101 }
102 }
103 }
104 ASSERT_LT(i, tries);
105}