]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_context.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
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)
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.
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"
31 TEST ( CephContext
, do_command
)
33 CephContext
* cct
= ( new CephContext ( CEPH_ENTITY_TYPE_CLIENT
))-> get ();
35 cct
-> _conf
-> cluster
= "ceph" ;
38 string
value ( "value" );
39 cct
-> _conf
. set_val ( key
. c_str (), value
. c_str ());
46 std :: unique_ptr
< Formatter
> f ( Formatter :: create ( "xml" , "xml" ));
47 cct
-> do_command ( "config get" , cmdmap
, f
. get (), ss
, & out
);
49 string
s ( out
. c_str (), out
. length ());
50 EXPECT_EQ ( "<config_get><key>" + value
+ "</key></config_get>" , s
);
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
);
62 string
s ( out
. c_str (), out
. length ());
63 EXPECT_EQ (- EINVAL
, r
);
65 EXPECT_EQ ( "" , ss
. str ()); // no error string :/
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
);
77 string
s ( out
. c_str (), out
. length ());
78 EXPECT_EQ (- ENOENT
, r
);
80 EXPECT_EQ ( "Setting not found: 'doesnotexist123'" , ss
. str ());
86 std :: unique_ptr
< Formatter
> f ( Formatter :: create ( "xml" , "xml" ));
87 cct
-> do_command ( "config diff get" , cmdmap
, f
. get (), ss
, & 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
);
95 TEST ( CephContext
, experimental_features
)
97 CephContext
* cct
= ( new CephContext ( CEPH_ENTITY_TYPE_CLIENT
))-> get ();
99 cct
-> _conf
-> cluster
= "ceph" ;
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" ));
105 cct
-> _conf
. set_val ( "enable_experimental_unrecoverable_data_corrupting_features" ,
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" ));
112 cct
-> _conf
. set_val ( "enable_experimental_unrecoverable_data_corrupting_features" ,
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" ));
119 cct
-> _conf
. set_val ( "enable_experimental_unrecoverable_data_corrupting_features" ,
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" ));
126 cct
-> _conf
. set_val ( "enable_experimental_unrecoverable_data_corrupting_features" ,
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" ));
138 * compile-command: "cd ../.. ;
139 * make unittest_context &&
141 * --max-stackframe=20000000 --tool=memcheck \
142 * ./unittest_context # --gtest_filter=CephContext.*