]>
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 | ||
20effc67 TL |
29 | using namespace std; |
30 | ||
7c673cae FG |
31 | TEST(CephContext, do_command) |
32 | { | |
33 | CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); | |
34 | ||
35 | cct->_conf->cluster = "ceph"; | |
36 | ||
37 | string key("key"); | |
38 | string value("value"); | |
11fdf7f2 | 39 | cct->_conf.set_val(key.c_str(), value.c_str()); |
7c673cae FG |
40 | cmdmap_t cmdmap; |
41 | cmdmap["var"] = key; | |
42 | ||
43 | { | |
9f95a23c | 44 | stringstream ss; |
7c673cae | 45 | bufferlist out; |
9f95a23c TL |
46 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); |
47 | cct->do_command("config get", cmdmap, f.get(), ss, &out); | |
48 | f->flush(out); | |
7c673cae FG |
49 | string s(out.c_str(), out.length()); |
50 | EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s); | |
51 | } | |
52 | ||
53 | { | |
9f95a23c | 54 | stringstream ss; |
7c673cae | 55 | bufferlist out; |
9f95a23c TL |
56 | cmdmap_t bad_cmdmap; // no 'var' field |
57 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); | |
58 | int r = cct->do_command("config get", bad_cmdmap, f.get(), ss, &out); | |
59 | if (r >= 0) { | |
60 | f->flush(out); | |
61 | } | |
7c673cae | 62 | string s(out.c_str(), out.length()); |
9f95a23c TL |
63 | EXPECT_EQ(-EINVAL, r); |
64 | EXPECT_EQ("", s); | |
65 | EXPECT_EQ("", ss.str()); // no error string :/ | |
66 | } | |
67 | { | |
68 | stringstream ss; | |
69 | bufferlist out; | |
70 | cmdmap_t bad_cmdmap; | |
71 | bad_cmdmap["var"] = string("doesnotexist123"); | |
72 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); | |
73 | int r = cct->do_command("config help", bad_cmdmap, f.get(), ss, &out); | |
74 | if (r >= 0) { | |
75 | f->flush(out); | |
76 | } | |
77 | string s(out.c_str(), out.length()); | |
78 | EXPECT_EQ(-ENOENT, r); | |
79 | EXPECT_EQ("", s); | |
80 | EXPECT_EQ("Setting not found: 'doesnotexist123'", ss.str()); | |
7c673cae FG |
81 | } |
82 | ||
31f18b77 | 83 | { |
9f95a23c | 84 | stringstream ss; |
31f18b77 | 85 | bufferlist out; |
9f95a23c TL |
86 | std::unique_ptr<Formatter> f(Formatter::create("xml", "xml")); |
87 | cct->do_command("config diff get", cmdmap, f.get(), ss, &out); | |
88 | f->flush(out); | |
31f18b77 | 89 | string s(out.c_str(), out.length()); |
20effc67 | 90 | 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><rbd_qos_exclude_ops><default>0</default><final>0</final></rbd_qos_exclude_ops></diff></config_diff_get>", s); |
31f18b77 | 91 | } |
7c673cae FG |
92 | cct->put(); |
93 | } | |
94 | ||
95 | TEST(CephContext, experimental_features) | |
96 | { | |
97 | CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); | |
98 | ||
99 | cct->_conf->cluster = "ceph"; | |
100 | ||
101 | ASSERT_FALSE(cct->check_experimental_feature_enabled("foo")); | |
102 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
103 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
104 | ||
11fdf7f2 | 105 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 106 | "foo,bar"); |
11fdf7f2 | 107 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
108 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
109 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
110 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
111 | ||
11fdf7f2 | 112 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 113 | "foo bar"); |
11fdf7f2 | 114 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
115 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
116 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
117 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
118 | ||
11fdf7f2 | 119 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 120 | "baz foo"); |
11fdf7f2 | 121 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
122 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
123 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
124 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
125 | ||
11fdf7f2 | 126 | cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", |
7c673cae | 127 | "*"); |
11fdf7f2 | 128 | cct->_conf.apply_changes(&cout); |
7c673cae FG |
129 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); |
130 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
131 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
132 | ||
133 | cct->_log->flush(); | |
134 | } | |
135 | ||
136 | /* | |
137 | * Local Variables: | |
138 | * compile-command: "cd ../.. ; | |
139 | * make unittest_context && | |
140 | * valgrind \ | |
141 | * --max-stackframe=20000000 --tool=memcheck \ | |
142 | * ./unittest_context # --gtest_filter=CephContext.* | |
143 | * " | |
144 | * End: | |
145 | */ |