From: Marcin Siodelski Date: Mon, 11 Jan 2021 10:32:34 +0000 (+0100) Subject: [#1402] Function to create ha-reset command X-Git-Tag: Kea-1.9.4~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a154a435fd3c6d99f3406439ab7cb4aff70fd12;p=thirdparty%2Fkea.git [#1402] Function to create ha-reset command Added function to CommandCreator to generate ha-reset command. --- diff --git a/src/hooks/dhcp/high_availability/command_creator.cc b/src/hooks/dhcp/high_availability/command_creator.cc index ff12e6be55..2fa8a1ff25 100644 --- a/src/hooks/dhcp/high_availability/command_creator.cc +++ b/src/hooks/dhcp/high_availability/command_creator.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -38,6 +38,13 @@ CommandCreator::createDHCPEnable(const HAServerType& server_type) { return (command); } +ConstElementPtr +CommandCreator::createHAReset(const HAServerType& server_type) { + ConstElementPtr command = config::createCommand("ha-reset"); + insertService(command, server_type); + return (command); +} + ConstElementPtr CommandCreator::createHeartbeat(const HAServerType& server_type) { ConstElementPtr command = config::createCommand("ha-heartbeat"); diff --git a/src/hooks/dhcp/high_availability/command_creator.h b/src/hooks/dhcp/high_availability/command_creator.h index 54a4fcf614..e9ce338d4a 100644 --- a/src/hooks/dhcp/high_availability/command_creator.h +++ b/src/hooks/dhcp/high_availability/command_creator.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -30,10 +30,18 @@ public: /// @brief Creates dhcp-enable command for DHCP server. /// + /// @param server_type type of the DHCP server, i.e. v4 or v6. /// @return Pointer to the JSON representation of the command. static data::ConstElementPtr createDHCPEnable(const HAServerType& server_type); + /// @brief Creates ha-reset command. + /// + /// @param server_type type of the DHCP server, i.e. v4 or v6. + /// @return Pointer to the JSON representation of the command. + static data::ConstElementPtr + createHAReset(const HAServerType& server_type); + /// @brief Creates ha-heartbeat command for DHCP server. /// /// @return Pointer to the JSON representation of the command. diff --git a/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc b/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc index 393ef7788d..406c4290eb 100644 --- a/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2021 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -170,6 +170,12 @@ TEST(CommandCreatorTest, createDHCPEnable4) { ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp4")); } +// This test verifies that the ha-reset command sent to DHCPv4 server is correct. +TEST(CommandCreatorTest, createHAReset4) { + ConstElementPtr command = CommandCreator::createHAReset(HAServerType::DHCPv4); + ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-reset", "dhcp4")); +} + // This test verifies that the ha-heartbeat command is correct. TEST(CommandCreatorTest, createHeartbeat4) { ConstElementPtr command = CommandCreator::createHeartbeat(HAServerType::DHCPv4); @@ -281,6 +287,14 @@ TEST(CommandCreatorTest, createDHCPEnable6) { ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "dhcp-enable", "dhcp6")); } +// This test verifies that the ha-reset command sent to DHCPv6 server is correct. +TEST(CommandCreatorTest, createHAReset6) { + ConstElementPtr command = CommandCreator::createHAReset(HAServerType::DHCPv6); + ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-reset", "dhcp6")); +} + +// This test verifies that the command generated for the lease update +// is correct. TEST(CommandCreatorTest, createLease6Update) { ConstElementPtr command = CommandCreator::createLease6Update(*createLease6()); ConstElementPtr arguments;