Commit 4753ad3c authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[master] Unit-test fixes after trac3987 merge.

parent cac05c16
......@@ -274,6 +274,8 @@ Dhcpv4Srv::~Dhcpv4Srv() {
IfaceMgr::instance().closeSockets();
// The lease manager was instantiated during DHCPv4Srv configuration,
// so we should clean up after ourselves.
LeaseMgrFactory::destroy();
}
......
......@@ -89,7 +89,8 @@ Dhcpv4SrvTest::acquireLease(Dhcp4Client& client) {
}
void
Dhcpv4SrvTest::acquireAndDecline(const std::string& hw_address_1,
Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
const std::string& hw_address_1,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
......@@ -101,7 +102,7 @@ Dhcpv4SrvTest::acquireAndDecline(const std::string& hw_address_1,
// Ok, do the normal lease aquisition.
CfgMgr::instance().clear();
Dhcp4Client client(Dhcp4Client::SELECTING);
// Configure DHCP server.
configure(DECLINE_CONFIGS[0], *client.getServer());
// Explicitly set the client id.
......@@ -204,7 +205,8 @@ public:
// This test checks that the client can acquire and decline the lease.
TEST_F(DeclineTest, declineNoIdentifierChange) {
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
}
......@@ -215,7 +217,8 @@ TEST_F(DeclineTest, declineNoIdentifierChange) {
// client identifier.
// - The server successfully declines the lease.
TEST_F(DeclineTest, declineHWAddressOnly) {
acquireAndDecline("01:02:03:04:05:06", "",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "",
"01:02:03:04:05:06", "",
SHOULD_PASS);
}
......@@ -226,7 +229,8 @@ TEST_F(DeclineTest, declineHWAddressOnly) {
// client identifier.
// - The server successfully declines the lease.
TEST_F(DeclineTest, declineNoClientId) {
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "",
SHOULD_PASS);
}
......@@ -238,7 +242,8 @@ TEST_F(DeclineTest, declineNoClientId) {
// - The server identifies the lease using HW address and declines
// this lease.
TEST_F(DeclineTest, declineNoClientId2) {
acquireAndDecline("01:02:03:04:05:06", "",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
}
......@@ -249,7 +254,8 @@ TEST_F(DeclineTest, declineNoClientId2) {
// client identifier.
// - The server should not remove the lease.
TEST_F(DeclineTest, declineNonMatchingClientId) {
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:15:16",
SHOULD_FAIL);
}
......@@ -261,7 +267,8 @@ TEST_F(DeclineTest, declineNonMatchingClientId) {
// - The server uses client identifier to find the client's lease and
// declines it.
TEST_F(DeclineTest, declineNonMatchingHWAddress) {
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"06:06:06:06:06:06", "12:14",
SHOULD_PASS);
}
......
......@@ -213,6 +213,11 @@ public:
using Dhcpv4Srv::alloc_engine_;
};
// We need to pass one reference to the Dhcp4Client, which is defined in
// dhcp4_client.h. That header includes this file. To avoid circular
// dependencies, we use forward declaration here.
class Dhcp4Client;
class Dhcpv4SrvTest : public ::testing::Test {
public:
......@@ -427,6 +432,7 @@ public:
/// @brief Tests if the acquired lease is or is not declined.
///
/// @param client Dhcp4Client instance
/// @param hw_address_1 HW Address to be used to acquire the lease.
/// @param client_id_1 Client id to be used to acquire the lease.
/// @param hw_address_2 HW Address to be used to decline the lease.
......@@ -434,7 +440,8 @@ public:
/// @param expected_result SHOULD_PASS if the lease is expected to
/// be successfully declined, or SHOULD_FAIL if the lease is expected
/// to not be declined.
void acquireAndDecline(const std::string& hw_address_1,
void acquireAndDecline(Dhcp4Client& client,
const std::string& hw_address_1,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
......
......@@ -15,6 +15,7 @@
#include <config.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/dhcp4_client.h>
#include <dhcp4/json_config_parser.h>
#include <cc/command_interpreter.h>
#include <config/command_mgr.h>
......@@ -1485,7 +1486,8 @@ TEST_F(HooksDhcpv4SrvTest, HooksDecline) {
"lease4_decline", lease4_decline_callout));
// Conduct the actual DORA + Decline.
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
......@@ -1528,7 +1530,8 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineDrop) {
// Conduct the actual DORA + Decline. The DECLINE should fail, as the
// hook will set the status to DROP.
acquireAndDecline("01:02:03:04:05:06", "12:14",
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_FAIL);
......
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