]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com> | |
7 | * | |
8 | * Author: Loic Dachary <loic@dachary.org> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU Library Public License as published by | |
12 | * the Free Software Foundation; either version 2, or (at your option) | |
13 | * any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU Library Public License for more details. | |
19 | * | |
20 | * | |
21 | */ | |
22 | #include "gtest/gtest.h" | |
23 | #include "include/types.h" | |
24 | #include "include/msgr.h" | |
25 | #include "common/ceph_context.h" | |
11fdf7f2 | 26 | #include "common/config_proxy.h" |
7c673cae FG |
27 | #include "log/Log.h" |
28 | ||
29 | TEST(CephContext, do_command) | |
30 | { | |
31 | CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); | |
32 | ||
33 | cct->_conf->cluster = "ceph"; | |
34 | ||
35 | string key("key"); | |
36 | string value("value"); | |
11fdf7f2 | 37 | cct->_conf.set_val(key.c_str(), value.c_str()); |
7c673cae FG |
38 | cmdmap_t cmdmap; |
39 | cmdmap["var"] = key; | |
40 | ||
41 | { | |
9f95a23c | 42 | stringstream ss; |
7c673cae | 43 | bufferlist out; |
9f95a23c TL |
44 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); |
45 | cct->do_command("config get", cmdmap, f.get(), ss, &out); | |
46 | f->flush(out); | |
7c673cae FG |
47 | string s(out.c_str(), out.length()); |
48 | EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s); | |
49 | } | |
50 | ||
51 | { | |
9f95a23c | 52 | stringstream ss; |
7c673cae | 53 | bufferlist out; |
9f95a23c TL |
54 | cmdmap_t bad_cmdmap; // no 'var' field |
55 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); | |
56 | int r = cct->do_command("config get", bad_cmdmap, f.get(), ss, &out); | |
57 | if (r >= 0) { | |
58 | f->flush(out); | |
59 | } | |
7c673cae | 60 | string s(out.c_str(), out.length()); |
9f95a23c TL |
61 | EXPECT_EQ(-EINVAL, r); |
62 | EXPECT_EQ("", s); | |
63 | EXPECT_EQ("", ss.str()); // no error string :/ | |
64 | } | |
65 | { | |
66 | stringstream ss; | |
67 | bufferlist out; | |
68 | cmdmap_t bad_cmdmap; | |
69 | bad_cmdmap["var"] = string("doesnotexist123"); | |
70 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); | |
71 | int r = cct->do_command("config help", bad_cmdmap, f.get(), ss, &out); | |
72 | if (r >= 0) { | |
73 | f->flush(out); | |
74 | } | |
75 | string s(out.c_str(), out.length()); | |
76 | EXPECT_EQ(-ENOENT, r); | |
77 | EXPECT_EQ("", s); | |
78 | EXPECT_EQ("Setting not found: 'doesnotexist123'", ss.str()); | |
7c673cae FG |
79 | } |
80 | ||
31f18b77 | 81 | { |
9f95a23c | 82 | stringstream ss; |
31f18b77 | 83 | bufferlist out; |
9f95a23c TL |
84 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); |
85 | cct->do_command("config diff get", cmdmap, f.get(), ss, &out); | |
86 | f->flush(out); | |
31f18b77 | 87 | string s(out.c_str(), out.length()); |
494da23a | 88 | EXPECT_EQ("<config_diff_get><diff><key><default></default><override>" + value + "</override><final>value</final></key><rbd_default_features><default>61</default><final>61</final></rbd_default_features></diff></config_diff_get>", s); |
31f18b77 | 89 | } |
7c673cae FG |
90 | cct->put(); |
91 | } | |
92 | ||
93 | TEST(CephContext, experimental_features) | |
94 | { | |
95 | CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); | |
96 | ||
97 | cct->_conf->cluster = "ceph"; | |
98 | ||
99 | ASSERT_FALSE(cct->check_experimental_feature_enabled("foo")); | |
100 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
101 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
102 | ||
11fdf7f2 | 103 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 104 | "foo,bar"); |
11fdf7f2 | 105 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
106 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
107 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
108 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
109 | ||
11fdf7f2 | 110 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 111 | "foo bar"); |
11fdf7f2 | 112 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
113 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
114 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
115 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
116 | ||
11fdf7f2 | 117 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 118 | "baz foo"); |
11fdf7f2 | 119 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
120 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
121 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
122 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
123 | ||
11fdf7f2 | 124 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 125 | "*"); |
11fdf7f2 | 126 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
127 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
128 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
129 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
130 | ||
131 | cct->_log->flush(); | |
132 | } | |
133 | ||
134 | /* | |
135 | * Local Variables: | |
136 | * compile-command: "cd ../.. ; | |
137 | * make unittest_context && | |
138 | * valgrind \ | |
139 | * --max-stackframe=20000000 --tool=memcheck \ | |
140 | * ./unittest_context # --gtest_filter=CephContext.* | |
141 | * " | |
142 | * End: | |
143 | */ |