diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-09-18 13:34:55 +0200 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-10-03 20:04:37 +0200 |
commit | b116338663406107b6d3160a34e0f988942ca82e (patch) | |
tree | 0bbe29ff5d3f935a5c5796a1663630a68f788e59 | |
parent | [#3536] removed empty line in getDBVersions (diff) | |
download | kea-b116338663406107b6d3160a34e0f988942ca82e.tar.xz kea-b116338663406107b6d3160a34e0f988942ca82e.zip |
[#3536] refactor getDBVersions
-rw-r--r-- | src/bin/dhcp4/dhcp4_srv.cc | 16 | ||||
-rw-r--r-- | src/bin/dhcp6/dhcp6_srv.cc | 16 | ||||
-rw-r--r-- | src/lib/dhcpsrv/host_data_source_factory.cc | 12 | ||||
-rw-r--r-- | src/lib/dhcpsrv/host_data_source_factory.h | 2 | ||||
-rw-r--r-- | src/lib/dhcpsrv/lease_mgr_factory.cc | 12 | ||||
-rw-r--r-- | src/lib/dhcpsrv/lease_mgr_factory.h | 2 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc | 9 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc | 22 |
8 files changed, 55 insertions, 36 deletions
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 14929c54ac..6fe52144d8 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -5018,14 +5018,18 @@ Dhcpv4Srv::getVersion(bool extended) { tmp << "- " << Logger::getVersion() << endl; tmp << "- " << CryptoLink::getVersion(); auto info = LeaseMgrFactory::getDBVersions(); - if (!info.empty()) { - tmp << endl <<"lease backends:" << endl; - tmp << info; + if (info.size()) { + tmp << endl << "lease backends:"; + for (auto const& version : info) { + tmp << endl << "- " << version; + } } info = HostDataSourceFactory::getDBVersions(); - if (!info.empty()) { - tmp << endl << "host backends:" << endl; - tmp << info; + if (info.size()) { + tmp << endl << "host backends:"; + for (auto const& version : info) { + tmp << endl << "- " << version; + } } // @todo: more details about database runtime } diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 003ddc514b..3813ecf11c 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -4695,14 +4695,18 @@ Dhcpv6Srv::getVersion(bool extended) { tmp << "- " << Logger::getVersion() << endl; tmp << "- " << CryptoLink::getVersion(); auto info = LeaseMgrFactory::getDBVersions(); - if (!info.empty()) { - tmp << endl <<"lease backends:" << endl; - tmp << info; + if (info.size()) { + tmp << endl << "lease backends:"; + for (auto const& version : info) { + tmp << endl << "- " << version; + } } info = HostDataSourceFactory::getDBVersions(); - if (!info.empty()) { - tmp << endl << "host backends:" << endl; - tmp << info; + if (info.size()) { + tmp << endl << "host backends:"; + for (auto const& version : info) { + tmp << endl << "- " << version; + } } // @todo: more details about database runtime } diff --git a/src/lib/dhcpsrv/host_data_source_factory.cc b/src/lib/dhcpsrv/host_data_source_factory.cc index 35f72168c0..446ccc11d0 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.cc +++ b/src/lib/dhcpsrv/host_data_source_factory.cc @@ -179,21 +179,17 @@ HostDataSourceFactory::logRegistered() { .arg(txt.str()); } -std::string +std::list<std::string> HostDataSourceFactory::getDBVersions() { - std::stringstream txt; - + std::list<std::string> result; for (auto const& x : map_) { auto version = x.second.second(); - if (!txt.str().empty() && !version.empty()) { - txt << endl; - } if (!version.empty()) { - txt << "- " << version; + result.push_back(version); } } - return (txt.str()); + return (result); } } // namespace dhcp diff --git a/src/lib/dhcpsrv/host_data_source_factory.h b/src/lib/dhcpsrv/host_data_source_factory.h index 22609421e2..ba7fa81dc7 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.h +++ b/src/lib/dhcpsrv/host_data_source_factory.h @@ -145,7 +145,7 @@ public: static void logRegistered(); /// @brief Return extended version info for registered backends. - static std::string getDBVersions(); + static std::list<std::string> getDBVersions(); private: /// @brief Factory map diff --git a/src/lib/dhcpsrv/lease_mgr_factory.cc b/src/lib/dhcpsrv/lease_mgr_factory.cc index b619a5611d..28936cf321 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.cc +++ b/src/lib/dhcpsrv/lease_mgr_factory.cc @@ -196,21 +196,17 @@ LeaseMgrFactory::logRegistered() { .arg(txt.str()); } -std::string +std::list<std::string> LeaseMgrFactory::getDBVersions() { - std::stringstream txt; - + std::list<std::string> result; for (auto const& x : map_) { auto version = x.second.second(); - if (!txt.str().empty() && !version.empty()) { - txt << endl; - } if (!version.empty()) { - txt << "- " << version; + result.push_back(version); } } - return (txt.str()); + return (result); } } // namespace dhcp diff --git a/src/lib/dhcpsrv/lease_mgr_factory.h b/src/lib/dhcpsrv/lease_mgr_factory.h index fdf6934e21..ba8ea7bede 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.h +++ b/src/lib/dhcpsrv/lease_mgr_factory.h @@ -154,7 +154,7 @@ public: static void logRegistered(); /// @brief Return extended version info for registered backends. - static std::string getDBVersions(); + static std::list<std::string> getDBVersions(); private: /// @brief Hold pointer to lease manager diff --git a/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc b/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc index eaefd7a2eb..4485a496b1 100644 --- a/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc @@ -193,11 +193,16 @@ TEST_F(HostDataSourceFactoryTest, multiple) { EXPECT_TRUE(registerFactory2()); EXPECT_NO_THROW(HostDataSourceFactory::add(sources_, "type=mem2")); - EXPECT_EQ("- version 2", HostDataSourceFactory::getDBVersions()); + std::list<std::string> expected; + expected.push_back("version 2"); + EXPECT_EQ(expected, HostDataSourceFactory::getDBVersions()); EXPECT_TRUE(registerFactory()); - EXPECT_EQ("- version 1\n- version 2", HostDataSourceFactory::getDBVersions()); + expected.clear(); + expected.push_back("version 1"); + expected.push_back("version 2"); + EXPECT_EQ(expected, HostDataSourceFactory::getDBVersions()); // Delete them EXPECT_TRUE(HostDataSourceFactory::del(sources_, "mem1")); diff --git a/src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc index bc7161faa5..bb22484cf0 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_factory_unittest.cc @@ -220,11 +220,18 @@ TEST_F(LeaseMgrFactoryTest, multipleV4) { EXPECT_TRUE(LeaseMgrFactory::haveInstance()); EXPECT_EQ(LeaseMgrFactory::instance().getType(), "mem2"); - EXPECT_EQ("- version 2\n- Memfile backend 3.0", LeaseMgrFactory::getDBVersions()); + std::list<std::string> expected; + expected.push_back("version 2"); + expected.push_back("Memfile backend 3.0"); + EXPECT_EQ(expected, LeaseMgrFactory::getDBVersions()); EXPECT_TRUE(registerFactory()); - EXPECT_EQ("- version 1\n- version 2\n- Memfile backend 3.0", LeaseMgrFactory::getDBVersions()); + expected.clear(); + expected.push_back("version 1"); + expected.push_back("version 2"); + expected.push_back("Memfile backend 3.0"); + EXPECT_EQ(expected, LeaseMgrFactory::getDBVersions()); // Delete them EXPECT_NO_THROW(LeaseMgrFactory::destroy()); @@ -247,11 +254,18 @@ TEST_F(LeaseMgrFactoryTest, multipleV6) { EXPECT_TRUE(LeaseMgrFactory::haveInstance()); EXPECT_EQ(LeaseMgrFactory::instance().getType(), "mem2"); - EXPECT_EQ("- version 2\n- Memfile backend 5.0", LeaseMgrFactory::getDBVersions()); + std::list<std::string> expected; + expected.push_back("version 2"); + expected.push_back("Memfile backend 5.0"); + EXPECT_EQ(expected, LeaseMgrFactory::getDBVersions()); EXPECT_TRUE(registerFactory()); - EXPECT_EQ("- version 1\n- version 2\n- Memfile backend 5.0", LeaseMgrFactory::getDBVersions()); + expected.clear(); + expected.push_back("version 1"); + expected.push_back("version 2"); + expected.push_back("Memfile backend 5.0"); + EXPECT_EQ(expected, LeaseMgrFactory::getDBVersions()); // Delete them EXPECT_NO_THROW(LeaseMgrFactory::destroy()); |