]> git.proxmox.com Git - ceph.git/blame_incremental - ceph/src/test/common/test_context.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / common / test_context.cc
... / ...
CommitLineData
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_proxy.h"
27#include "log/Log.h"
28
29using namespace std;
30
31TEST(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");
39 cct->_conf.set_val(key.c_str(), value.c_str());
40 cmdmap_t cmdmap;
41 cmdmap["var"] = key;
42
43 {
44 stringstream ss;
45 bufferlist out;
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);
49 string s(out.c_str(), out.length());
50 EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s);
51 }
52
53 {
54 stringstream ss;
55 bufferlist out;
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 }
62 string s(out.c_str(), out.length());
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());
81 }
82
83 {
84 stringstream ss;
85 bufferlist out;
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);
89 string s(out.c_str(), out.length());
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);
91 }
92 cct->put();
93}
94
95TEST(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
105 cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features",
106 "foo,bar");
107 cct->_conf.apply_changes(&cout);
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
112 cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features",
113 "foo bar");
114 cct->_conf.apply_changes(&cout);
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
119 cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features",
120 "baz foo");
121 cct->_conf.apply_changes(&cout);
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
126 cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features",
127 "*");
128 cct->_conf.apply_changes(&cout);
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 */