Commit 4f2df8c3 authored by Francis Dupont's avatar Francis Dupont Committed by Marcin Siodelski

[#1041] Augmented HA report

parent 5c64cab2
{
"avail": "1.7.3",
"brief": [
"This command returns server runtime informations.",
"This command does not take any parameters."
"This command returns server runtime information.",
"It takes no arguments."
],
"cmd-syntax": [
"{",
......@@ -16,7 +16,9 @@
" \"result\": 0,",
" \"arguments\": {",
" \"pid\": 1234,",
" \"uptime\": 59",
" \"uptime\": 59,",
" \"reload\": 10,",
" ...",
" }",
"}"
],
......
......@@ -1031,13 +1031,23 @@ TEST_F(CtrlChannelDhcpv4SrvTest, serverTagGet) {
TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) {
createUnixChannelServer();
std::string response;
std::string response_txt;
// Send the version-get command
sendUnixCommand("{ \"command\": \"status-get\" }", response);
EXPECT_TRUE(response.find("\"result\": 0") != string::npos);
EXPECT_TRUE(response.find("\"pid\": ") != string::npos);
EXPECT_TRUE(response.find("\"uptime\": ") != string::npos);
sendUnixCommand("{ \"command\": \"status-get\" }", response_txt);
ConstElementPtr response;
ASSERT_NO_THROW(response = Element::fromJSON(response_txt));
ASSERT_TRUE(response);
ASSERT_EQ(Element::map, response->getType());
EXPECT_EQ(2, response->size());
ConstElementPtr result = response->get("result");
ASSERT_TRUE(result);
ASSERT_EQ(Element::integer, result->getType());
EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType());
EXPECT_TRUE(arguments->contains("pid"));
EXPECT_TRUE(arguments->contains("uptime"));
}
// This test verifies that the DHCP server handles config-backend-pull command
......
......@@ -923,13 +923,23 @@ TEST_F(CtrlChannelDhcpv6SrvTest, getVersion) {
TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) {
createUnixChannelServer();
std::string response;
std::string response_txt;
// Send the version-get command
sendUnixCommand("{ \"command\": \"status-get\" }", response);
EXPECT_TRUE(response.find("\"result\": 0") != string::npos);
EXPECT_TRUE(response.find("\"pid\": ") != string::npos);
EXPECT_TRUE(response.find("\"uptime\": ") != string::npos);
sendUnixCommand("{ \"command\": \"status-get\" }", response_txt);
ConstElementPtr response;
ASSERT_NO_THROW(response = Element::fromJSON(response_txt));
ASSERT_TRUE(response);
ASSERT_EQ(Element::map, response->getType());
EXPECT_EQ(2, response->size());
ConstElementPtr result = response->get("result");
ASSERT_TRUE(result);
ASSERT_EQ(Element::integer, result->getType());
EXPECT_EQ(0, result->intValue());
ConstElementPtr arguments = response->get("arguments");
ASSERT_EQ(Element::map, arguments->getType());
EXPECT_TRUE(arguments->contains("pid"));
EXPECT_TRUE(arguments->contains("uptime"));
}
// This test verifies that the DHCP server handles server-tag-get command
......
......@@ -274,23 +274,11 @@ HAImpl::commandProcessed(hooks::CalloutHandle& callout_handle) {
if (!resp_args || (resp_args->getType() != Element::map)) {
return;
}
// Add the ha state to arguments.
// Add the ha servers info to arguments.
ElementPtr mutable_resp_args =
boost::const_pointer_cast<Element>(resp_args);
int state = service_->getCurrState();
try {
mutable_resp_args->set("ha-state",
Element::create(stateToString(state)));
} catch (const std::exception&) {
return;
}
state = service_->getPartnerState();
try {
mutable_resp_args->set("ha-partner-state",
Element::create(stateToString(state)));
} catch (const std::exception&) {
return;
}
ConstElementPtr ha_servers = service_->commandProcessed();
mutable_resp_args->set("ha-servers", ha_servers);
}
}
......@@ -425,6 +413,5 @@ HAImpl::continueHandler(hooks::CalloutHandle& callout_handle) {
callout_handle.setArgument("response", response);
}
} // end of namespace isc::ha
} // end of namespace isc
......@@ -118,7 +118,8 @@ public:
/// service is enabled in a state for which this is not allowed, e.g.
/// waiting, syncing etc. We don't want to rely on the HA partner to do
/// a correct thing in that respect.
/// It too adds the HA state to "status-get" commands.
/// It too adds the HA servers information to "status-get" command
/// responses by calling @c HAService::commandProcessed.
///
/// @param callout_handle Callout handle provided to the callout.
void commandProcessed(hooks::CalloutHandle& callout_handle);
......
......@@ -952,6 +952,53 @@ HAService::logFailedLeaseUpdates(const PktPtr& query,
log_proc(query, args, "failed-leases", HA_LEASE_UPDATE_CREATE_UPDATE_FAILED_ON_PEER);
}
ConstElementPtr
HAService::commandProcessed() const {
ElementPtr ha_servers = Element::createMap();
// Local part
ElementPtr local = Element::createMap();
HAConfig::PeerConfig::Role role;
role = config_->getThisServerConfig()->getRole();
std::string role_txt = HAConfig::PeerConfig::roleToString(role);
local->set("role", Element::create(role_txt));
int state = getCurrState();
try {
local->set("state", Element::create(stateToString(state)));
} catch (const std::exception&) {
/* ignore errors */
}
std::set<std::string> scopes = query_filter_.getServedScopes();
ElementPtr list = Element::createList();
for (std::string scope : scopes) {
list->add(Element::create(scope));
}
local->set("scopes", list);
ha_servers->set("local", local);
// Remote part
ElementPtr remote = Element::createMap();
try {
role = config_->getFailoverPeerConfig()->getRole();
std::string role_txt = HAConfig::PeerConfig::roleToString(role);
remote->set("role", Element::create(role_txt));
} catch (const std::exception&) {
/* ignore errors */
}
try {
state = getPartnerState();
remote->set("received-state", Element::create(stateToString(state)));
} catch (const std::exception&) {
/* ignore errors */
}
// No current way to get remote scopes.
// Add remote if not empty.
if (remote->size() > 0) {
ha_servers->set("remote", remote);
}
return (ha_servers);
}
ConstElementPtr
HAService::processHeartbeat() {
ElementPtr arguments = Element::createMap();
......
......@@ -507,6 +507,12 @@ public:
/// @return Pointer to the response to the heartbeat.
data::ConstElementPtr processHeartbeat();
/// @brief Processes status-get command and returns a response.
///
/// @c HAImpl::commandProcessed calls this to add HA servers info
/// into the status-get response.
data::ConstElementPtr commandProcessed() const;
protected:
/// @brief Starts asynchronous heartbeat to a peer.
......
......@@ -561,7 +561,12 @@ TEST_F(HAImplTest, statusGet) {
ASSERT_TRUE(got);
std::string expected =
"{ \"arguments\": { \"ha-state\": \"waiting\", \"pid\": 1 }, \"result\": 0 }";
"{ \"arguments\": { "
"\"ha-servers\": { "
"\"local\": { \"role\": \"primary\", \"scopes\": [ ], "
"\"state\": \"waiting\" }, "
"\"remote\": { \"role\": \"secondary\" } }, "
"\"pid\": 1 }, \"result\": 0 }";
EXPECT_EQ(expected, got->str());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment