2018-01-09 14:49:14 +01:00
|
|
|
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
|
2012-10-16 16:39:32 +01:00
|
|
|
//
|
2015-12-15 21:37:34 +01:00
|
|
|
// 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
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
#include <config.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
|
|
|
|
#include <asiolink/io_address.h>
|
|
|
|
#include <dhcpsrv/lease_mgr_factory.h>
|
|
|
|
#include <dhcpsrv/mysql_lease_mgr.h>
|
2012-12-18 16:32:34 +01:00
|
|
|
#include <dhcpsrv/tests/test_utils.h>
|
2014-03-10 20:23:39 +01:00
|
|
|
#include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
|
2016-03-01 09:33:06 +01:00
|
|
|
#include <dhcpsrv/testutils/mysql_schema.h>
|
2013-03-15 14:19:42 -04:00
|
|
|
#include <exceptions/exceptions.h>
|
2018-08-29 15:40:02 +02:00
|
|
|
#include <mysql/mysql_connection.h>
|
2012-11-16 11:19:19 +00:00
|
|
|
|
2012-11-16 14:15:45 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2012-12-03 21:23:48 +00:00
|
|
|
#include <algorithm>
|
2012-10-16 16:39:32 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2012-10-20 22:52:25 +01:00
|
|
|
#include <string>
|
2012-11-16 14:15:45 +00:00
|
|
|
#include <utility>
|
2012-10-16 16:39:32 +01:00
|
|
|
|
|
|
|
using namespace isc;
|
|
|
|
using namespace isc::asiolink;
|
2018-08-28 13:09:25 +02:00
|
|
|
using namespace isc::db;
|
2012-10-16 16:39:32 +01:00
|
|
|
using namespace isc::dhcp;
|
2012-12-18 16:32:34 +01:00
|
|
|
using namespace isc::dhcp::test;
|
2012-10-16 16:39:32 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-11-05 19:29:39 +00:00
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Test fixture class for testing MySQL Lease Manager
|
|
|
|
///
|
|
|
|
/// Opens the database prior to each test and closes it afterwards.
|
|
|
|
/// All pending transactions are deleted prior to closure.
|
2012-10-20 22:52:25 +01:00
|
|
|
|
2013-08-14 13:48:19 +02:00
|
|
|
class MySqlLeaseMgrTest : public GenericLeaseMgrTest {
|
2012-10-20 22:52:25 +01:00
|
|
|
public:
|
2018-02-16 22:21:08 +02:00
|
|
|
/// @brief Clears the database and opens connection to it.
|
|
|
|
void initializeTest() {
|
2012-12-03 15:35:36 +00:00
|
|
|
// Ensure schema is the correct one.
|
2015-12-01 20:32:31 +01:00
|
|
|
destroyMySQLSchema();
|
|
|
|
createMySQLSchema();
|
2012-11-21 12:44:18 +00:00
|
|
|
|
2012-12-03 15:35:36 +00:00
|
|
|
// Connect to the database
|
2012-11-08 13:14:19 +00:00
|
|
|
try {
|
2015-12-01 20:32:31 +01:00
|
|
|
LeaseMgrFactory::create(validMySQLConnectionString());
|
2012-11-08 13:14:19 +00:00
|
|
|
} catch (...) {
|
|
|
|
std::cerr << "*** ERROR: unable to open database. The test\n"
|
|
|
|
"*** environment is broken and must be fixed before\n"
|
|
|
|
"*** the MySQL tests will run correctly.\n"
|
|
|
|
"*** The reason for the problem is described in the\n"
|
|
|
|
"*** accompanying exception output.\n";
|
|
|
|
throw;
|
|
|
|
}
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2012-10-24 22:14:42 +01:00
|
|
|
lmptr_ = &(LeaseMgrFactory::instance());
|
|
|
|
}
|
|
|
|
|
2018-02-16 22:21:08 +02:00
|
|
|
/// @brief Destroys the LM and the schema.
|
|
|
|
void destroyTest() {
|
|
|
|
try {
|
|
|
|
lmptr_->rollback();
|
|
|
|
} catch (...) {
|
|
|
|
// Rollback may fail if backend is in read only mode. That's ok.
|
|
|
|
}
|
|
|
|
LeaseMgrFactory::destroy();
|
|
|
|
destroyMySQLSchema();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
|
|
|
/// Deletes everything from the database and opens it.
|
|
|
|
MySqlLeaseMgrTest() {
|
|
|
|
initializeTest();
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Destructor
|
|
|
|
///
|
2012-12-03 15:35:36 +00:00
|
|
|
/// Rolls back all pending transactions. The deletion of lmptr_ will close
|
|
|
|
/// the database. Then reopen it and delete everything created by the test.
|
2012-10-29 19:19:36 +00:00
|
|
|
virtual ~MySqlLeaseMgrTest() {
|
2018-02-16 22:21:08 +02:00
|
|
|
destroyTest();
|
2012-10-29 19:19:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Reopen the database
|
|
|
|
///
|
|
|
|
/// Closes the database and re-open it. Anything committed should be
|
|
|
|
/// visible.
|
2014-03-25 15:53:02 +01:00
|
|
|
///
|
|
|
|
/// Parameter is ignored for MySQL backend as the v4 and v6 leases share
|
|
|
|
/// the same database.
|
|
|
|
void reopen(Universe) {
|
2012-10-24 22:14:42 +01:00
|
|
|
LeaseMgrFactory::destroy();
|
2015-12-01 20:32:31 +01:00
|
|
|
LeaseMgrFactory::create(validMySQLConnectionString());
|
2012-10-24 14:12:06 +01:00
|
|
|
lmptr_ = &(LeaseMgrFactory::instance());
|
2012-10-20 22:52:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check that database can be opened
|
|
|
|
///
|
|
|
|
/// This test checks if the MySqlLeaseMgr can be instantiated. This happens
|
|
|
|
/// only if the database can be opened. Note that this is not part of the
|
|
|
|
/// MySqlLeaseMgr test fixure set. This test checks that the database can be
|
|
|
|
/// opened: the fixtures assume that and check basic operations.
|
2012-10-20 22:52:25 +01:00
|
|
|
TEST(MySqlOpenTest, OpenDatabase) {
|
2012-11-05 19:29:39 +00:00
|
|
|
// Schema needs to be created for the test to work.
|
2016-04-11 15:16:58 -04:00
|
|
|
destroyMySQLSchema(true);
|
2016-04-08 09:43:22 -04:00
|
|
|
createMySQLSchema(true);
|
2012-11-05 19:29:39 +00:00
|
|
|
|
|
|
|
// Check that lease manager open the database opens correctly and tidy up.
|
2016-05-11 20:40:25 +01:00
|
|
|
// If it fails, print the error message.
|
2012-10-24 21:18:13 +01:00
|
|
|
try {
|
2015-12-01 20:32:31 +01:00
|
|
|
LeaseMgrFactory::create(validMySQLConnectionString());
|
2018-02-16 22:21:08 +02:00
|
|
|
EXPECT_NO_THROW((void)LeaseMgrFactory::instance());
|
2012-10-24 21:18:13 +01:00
|
|
|
LeaseMgrFactory::destroy();
|
|
|
|
} catch (const isc::Exception& ex) {
|
|
|
|
FAIL() << "*** ERROR: unable to open database, reason:\n"
|
2012-11-08 13:14:19 +00:00
|
|
|
<< " " << ex.what() << "\n"
|
2012-10-24 21:18:13 +01:00
|
|
|
<< "*** The test environment is broken and must be fixed\n"
|
|
|
|
<< "*** before the MySQL tests will run correctly.\n";
|
|
|
|
}
|
|
|
|
|
2016-05-11 20:40:25 +01:00
|
|
|
// Check that lease manager open the database opens correctly with a longer
|
|
|
|
// timeout. If it fails, print the error message.
|
|
|
|
try {
|
2017-01-20 14:52:54 +01:00
|
|
|
string connection_string = validMySQLConnectionString() + string(" ") +
|
2016-05-11 20:40:25 +01:00
|
|
|
string(VALID_TIMEOUT);
|
|
|
|
LeaseMgrFactory::create(connection_string);
|
|
|
|
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
|
|
|
|
LeaseMgrFactory::destroy();
|
|
|
|
} catch (const isc::Exception& ex) {
|
|
|
|
FAIL() << "*** ERROR: unable to open database, reason:\n"
|
|
|
|
<< " " << ex.what() << "\n"
|
|
|
|
<< "*** The test environment is broken and must be fixed\n"
|
|
|
|
<< "*** before the MySQL tests will run correctly.\n";
|
|
|
|
}
|
|
|
|
|
2012-10-24 14:12:06 +01:00
|
|
|
// Check that attempting to get an instance of the lease manager when
|
|
|
|
// none is set throws an exception.
|
|
|
|
EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager);
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
// Check that wrong specification of backend throws an exception.
|
|
|
|
// (This is really a check on LeaseMgrFactory, but is convenient to
|
|
|
|
// perform here.)
|
2012-10-24 19:34:38 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
|
|
|
NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
|
|
|
|
InvalidParameter);
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2012-10-24 14:12:06 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2012-10-16 16:39:32 +01:00
|
|
|
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
|
2012-10-24 14:12:06 +01:00
|
|
|
InvalidType);
|
2012-10-17 18:37:22 +01:00
|
|
|
|
|
|
|
// Check that invalid login data causes an exception.
|
2012-10-24 14:12:06 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2016-04-11 11:51:15 -04:00
|
|
|
MYSQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
|
2012-10-16 16:39:32 +01:00
|
|
|
DbOpenError);
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2018-05-09 09:52:54 -04:00
|
|
|
#ifndef OS_OSX
|
|
|
|
// Under MacOS, connecting with an invalid host can cause a TCP/IP socket
|
|
|
|
// to be orphaned and never closed. This can interfere with subsequent tests
|
|
|
|
// which attempt to locate and manipulate MySQL client socket descriptor.
|
|
|
|
// In the interests of progress, we'll just avoid this test.
|
2012-10-24 14:12:06 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2016-04-11 11:51:15 -04:00
|
|
|
MYSQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
|
2012-10-16 16:39:32 +01:00
|
|
|
DbOpenError);
|
2018-05-09 09:52:54 -04:00
|
|
|
#endif
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2012-10-24 14:12:06 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2016-04-11 11:51:15 -04:00
|
|
|
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
|
2012-10-16 16:39:32 +01:00
|
|
|
DbOpenError);
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2012-10-24 14:12:06 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2016-04-11 11:51:15 -04:00
|
|
|
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
|
2012-10-16 16:39:32 +01:00
|
|
|
DbOpenError);
|
2018-02-16 22:21:08 +02:00
|
|
|
|
|
|
|
// Check for invalid timeouts
|
2016-05-11 20:40:25 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
|
|
|
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
|
|
|
|
DbInvalidTimeout);
|
2018-02-16 22:21:08 +02:00
|
|
|
|
2016-05-11 20:40:25 +01:00
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
|
|
|
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
|
|
|
|
DbInvalidTimeout);
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-24 19:34:38 +01:00
|
|
|
// Check for missing parameters
|
|
|
|
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
|
2016-04-11 11:51:15 -04:00
|
|
|
MYSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
|
2012-10-24 19:34:38 +01:00
|
|
|
NoDatabaseName);
|
2012-11-05 19:29:39 +00:00
|
|
|
|
|
|
|
// Tidy up after the test
|
2016-04-11 15:16:58 -04:00
|
|
|
destroyMySQLSchema(true);
|
2018-05-02 13:36:02 -04:00
|
|
|
LeaseMgrFactory::destroy();
|
2012-10-18 11:33:51 +01:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check the getType() method
|
|
|
|
///
|
|
|
|
/// getType() returns a string giving the type of the backend, which should
|
|
|
|
/// always be "mysql".
|
2012-11-13 15:43:42 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getType) {
|
2012-11-13 12:14:55 +00:00
|
|
|
EXPECT_EQ(std::string("mysql"), lmptr_->getType());
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check conversion functions
|
|
|
|
///
|
|
|
|
/// The server works using cltt and valid_filetime. In the database, the
|
|
|
|
/// information is stored as expire_time and valid-lifetime, which are
|
|
|
|
/// related by
|
|
|
|
///
|
|
|
|
/// expire_time = cltt + valid_lifetime
|
|
|
|
///
|
|
|
|
/// This test checks that the conversion is correct. It does not check that the
|
|
|
|
/// data is entered into the database correctly, only that the MYSQL_TIME
|
|
|
|
/// structure used for the entry is correctly set up.
|
2012-11-14 14:30:46 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, checkTimeConversion) {
|
2012-10-20 22:52:25 +01:00
|
|
|
const time_t cltt = time(NULL);
|
|
|
|
const uint32_t valid_lft = 86400; // 1 day
|
2012-10-24 21:18:13 +01:00
|
|
|
struct tm tm_expire;
|
|
|
|
MYSQL_TIME mysql_expire;
|
|
|
|
|
|
|
|
// Work out what the broken-down time will be for one day
|
|
|
|
// after the current time.
|
|
|
|
time_t expire_time = cltt + valid_lft;
|
|
|
|
(void) localtime_r(&expire_time, &tm_expire);
|
|
|
|
|
|
|
|
// Convert to the database time
|
2015-11-30 21:26:25 +01:00
|
|
|
MySqlConnection::convertToDatabaseTime(cltt, valid_lft, mysql_expire);
|
2012-10-24 21:18:13 +01:00
|
|
|
|
|
|
|
// Are the times the same?
|
|
|
|
EXPECT_EQ(tm_expire.tm_year + 1900, mysql_expire.year);
|
|
|
|
EXPECT_EQ(tm_expire.tm_mon + 1, mysql_expire.month);
|
|
|
|
EXPECT_EQ(tm_expire.tm_mday, mysql_expire.day);
|
|
|
|
EXPECT_EQ(tm_expire.tm_hour, mysql_expire.hour);
|
|
|
|
EXPECT_EQ(tm_expire.tm_min, mysql_expire.minute);
|
|
|
|
EXPECT_EQ(tm_expire.tm_sec, mysql_expire.second);
|
|
|
|
EXPECT_EQ(0, mysql_expire.second_part);
|
|
|
|
EXPECT_EQ(0, mysql_expire.neg);
|
2012-10-16 16:39:32 +01:00
|
|
|
|
2012-10-20 22:52:25 +01:00
|
|
|
// Convert back
|
|
|
|
time_t converted_cltt = 0;
|
2015-11-30 21:26:25 +01:00
|
|
|
MySqlConnection::convertFromDatabaseTime(mysql_expire, valid_lft, converted_cltt);
|
2012-10-20 22:52:25 +01:00
|
|
|
EXPECT_EQ(cltt, converted_cltt);
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check getName() returns correct database name
|
2012-10-29 19:19:36 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getName) {
|
|
|
|
EXPECT_EQ(std::string("keatest"), lmptr_->getName());
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check that getVersion() returns the expected version
|
2012-11-14 14:30:46 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, checkVersion) {
|
2012-10-18 11:33:51 +01:00
|
|
|
// Check version
|
2012-10-20 22:52:25 +01:00
|
|
|
pair<uint32_t, uint32_t> version;
|
|
|
|
ASSERT_NO_THROW(version = lmptr_->getVersion());
|
2016-06-23 14:32:06 +02:00
|
|
|
EXPECT_EQ(MYSQL_SCHEMA_VERSION_MAJOR, version.first);
|
|
|
|
EXPECT_EQ(MYSQL_SCHEMA_VERSION_MINOR, version.second);
|
2012-10-20 22:52:25 +01:00
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// LEASE4 /////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-12-03 15:35:36 +00:00
|
|
|
/// @brief Basic Lease4 Checks
|
2012-11-23 18:23:21 +00:00
|
|
|
///
|
2012-12-10 11:21:24 +00:00
|
|
|
/// Checks that the addLease, getLease4 (by address) and deleteLease (with an
|
|
|
|
/// IPv4 address) works.
|
2012-11-21 12:44:18 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, basicLease4) {
|
2014-03-06 10:05:19 +00:00
|
|
|
testBasicLease4();
|
|
|
|
}
|
2012-11-21 12:44:18 +00:00
|
|
|
|
2014-05-20 16:01:25 -04:00
|
|
|
/// @brief Check that Lease4 code safely handles invalid dates.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, maxDate4) {
|
|
|
|
testMaxDate4();
|
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
/// @brief Lease4 update tests
|
2013-08-27 16:00:16 +02:00
|
|
|
///
|
2014-03-12 18:58:18 +01:00
|
|
|
/// Checks that we are able to update a lease in the database.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, updateLease4) {
|
|
|
|
testUpdateLease4();
|
2013-08-27 16:00:16 +02:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease4 methods - access by Hardware Address
|
2014-03-06 10:28:46 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1) {
|
|
|
|
testGetLease4HWAddr1();
|
|
|
|
}
|
2012-11-23 12:47:40 +00:00
|
|
|
|
2014-03-06 10:28:46 +00:00
|
|
|
/// @brief Check GetLease4 methods - access by Hardware Address
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2) {
|
|
|
|
testGetLease4HWAddr2();
|
2012-12-03 21:23:48 +00:00
|
|
|
}
|
2012-11-23 12:47:40 +00:00
|
|
|
|
2012-12-03 21:23:48 +00:00
|
|
|
// @brief Get lease4 by hardware address (2)
|
|
|
|
//
|
|
|
|
// Check that the system can cope with getting a hardware address of
|
|
|
|
// any size.
|
2014-03-06 11:13:55 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSize) {
|
|
|
|
testGetLease4HWAddrSize();
|
2012-11-23 12:47:40 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
|
|
|
|
///
|
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
|
/// a combination of hardware address and subnet ID
|
2012-11-23 12:23:17 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
|
2014-03-06 11:13:55 +00:00
|
|
|
testGetLease4HWAddrSubnetId();
|
2012-12-03 21:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @brief Get lease4 by hardware address and subnet ID (2)
|
|
|
|
//
|
|
|
|
// Check that the system can cope with getting a hardware address of
|
|
|
|
// any size.
|
2014-03-06 11:13:55 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSubnetIdSize) {
|
|
|
|
testGetLease4HWAddrSubnetIdSize();
|
|
|
|
}
|
2012-12-03 21:23:48 +00:00
|
|
|
|
2014-03-06 11:13:55 +00:00
|
|
|
// This test was derived from memfile.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
|
|
|
|
testGetLease4ClientId();
|
2012-11-23 12:23:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease4 methods - access by Client ID
|
|
|
|
///
|
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
|
/// the Client ID.
|
2014-03-06 11:13:55 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientId2) {
|
|
|
|
testGetLease4ClientId2();
|
2012-11-21 19:38:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 21:23:48 +00:00
|
|
|
// @brief Get Lease4 by client ID (2)
|
|
|
|
//
|
|
|
|
// Check that the system can cope with a client ID of any size.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSize) {
|
2014-03-06 11:13:55 +00:00
|
|
|
testGetLease4ClientIdSize();
|
2012-12-03 21:23:48 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease4 methods - access by Client ID & Subnet ID
|
|
|
|
///
|
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
|
/// a combination of client and subnet IDs.
|
2012-11-23 13:48:42 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetId) {
|
2014-03-06 11:13:55 +00:00
|
|
|
testGetLease4ClientIdSubnetId();
|
2012-11-23 13:48:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 14:49:14 +01:00
|
|
|
// This test checks that all IPv4 leases for a specified subnet id are returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases4SubnetId) {
|
|
|
|
testGetLeases4SubnetId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test checks that all IPv4 leases are returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases4) {
|
|
|
|
testGetLeases4();
|
|
|
|
}
|
|
|
|
|
2018-06-25 21:47:20 +02:00
|
|
|
// Test that a range of IPv4 leases is returned with paging.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases4Paged) {
|
|
|
|
testGetLeases4Paged();
|
|
|
|
}
|
|
|
|
|
2018-01-13 00:24:41 +01:00
|
|
|
// This test checks that all IPv6 leases for a specified subnet id are returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6SubnetId) {
|
|
|
|
testGetLeases6SubnetId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test checks that all IPv6 leases are returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6) {
|
|
|
|
testGetLeases6();
|
|
|
|
}
|
|
|
|
|
2018-06-26 10:27:07 +02:00
|
|
|
// Test that a range of IPv6 leases is returned with paging.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6Paged) {
|
|
|
|
testGetLeases6Paged();
|
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
/// @brief Basic Lease4 Checks
|
|
|
|
///
|
|
|
|
/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
2018-02-16 22:21:08 +02:00
|
|
|
/// updateLease4() and deleteLease can handle NULL client-id.
|
2014-03-12 18:58:18 +01:00
|
|
|
/// (client-id is optional and may not be present)
|
|
|
|
TEST_F(MySqlLeaseMgrTest, lease4NullClientId) {
|
|
|
|
testLease4NullClientId();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Verify that too long hostname for Lease4 is not accepted.
|
|
|
|
///
|
|
|
|
/// Checks that the it is not possible to create a lease when the hostname
|
|
|
|
/// length exceeds 255 characters.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, lease4InvalidHostname) {
|
|
|
|
testLease4InvalidHostname();
|
|
|
|
}
|
|
|
|
|
2018-02-16 22:21:08 +02:00
|
|
|
/// @brief Check that the expired DHCPv4 leases can be retrieved.
|
|
|
|
///
|
|
|
|
/// This test adds a number of leases to the lease database and marks
|
|
|
|
/// some of them as expired. Then it queries for expired leases and checks
|
|
|
|
/// whether only expired leases are returned, and that they are returned in
|
|
|
|
/// the order from most to least expired. It also checks that the lease
|
|
|
|
/// which is marked as 'reclaimed' is not returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getExpiredLeases4) {
|
|
|
|
testGetExpiredLeases4();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Check that expired reclaimed DHCPv4 leases are removed.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases4) {
|
|
|
|
testDeleteExpiredReclaimedLeases4();
|
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// LEASE6 /////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Test checks whether simple add, get and delete operations are possible
|
|
|
|
// on Lease6
|
|
|
|
TEST_F(MySqlLeaseMgrTest, testAddGetDelete6) {
|
|
|
|
testAddGetDelete6(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Basic Lease6 Checks
|
|
|
|
///
|
|
|
|
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
|
|
|
|
/// IPv6 address) works.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, basicLease6) {
|
|
|
|
testBasicLease6();
|
|
|
|
}
|
|
|
|
|
2014-05-20 16:01:25 -04:00
|
|
|
/// @brief Check that Lease6 code safely handles invalid dates.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, maxDate6) {
|
|
|
|
testMaxDate6();
|
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
/// @brief Verify that too long hostname for Lease6 is not accepted.
|
|
|
|
///
|
|
|
|
/// Checks that the it is not possible to create a lease when the hostname
|
|
|
|
/// length exceeds 255 characters.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, lease6InvalidHostname) {
|
|
|
|
testLease6InvalidHostname();
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease6 methods - access by DUID/IAID
|
|
|
|
///
|
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
2014-03-06 18:07:26 +00:00
|
|
|
/// a combination of DUID and IAID.
|
2013-09-13 10:05:28 -04:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6DuidIaid) {
|
2014-03-06 18:07:26 +00:00
|
|
|
testGetLeases6DuidIaid();
|
2012-11-04 19:57:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 18:07:26 +00:00
|
|
|
// Check that the system can cope with a DUID of allowed size.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6DuidSize) {
|
|
|
|
testGetLeases6DuidSize();
|
2012-12-03 21:23:48 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 10:05:28 -04:00
|
|
|
/// @brief Check that getLease6 methods discriminate by lease type.
|
|
|
|
///
|
|
|
|
/// Adds six leases, two per lease type all with the same duid and iad but
|
|
|
|
/// with alternating subnet_ids.
|
|
|
|
/// It then verifies that all of getLeases6() method variants correctly
|
|
|
|
/// discriminate between the leases based on lease type alone.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, lease6LeaseTypeCheck) {
|
2014-03-06 18:07:26 +00:00
|
|
|
testLease6LeaseTypeCheck();
|
2013-09-13 10:05:28 -04:00
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
|
|
|
|
///
|
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
|
/// a combination of DIUID and IAID.
|
2012-11-21 19:38:26 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
|
2014-03-06 18:07:26 +00:00
|
|
|
testGetLease6DuidIaidSubnetId();
|
2012-11-03 18:26:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 18:58:18 +01:00
|
|
|
// Test checks that getLease6() works with different DUID sizes
|
2012-12-03 21:23:48 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
|
2014-03-06 18:07:26 +00:00
|
|
|
testGetLease6DuidIaidSubnetIdSize();
|
2012-12-03 21:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 17:00:50 +02:00
|
|
|
// @brief check leases could be retrieved by DUID
|
|
|
|
///
|
|
|
|
/// Create leases, add them to backend and verify if it can be queried
|
|
|
|
/// using DUID index
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getLeases6Duid) {
|
|
|
|
testGetLeases6Duid();
|
|
|
|
}
|
|
|
|
|
2012-11-23 18:23:21 +00:00
|
|
|
/// @brief Lease6 update tests
|
|
|
|
///
|
|
|
|
/// Checks that we are able to update a lease in the database.
|
2012-11-14 14:30:46 +00:00
|
|
|
TEST_F(MySqlLeaseMgrTest, updateLease6) {
|
2014-03-06 18:07:26 +00:00
|
|
|
testUpdateLease6();
|
2012-10-24 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:51:03 +02:00
|
|
|
/// @brief DHCPv4 Lease recreation tests
|
|
|
|
///
|
|
|
|
/// Checks that the lease can be created, deleted and recreated with
|
|
|
|
/// different parameters. It also checks that the re-created lease is
|
|
|
|
/// correctly stored in the lease database.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, testRecreateLease4) {
|
|
|
|
testRecreateLease4();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief DHCPv6 Lease recreation tests
|
|
|
|
///
|
|
|
|
/// Checks that the lease can be created, deleted and recreated with
|
|
|
|
/// different parameters. It also checks that the re-created lease is
|
|
|
|
/// correctly stored in the lease database.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, testRecreateLease6) {
|
|
|
|
testRecreateLease6();
|
|
|
|
}
|
|
|
|
|
2014-05-21 08:16:43 -04:00
|
|
|
/// @brief Checks that null DUID is not allowed.
|
2014-11-06 19:40:25 +01:00
|
|
|
TEST_F(MySqlLeaseMgrTest, nullDuid) {
|
2014-05-21 08:16:43 -04:00
|
|
|
testNullDuid();
|
|
|
|
}
|
|
|
|
|
2014-11-06 19:36:46 +01:00
|
|
|
/// @brief Tests whether memfile can store and retrieve hardware addresses
|
|
|
|
TEST_F(MySqlLeaseMgrTest, testLease6Mac) {
|
|
|
|
testLease6MAC();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Tests whether memfile can store and retrieve hardware addresses
|
|
|
|
TEST_F(MySqlLeaseMgrTest, testLease6HWTypeAndSource) {
|
|
|
|
testLease6HWTypeAndSource();
|
|
|
|
}
|
|
|
|
|
2015-09-07 10:47:30 +02:00
|
|
|
/// @brief Check that the expired DHCPv6 leases can be retrieved.
|
|
|
|
///
|
|
|
|
/// This test adds a number of leases to the lease database and marks
|
|
|
|
/// some of them as expired. Then it queries for expired leases and checks
|
|
|
|
/// whether only expired leases are returned, and that they are returned in
|
|
|
|
/// the order from most to least expired. It also checks that the lease
|
|
|
|
/// which is marked as 'reclaimed' is not returned.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, getExpiredLeases6) {
|
|
|
|
testGetExpiredLeases6();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Check that expired reclaimed DHCPv6 leases are removed.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases6) {
|
|
|
|
testDeleteExpiredReclaimedLeases6();
|
|
|
|
}
|
|
|
|
|
2018-02-28 10:48:23 +02:00
|
|
|
/// @brief Verifies that IPv4 lease statistics can be recalculated.
|
2016-08-24 08:50:47 -04:00
|
|
|
TEST_F(MySqlLeaseMgrTest, recountLeaseStats4) {
|
|
|
|
testRecountLeaseStats4();
|
[4294] Memfile and MySql now support recalulating IPv4 lease statistics
src/lib/dhcpsrv/cfg_subnets4.cc
CfgSubnets4::removeStatistics()
- added removal of all lease statistics per subnet, and global declined address
stats
CfgSubnets4::updateStatistics()
- added call to LeaseMgr::recountAddressStats4
src/lib/dhcpsrv/lease.cc
src/lib/dhcpsrv/lease.h
Replaces lease state constants with LeaseState enumeration.
src/lib/dhcpsrv/lease_mgr.cc
src/lib/dhcpsrv/lease_mgr.h
struct AddressStatsRow4 - contains the content of one row of the IPv4
lease statistical data result set
class AddressStatsQuery4 - base class for constructing the IPv4
lease statistical data result set for an IPv4 lease storage
LeaseMgr::recountAddressStats4() - new method which recalculates
per-subnet and global stats for IPv4 leases
LeaseMgr::startAddressStatsQuery4() - new virtual method that fetches
the IPv4 lease statistical data result set
src/lib/dhcpsrv/lease_mgr_factory.h
src/lib/dhcpsrv/lease_mgr_factory.cc
LeaseMgrFactory::haveInstance() - new static method which indicates
whether or not the lease manager singleton exists
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
MemfileAddressStatsQuery4 - Derivation of AddressStatsQuery4, it constructs
the IPv4 lease statistical data by iterating over IPv4 lease storage
Memfile_LeaseMgr::startAddressStatsQuery4() - new virtual method which
creates, starts, and returns a MemfileAddressStatsQuery4
src/lib/dhcpsrv/memfile_lease_storage.h
Added an a per subnet_ID index to IPv4 storage
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
- Added RECOUNT_LEASE4_STATS query
MySqlAddressStatsQuery4 Derivation of AddressStatsQuery4, it constructs
the IPv4 lease statistical data by executing RECOUNT_LEASE4_STATS
MySqlLeaseMgr::startAddressStatsQuery4() - new virtual method which
creates, starts, and returns a MySqlAddressStatsQuery4
src/lib/dhcpsrv/tests/alloc_engine_utils.cc
AllocEngine6Test::AllocEngine6Test()
AllocEngine4Test::AllocEngine4Test()
- moved lease mgr create up above configuration commit
src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc
~CfgMySQLDbAccessTest() - added destruction of lease manager singleton,
otherwise subsequent tests can fail
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
GenericLeaseMgrTest::checkStat() - new method for comparing a stat
GenericLeaseMgrTest::checkAddressStats4() - new method for comparing a list
of stats
GenericLeaseMgrTest::makeLease4() - new method for making a minimal lease
GenericLeaseMgrTest::testRecountAddressStats4() - new method which tests
a lease manager's ability to recalculate the IPv4 lease statistics
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
TEST_F(MemfileLeaseMgrTest, recountAddressStats4) - new test which tests
Memfile_LeaseMgr's ability to recalculate IPv4 lease statistics
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
TEST_F(MySqlLeaseMgrTest, recountAddressStats4) - new test which tests
MySqlLeaseMgr's ability to recalculate IPv4 lease statistics
2016-08-12 14:02:35 -04:00
|
|
|
}
|
|
|
|
|
2018-02-28 10:48:23 +02:00
|
|
|
/// @brief Verifies that IPv6 lease statistics can be recalculated.
|
2016-08-24 08:50:47 -04:00
|
|
|
TEST_F(MySqlLeaseMgrTest, recountLeaseStats6) {
|
|
|
|
testRecountLeaseStats6();
|
2016-08-16 11:13:17 -04:00
|
|
|
}
|
|
|
|
|
2018-02-28 10:48:23 +02:00
|
|
|
// @brief Tests that leases from specific subnet can be removed.
|
2017-08-04 21:00:11 +02:00
|
|
|
TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4) {
|
|
|
|
testWipeLeases4();
|
|
|
|
}
|
|
|
|
|
2018-02-28 10:48:23 +02:00
|
|
|
// @brief Tests that leases from specific subnet can be removed.
|
2017-08-04 21:00:11 +02:00
|
|
|
TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6) {
|
|
|
|
testWipeLeases6();
|
|
|
|
}
|
|
|
|
|
2018-04-06 15:16:24 -04:00
|
|
|
/// @brief Test fixture class for validating @c LeaseMgr using
|
|
|
|
/// MySQL as back end and MySQL connectivity loss.
|
|
|
|
class MySQLLeaseMgrDbLostCallbackTest : public LeaseMgrDbLostCallbackTest {
|
|
|
|
public:
|
|
|
|
virtual void destroySchema() {
|
|
|
|
test::destroyMySQLSchema();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void createSchema() {
|
|
|
|
test::createMySQLSchema();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string validConnectString() {
|
|
|
|
return (test::validMySQLConnectionString());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string invalidConnectString() {
|
2018-05-02 13:36:02 -04:00
|
|
|
return (connectionString(MYSQL_VALID_TYPE, INVALID_NAME, VALID_HOST,
|
2018-04-06 15:16:24 -04:00
|
|
|
VALID_USER, VALID_PASSWORD));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verifies that db lost callback is not invoked on an open failure
|
|
|
|
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailure) {
|
2018-05-02 13:36:02 -04:00
|
|
|
testNoCallbackOnOpenFailure();
|
2018-04-06 15:16:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that loss of connectivity to MySQL is handled correctly.
|
|
|
|
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testDbLostCallback) {
|
|
|
|
testDbLostCallback();
|
|
|
|
}
|
|
|
|
|
2018-05-02 13:36:02 -04:00
|
|
|
// Tests v4 lease stats query variants.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, leaseStatsQuery4) {
|
|
|
|
testLeaseStatsQuery4();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests v6 lease stats query variants.
|
|
|
|
TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6) {
|
|
|
|
testLeaseStatsQuery6();
|
|
|
|
}
|
|
|
|
|
2018-02-16 22:21:08 +02:00
|
|
|
} // namespace
|