]>
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" | |
26 | #include "common/config.h" | |
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"); | |
37 | cct->_conf->set_val(key.c_str(), value.c_str(), false); | |
38 | cmdmap_t cmdmap; | |
39 | cmdmap["var"] = key; | |
40 | ||
41 | { | |
42 | bufferlist out; | |
43 | cct->do_command("config get", cmdmap, "xml", &out); | |
44 | string s(out.c_str(), out.length()); | |
45 | EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s); | |
46 | } | |
47 | ||
48 | { | |
49 | bufferlist out; | |
50 | cct->do_command("config get", cmdmap, "UNSUPPORTED", &out); | |
51 | string s(out.c_str(), out.length()); | |
52 | EXPECT_EQ("{\n \"key\": \"value\"\n}\n", s); | |
53 | } | |
54 | ||
31f18b77 FG |
55 | { |
56 | bufferlist out; | |
57 | cct->do_command("config diff get", cmdmap, "xml", &out); | |
58 | string s(out.c_str(), out.length()); | |
59 | EXPECT_EQ("<config_diff_get><diff><current><key>" + value + | |
60 | "</key></current><defaults><key></key></defaults></diff></config_diff_get>", s); | |
61 | } | |
7c673cae FG |
62 | cct->put(); |
63 | } | |
64 | ||
65 | TEST(CephContext, experimental_features) | |
66 | { | |
67 | CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); | |
68 | ||
69 | cct->_conf->cluster = "ceph"; | |
70 | ||
71 | ASSERT_FALSE(cct->check_experimental_feature_enabled("foo")); | |
72 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
73 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
74 | ||
75 | cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features", | |
76 | "foo,bar"); | |
77 | cct->_conf->apply_changes(&cout); | |
78 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); | |
79 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
80 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
81 | ||
82 | cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features", | |
83 | "foo bar"); | |
84 | cct->_conf->apply_changes(&cout); | |
85 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); | |
86 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
87 | ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); | |
88 | ||
89 | cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features", | |
90 | "baz foo"); | |
91 | cct->_conf->apply_changes(&cout); | |
92 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); | |
93 | ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); | |
94 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
95 | ||
96 | cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features", | |
97 | "*"); | |
98 | cct->_conf->apply_changes(&cout); | |
99 | ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); | |
100 | ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); | |
101 | ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); | |
102 | ||
103 | cct->_log->flush(); | |
104 | } | |
105 | ||
106 | /* | |
107 | * Local Variables: | |
108 | * compile-command: "cd ../.. ; | |
109 | * make unittest_context && | |
110 | * valgrind \ | |
111 | * --max-stackframe=20000000 --tool=memcheck \ | |
112 | * ./unittest_context # --gtest_filter=CephContext.* | |
113 | * " | |
114 | * End: | |
115 | */ |