]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#93,!63] Implemented getHost() and getPort() MySQL backend functions.
authorMarcin Siodelski <marcin@isc.org>
Tue, 16 Oct 2018 14:39:50 +0000 (16:39 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 18 Oct 2018 11:35:08 +0000 (13:35 +0200)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc

index eae9f42c851a216e0a2122898d4a7501093dde92..6e6d4e05c28ed8a870023de026c96e9ba30d3c9a 100644 (file)
@@ -2468,17 +2468,17 @@ MySqlConfigBackendDHCPv4::deleteAllGlobalParameters4(const ServerSelector& serve
 
 std::string
 MySqlConfigBackendDHCPv4::getType() const {
-    return ("mysql");
+    return (impl_->getType());
 }
 
 std::string
 MySqlConfigBackendDHCPv4::getHost() const {
-    return ("");
+    return (impl_->getHost());
 }
 
 uint16_t
 MySqlConfigBackendDHCPv4::getPort() const {
-    return (0);
+    return (impl_->getPort());
 }
 
 bool
index b7a4681823f42aff6bf73c71c07c10287205c62f..6c446fd25e3ff5985720f368ea07736f8be6b3fe 100644 (file)
@@ -341,6 +341,35 @@ MySqlConfigBackendImpl::createOptionValueBinding(const OptionDescriptorPtr& opti
     return (MySqlBinding::createNull());
 }
 
+std::string
+MySqlConfigBackendImpl::getType() const {
+    return ("mysql");
+}
+
+std::string
+MySqlConfigBackendImpl::getHost() const {
+    std::string host = "localhost";
+    try {
+        host = conn_.getParameter("host");
+    } catch (...) {
+        // No host parameter. Return localhost as a default.
+    }
+    return (host);
+}
+
+uint16_t
+MySqlConfigBackendImpl::getPort() const {
+    try {
+        std::string sport = conn_.getParameter("port");
+        return (boost::lexical_cast<uint16_t>(sport));
+
+    } catch (...) {
+        // No port parameter or parameter invalid.
+    }
+    return (0);
+}
+
+
 
 } // end of namespace isc::dhcp
 } // end of namespace isc
index b7b0fe85b4bb00860aff091b96ec23d115f6e532..235e6b18c941fe04406157cb65d84542b3d24849 100644 (file)
@@ -248,6 +248,27 @@ public:
                 db::MySqlBinding::createNull());
     }
 
+    /// @brief Returns backend type in the textual format.
+    ///
+    /// @return "mysql".
+    std::string getType() const;
+
+    /// @brief Returns backend host.
+    ///
+    /// This is used by the @c BaseConfigBackendPool to select backend
+    /// when @c BackendSelector is specified.
+    ///
+    /// @return host on which the database is located.
+    std::string getHost() const;
+
+    /// @brief Returns backend port number.
+    ///
+    /// This is used by the @c BaseConfigBackendPool to select backend
+    /// when @c BackendSelector is specified.
+    ///
+    /// @return Port number on which database service is available.
+    uint16_t getPort() const;
+
     /// @brief Creates input binding for option value parameter.
     ///
     /// @param option Option descriptor holding option for which binding is to
index 86e8c3bfc325da1be88c68d6626e40bc14b5d87c..2ba27b0da9d15facba28976505159f070c01fa69 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 #include <mysql_cb_dhcp4.h>
+#include <database/testutils/schema.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/libdhcp++.h>
 #include <dhcp/option4_addrlst.h>
@@ -302,6 +303,38 @@ public:
     boost::shared_ptr<ConfigBackendDHCPv4> cbptr_;
 };
 
+// This test verifies that the expected backend type is returned.
+TEST_F(MySqlConfigBackendDHCPv4Test, getType) {
+    DatabaseConnection::ParameterMap params;
+    params["name"] = "keatest";
+    params["password"] = "keatest";
+    params["user"] = "keatest";
+    ASSERT_NO_THROW(cbptr_.reset(new MySqlConfigBackendDHCPv4(params)));
+    EXPECT_EQ("mysql", cbptr_->getType());
+}
+
+// This test verifies that by default localhost is returned as MySQL connection
+// host.
+TEST_F(MySqlConfigBackendDHCPv4Test, getHost) {
+    DatabaseConnection::ParameterMap params;
+    params["name"] = "keatest";
+    params["password"] = "keatest";
+    params["user"] = "keatest";
+    ASSERT_NO_THROW(cbptr_.reset(new MySqlConfigBackendDHCPv4(params)));
+    EXPECT_EQ("localhost", cbptr_->getHost());
+}
+
+// This test verifies that by default port of 0 is returned as MySQL connection
+// port.
+TEST_F(MySqlConfigBackendDHCPv4Test, getPort) {
+    DatabaseConnection::ParameterMap params;
+    params["name"] = "keatest";
+    params["password"] = "keatest";
+    params["user"] = "keatest";
+    ASSERT_NO_THROW(cbptr_.reset(new MySqlConfigBackendDHCPv4(params)));
+    EXPECT_EQ(0, cbptr_->getPort());
+}
+
 // This test verifies that the global parameter can be added, updated and
 // deleted.
 TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteGlobalParameter4) {