From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/test/common/test_context.cc | 143 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/test/common/test_context.cc (limited to 'src/test/common/test_context.cc') diff --git a/src/test/common/test_context.cc b/src/test/common/test_context.cc new file mode 100644 index 000000000..6b00f61c1 --- /dev/null +++ b/src/test/common/test_context.cc @@ -0,0 +1,143 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 Cloudwatt + * + * Author: Loic Dachary + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library Public License for more details. + * + * + */ +#include "gtest/gtest.h" +#include "include/types.h" +#include "include/msgr.h" +#include "common/ceph_context.h" +#include "common/config_proxy.h" +#include "log/Log.h" + +TEST(CephContext, do_command) +{ + CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); + + cct->_conf->cluster = "ceph"; + + string key("key"); + string value("value"); + cct->_conf.set_val(key.c_str(), value.c_str()); + cmdmap_t cmdmap; + cmdmap["var"] = key; + + { + stringstream ss; + bufferlist out; + std::unique_ptr f(Formatter::create("xml", "xml")); + cct->do_command("config get", cmdmap, f.get(), ss, &out); + f->flush(out); + string s(out.c_str(), out.length()); + EXPECT_EQ("" + value + "", s); + } + + { + stringstream ss; + bufferlist out; + cmdmap_t bad_cmdmap; // no 'var' field + std::unique_ptr f(Formatter::create("xml", "xml")); + int r = cct->do_command("config get", bad_cmdmap, f.get(), ss, &out); + if (r >= 0) { + f->flush(out); + } + string s(out.c_str(), out.length()); + EXPECT_EQ(-EINVAL, r); + EXPECT_EQ("", s); + EXPECT_EQ("", ss.str()); // no error string :/ + } + { + stringstream ss; + bufferlist out; + cmdmap_t bad_cmdmap; + bad_cmdmap["var"] = string("doesnotexist123"); + std::unique_ptr f(Formatter::create("xml", "xml")); + int r = cct->do_command("config help", bad_cmdmap, f.get(), ss, &out); + if (r >= 0) { + f->flush(out); + } + string s(out.c_str(), out.length()); + EXPECT_EQ(-ENOENT, r); + EXPECT_EQ("", s); + EXPECT_EQ("Setting not found: 'doesnotexist123'", ss.str()); + } + + { + stringstream ss; + bufferlist out; + std::unique_ptr f(Formatter::create("xml", "xml")); + cct->do_command("config diff get", cmdmap, f.get(), ss, &out); + f->flush(out); + string s(out.c_str(), out.length()); + EXPECT_EQ("" + value + "value6161", s); + } + cct->put(); +} + +TEST(CephContext, experimental_features) +{ + CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); + + cct->_conf->cluster = "ceph"; + + ASSERT_FALSE(cct->check_experimental_feature_enabled("foo")); + ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); + ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); + + cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", + "foo,bar"); + cct->_conf.apply_changes(&cout); + ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); + ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); + ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); + + cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", + "foo bar"); + cct->_conf.apply_changes(&cout); + ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); + ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); + ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); + + cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", + "baz foo"); + cct->_conf.apply_changes(&cout); + ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); + ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); + ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); + + cct->_conf.set_val("enable_experimental_unrecoverable_data_corrupting_features", + "*"); + cct->_conf.apply_changes(&cout); + ASSERT_TRUE(cct->check_experimental_feature_enabled("foo")); + ASSERT_TRUE(cct->check_experimental_feature_enabled("bar")); + ASSERT_TRUE(cct->check_experimental_feature_enabled("baz")); + + cct->_log->flush(); +} + +/* + * Local Variables: + * compile-command: "cd ../.. ; + * make unittest_context && + * valgrind \ + * --max-stackframe=20000000 --tool=memcheck \ + * ./unittest_context # --gtest_filter=CephContext.* + * " + * End: + */ -- cgit v1.2.3