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
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
#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>
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) {