mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-29 13:07:50 +00:00
[#93,!63] Implemented getHost() and getPort() MySQL backend functions.
This commit is contained in:
parent
d831078ac7
commit
78a457e633
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user