diff options
author | Sage Weil <sage@newdream.net> | 2021-11-18 00:02:29 +0100 |
---|---|---|
committer | Matan Breizman <mbreizma@redhat.com> | 2023-10-16 14:18:07 +0200 |
commit | b039f8e1e74d956c8a30d0c3c7d43316a7df5b8c (patch) | |
tree | affb9375dd7417b340bf81bc3c0be8d192c91dc5 /src/test/mon | |
parent | mon/ConfigMonitor: clean up pending_* clear()s (diff) | |
download | ceph-b039f8e1e74d956c8a30d0c3c7d43316a7df5b8c.tar.xz ceph-b039f8e1e74d956c8a30d0c3c7d43316a7df5b8c.zip |
test/mon: add unittest_config_map
Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit fe3a1dad9a74f89ed6d50a628ca739dddee75523)
Diffstat (limited to 'src/test/mon')
-rw-r--r-- | src/test/mon/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/test/mon/test_config_map.cc | 143 |
2 files changed, 150 insertions, 0 deletions
diff --git a/src/test/mon/CMakeLists.txt b/src/test/mon/CMakeLists.txt index 943ca99a3fe..8c271407e98 100644 --- a/src/test/mon/CMakeLists.txt +++ b/src/test/mon/CMakeLists.txt @@ -18,6 +18,13 @@ add_executable(ceph_test_mon_msg ) target_link_libraries(ceph_test_mon_msg os osdc global ${UNITTEST_LIBS}) +# unittest_config_map +add_executable(unittest_config_map + test_config_map.cc + ) +add_ceph_unittest(unittest_config_map) +target_link_libraries(unittest_config_map mon global) + # unittest_mon_moncap add_executable(unittest_mon_moncap moncap.cc diff --git a/src/test/mon/test_config_map.cc b/src/test/mon/test_config_map.cc new file mode 100644 index 00000000000..ab148a10bca --- /dev/null +++ b/src/test/mon/test_config_map.cc @@ -0,0 +1,143 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "mon/ConfigMap.h" + +#include <iostream> +#include <string> +#include "crush/CrushWrapper.h" +#include "common/ceph_context.h" +#include "global/global_context.h" +#include "gtest/gtest.h" + + +TEST(ConfigMap, parse_key) +{ + ConfigMap cm; + { + std::string name, who; + cm.parse_key("global/foo", &name, &who); + ASSERT_EQ("foo", name); + ASSERT_EQ("global", who); + } + { + std::string name, who; + cm.parse_key("mon/foo", &name, &who); + ASSERT_EQ("foo", name); + ASSERT_EQ("mon", who); + } + { + std::string name, who; + cm.parse_key("mon.a/foo", &name, &who); + ASSERT_EQ("foo", name); + ASSERT_EQ("mon.a", who); + } + { + std::string name, who; + cm.parse_key("mon.a/mgr/foo", &name, &who); + ASSERT_EQ("mgr/foo", name); + ASSERT_EQ("mon.a", who); + } + { + std::string name, who; + cm.parse_key("mon.a/a=b/foo", &name, &who); + ASSERT_EQ("foo", name); + ASSERT_EQ("mon.a/a=b", who); + } + { + std::string name, who; + cm.parse_key("mon.a/a=b/c=d/foo", &name, &who); + ASSERT_EQ("foo", name); + ASSERT_EQ("mon.a/a=b/c=d", who); + } +} + +TEST(ConfigMap, add_option) +{ + ConfigMap cm; + auto cct = new CephContext(CEPH_ENTITY_TYPE_MON); + int r; + + r = cm.add_option( + cct, "foo", "global", "fooval", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.global.options.size()); + + r = cm.add_option( + cct, "foo", "mon", "fooval", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.by_type.size()); + ASSERT_EQ(1, cm.by_type["mon"].options.size()); + + r = cm.add_option( + cct, "foo", "mon.a", "fooval", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.by_id.size()); + ASSERT_EQ(1, cm.by_id["mon.a"].options.size()); +} + + +TEST(ConfigMap, result_sections) +{ + ConfigMap cm; + auto cct = new CephContext(CEPH_ENTITY_TYPE_MON); + auto crush = new CrushWrapper; + crush->finalize(); + + int r; + + r = cm.add_option( + cct, "foo", "global", "g", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.global.options.size()); + + r = cm.add_option( + cct, "foo", "mon", "m", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.by_type.size()); + ASSERT_EQ(1, cm.by_type["mon"].options.size()); + + r = cm.add_option( + cct, "foo", "mon.a", "a", + [&](const std::string& name) { + return nullptr; + }); + ASSERT_EQ(0, r); + ASSERT_EQ(1, cm.by_id.size()); + ASSERT_EQ(1, cm.by_id["mon.a"].options.size()); + + EntityName n; + n.set(CEPH_ENTITY_TYPE_MON, "a"); + auto c = cm.generate_entity_map( + n, {}, crush, "none", nullptr); + ASSERT_EQ(1, c.size()); + ASSERT_EQ("a", c["foo"]); + + n.set(CEPH_ENTITY_TYPE_MON, "b"); + c = cm.generate_entity_map( + n, {}, crush, "none", nullptr); + ASSERT_EQ(1, c.size()); + ASSERT_EQ("m", c["foo"]); + + n.set(CEPH_ENTITY_TYPE_MDS, "c"); + c = cm.generate_entity_map( + n, {}, crush, "none", nullptr); + ASSERT_EQ(1, c.size()); + ASSERT_EQ("g", c["foo"]); +} + |