summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2018-05-09 17:19:54 +0200
committerThomas Markwalder <tmark@isc.org>2018-05-09 17:19:54 +0200
commit593ddeae138c496fca4dc282e5b54c8bb1dd9546 (patch)
treeff84ae7f66723e73fdb6223e5f2f764b9b5acbce /src/lib/dhcpsrv
parent[master] Added ChangeLog for #5590. (diff)
parent[5586] Addressed further review comments (diff)
downloadkea-593ddeae138c496fca4dc282e5b54c8bb1dd9546.tar.xz
kea-593ddeae138c496fca4dc282e5b54c8bb1dd9546.zip
[master] MySQL support for shared lease stats implemented
Merge branch 'trac5586'
Diffstat (limited to 'src/lib/dhcpsrv')
-rw-r--r--src/lib/dhcpsrv/lease_mgr.h3
-rw-r--r--src/lib/dhcpsrv/memfile_lease_mgr.cc82
-rw-r--r--src/lib/dhcpsrv/mysql_lease_mgr.cc178
-rw-r--r--src/lib/dhcpsrv/mysql_lease_mgr.h56
-rw-r--r--src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc14
-rw-r--r--src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc23
6 files changed, 299 insertions, 57 deletions
diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h
index fd43daa9fa..01190e67a9 100644
--- a/src/lib/dhcpsrv/lease_mgr.h
+++ b/src/lib/dhcpsrv/lease_mgr.h
@@ -202,13 +202,14 @@ public:
return (select_mode_);
};
-private:
+protected:
/// @brief First (or only) subnet_id in the selection criteria
SubnetID first_subnet_id_;
/// @brief Last subnet_id in the selection criteria when a range is given
SubnetID last_subnet_id_;
+private:
/// @brief Indicates the type of selection criteria specified
SelectMode select_mode_;
};
diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc
index 6e9421d048..449dae4564 100644
--- a/src/lib/dhcpsrv/memfile_lease_mgr.cc
+++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc
@@ -409,12 +409,19 @@ public:
// and wipe the accumulators
if ((*lease)->subnet_id_ != cur_id) {
if (cur_id > 0) {
- rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT,
- assigned));
- assigned = 0;
- rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED,
- declined));
- declined = 0;
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DEFAULT,
+ assigned));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id,
+ Lease::STATE_DECLINED,
+ declined));
+ declined = 0;
+ }
}
// Update current subnet id
@@ -430,8 +437,15 @@ public:
}
// Make the rows for last subnet
- rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT, assigned));
- rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED, declined));
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT,
+ assigned));
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DECLINED,
+ declined));
+ }
// Reset the next row position back to the beginning of the rows.
next_pos_ = rows_.begin();
@@ -538,18 +552,26 @@ public:
// and wipe the accumulators
if ((*lease)->subnet_id_ != cur_id) {
if (cur_id > 0) {
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
- Lease::STATE_DEFAULT,
- assigned));
- assigned = 0;
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
- Lease::STATE_DECLINED,
- declined));
- declined = 0;
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
- Lease::STATE_DEFAULT,
- assigned_pds));
- assigned_pds = 0;
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DEFAULT,
+ assigned));
+ assigned = 0;
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DECLINED,
+ declined));
+ declined = 0;
+ }
+
+ if (assigned_pds > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
+ Lease::STATE_DEFAULT,
+ assigned_pds));
+ assigned_pds = 0;
+ }
}
// Update current subnet id
@@ -577,12 +599,20 @@ public:
}
// Make the rows for last subnet, unless there were no rows
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
- Lease::STATE_DEFAULT, assigned));
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
- Lease::STATE_DECLINED, declined));
- rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
- Lease::STATE_DEFAULT, assigned_pds));
+ if (assigned > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DEFAULT, assigned));
+ }
+
+ if (declined > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA,
+ Lease::STATE_DECLINED, declined));
+ }
+
+ if (assigned_pds > 0) {
+ rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_PD,
+ Lease::STATE_DEFAULT, assigned_pds));
+ }
// Set the next row position to the beginning of the rows.
next_pos_ = rows_.begin();
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index 0916427b9e..59d105ee42 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -240,13 +240,37 @@ tagged_statements = { {
"hostname = ?, hwaddr = ?, hwtype = ?, hwaddr_source = ?, "
"state = ? "
"WHERE address = ?"},
- {MySqlLeaseMgr::RECOUNT_LEASE4_STATS,
- "SELECT subnet_id, state, count(state) as state_count "
- " FROM lease4 GROUP BY subnet_id, state ORDER BY subnet_id"},
- {MySqlLeaseMgr::RECOUNT_LEASE6_STATS,
- "SELECT subnet_id, lease_type, state, count(state) as state_count"
- " FROM lease6 GROUP BY subnet_id, lease_type, state "
- " ORDER BY subnet_id" }
+ {MySqlLeaseMgr::ALL_LEASE4_STATS,
+ "SELECT subnet_id, state, leases as state_count"
+ " FROM lease4_stat ORDER BY subnet_id, state"},
+
+ {MySqlLeaseMgr::SUBNET_LEASE4_STATS,
+ "SELECT subnet_id, state, leases as state_count"
+ " FROM lease4_stat "
+ " WHERE subnet_id = ? "
+ " ORDER BY state"},
+
+ {MySqlLeaseMgr::SUBNET_RANGE_LEASE4_STATS,
+ "SELECT subnet_id, state, leases as state_count"
+ " FROM lease4_stat "
+ " WHERE subnet_id >= ? and subnet_id <= ? "
+ " ORDER BY subnet_id, state"},
+
+ {MySqlLeaseMgr::ALL_LEASE6_STATS,
+ "SELECT subnet_id, lease_type, state, leases as state_count"
+ " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
+
+ {MySqlLeaseMgr::SUBNET_LEASE6_STATS,
+ "SELECT subnet_id, lease_type, state, leases as state_count"
+ " FROM lease6_stat "
+ " WHERE subnet_id = ? "
+ " ORDER BY lease_type, state" },
+
+ {MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
+ "SELECT subnet_id, lease_type, state, leases as state_count"
+ " FROM lease6_stat "
+ " WHERE subnet_id >= ? and subnet_id <= ? "
+ " ORDER BY subnet_id, lease_type, state" }
}
};
@@ -1262,11 +1286,14 @@ private:
///
class MySqlLeaseStatsQuery : public LeaseStatsQuery {
public:
- /// @brief Constructor
+ /// @brief Constructor to query for all subnets' stats
+ ///
+ /// The query created will return statistics for all subnets
///
- /// @param conn A open connection to the database housing the lease data
+ /// @param conn An open connection to the database housing the lease data
/// @param statement_index Index of the query's prepared statement
/// @param fetch_type Indicates if query supplies lease type
+ /// @throw if statement index is invalid.
MySqlLeaseStatsQuery(MySqlConnection& conn, const size_t statement_index,
const bool fetch_type)
: conn_(conn), statement_index_(statement_index), statement_(NULL),
@@ -1275,12 +1302,51 @@ public:
// This is the number of columns expected in the result set
bind_(fetch_type_ ? 4 : 3),
subnet_id_(0), lease_type_(0), lease_state_(0), state_count_(0) {
- if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
- isc_throw(BadValue, "MySqlLeaseStatsQuery"
- " - invalid statement index" << statement_index_);
- }
+ validateStatement();
+ }
+
+ /// @brief Constructor to query for a single subnet's stats
+ ///
+ /// The query created will return statistics for a single subnet
+ ///
+ /// @param conn An open connection to the database housing the lease data
+ /// @param statement_index Index of the query's prepared statement
+ /// @param fetch_type Indicates if query supplies lease type
+ /// @param subnet_id id of the subnet for which stats are desired
+ /// @throw BadValue if sunbet_id given is 0 or if statement index is invalid.
+ MySqlLeaseStatsQuery(MySqlConnection& conn, const size_t statement_index,
+ const bool fetch_type, const SubnetID& subnet_id)
+ : LeaseStatsQuery(subnet_id), conn_(conn), statement_index_(statement_index),
+ statement_(NULL), fetch_type_(fetch_type),
+ // Set the number of columns in the bind array based on fetch_type
+ // This is the number of columns expected in the result set
+ bind_(fetch_type_ ? 4 : 3),
+ subnet_id_(0), lease_type_(0), lease_state_(0), state_count_(0) {
+ validateStatement();
+ }
- statement_ = conn.statements_[statement_index_];
+ /// @brief Constructor to query for the stats for a range of subnets
+ ///
+ /// The query created will return statistics for the inclusive range of
+ /// subnets described by first and last sunbet IDs.
+ ///
+ /// @param conn An open connection to the database housing the lease data
+ /// @param statement_index Index of the query's prepared statement
+ /// @param fetch_type Indicates if query supplies lease type
+ /// @param first_subnet_id first subnet in the range of subnets
+ /// @param last_subnet_id last subnet in the range of subnets
+ /// @throw BadValue if either subnet ID is 0 or if last <= first or
+ /// if statement index is invalid.
+ MySqlLeaseStatsQuery(MySqlConnection& conn, const size_t statement_index,
+ const bool fetch_type, const SubnetID& first_subnet_id,
+ const SubnetID& last_subnet_id)
+ : LeaseStatsQuery(first_subnet_id, last_subnet_id), conn_(conn),
+ statement_index_(statement_index), statement_(NULL), fetch_type_(fetch_type),
+ // Set the number of columns in the bind array based on fetch_type
+ // This is the number of columns expected in the result set
+ bind_(fetch_type_ ? 4 : 3),
+ subnet_id_(0), lease_type_(0), lease_state_(0), state_count_(0) {
+ validateStatement();
}
/// @brief Destructor
@@ -1296,6 +1362,28 @@ public:
/// the output bind array and then executes the statement, and fetches
/// entire result set.
void start() {
+ // Set up where clause inputs if needed.
+ if (getSelectMode() != ALL_SUBNETS) {
+ MYSQL_BIND inbind[2];
+ memset(inbind, 0, sizeof(inbind));
+
+ // Add first_subnet_id used by both single and range.
+ inbind[0].buffer_type = MYSQL_TYPE_LONG;
+ inbind[0].buffer = reinterpret_cast<char*>(&first_subnet_id_);
+ inbind[0].is_unsigned = MLM_TRUE;
+
+ // Add last_subnet_id for range.
+ if (getSelectMode() == SUBNET_RANGE) {
+ inbind[1].buffer_type = MYSQL_TYPE_LONG;
+ inbind[1].buffer = reinterpret_cast<char*>(&last_subnet_id_);
+ inbind[1].is_unsigned = MLM_TRUE;
+ }
+
+ // Bind the parameters to the statement
+ int status = mysql_stmt_bind_param(statement_, &inbind[0]);
+ conn_.checkError(status, statement_index_, "unable to bind parameters");
+ }
+
int col = 0;
// subnet_id: unsigned int
bind_[col].buffer_type = MYSQL_TYPE_LONG;
@@ -1321,7 +1409,7 @@ public:
++col;
// state_count_: uint32_t
- bind_[col].buffer_type = MYSQL_TYPE_LONG;
+ bind_[col].buffer_type = MYSQL_TYPE_LONGLONG;
bind_[col].buffer = reinterpret_cast<char*>(&state_count_);
bind_[col].is_unsigned = MLM_TRUE;
@@ -1368,6 +1456,18 @@ public:
}
private:
+ /// @brief Validate the statement index passed to the constructor
+ /// Safely fetch the statement from the connection based on statement index
+ /// @throw BadValue if statement index is out of range
+ void validateStatement() {
+ if (statement_index_ >= MySqlLeaseMgr::NUM_STATEMENTS) {
+ isc_throw(BadValue, "MySqlLeaseStatsQuery"
+ " - invalid statement index" << statement_index_);
+ }
+
+ statement_ = conn_.statements_[statement_index_];
+ }
+
/// @brief Database connection to use to execute the query
MySqlConnection& conn_;
@@ -1390,7 +1490,7 @@ private:
/// @brief Receives the lease state when fetching a row
uint32_t lease_state_;
/// @brief Receives the state count when fetching a row
- uint32_t state_count_;
+ int64_t state_count_;
};
// MySqlLeaseMgr Constructor and Destructor
@@ -2185,21 +2285,63 @@ MySqlLeaseMgr::deleteExpiredReclaimedLeasesCommon(const uint32_t secs,
LeaseStatsQueryPtr
MySqlLeaseMgr::startLeaseStatsQuery4() {
LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
- RECOUNT_LEASE4_STATS,
+ ALL_LEASE4_STATS,
false));
query->start();
return(query);
}
LeaseStatsQueryPtr
+MySqlLeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ SUBNET_LEASE4_STATS,
+ false,
+ subnet_id));
+ query->start();
+ return(query);
+}
+
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startSubnetRangeLeaseStatsQuery4(const SubnetID& first_subnet_id,
+ const SubnetID& last_subnet_id) {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ SUBNET_RANGE_LEASE4_STATS,
+ false,
+ first_subnet_id, last_subnet_id));
+ query->start();
+ return(query);
+}
+
+LeaseStatsQueryPtr
MySqlLeaseMgr::startLeaseStatsQuery6() {
LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
- RECOUNT_LEASE6_STATS,
+ ALL_LEASE6_STATS,
true));
query->start();
return(query);
}
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ SUBNET_LEASE6_STATS,
+ true,
+ subnet_id));
+ query->start();
+ return(query);
+}
+
+LeaseStatsQueryPtr
+MySqlLeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_id,
+ const SubnetID& last_subnet_id) {
+ LeaseStatsQueryPtr query(new MySqlLeaseStatsQuery(conn_,
+ SUBNET_RANGE_LEASE6_STATS,
+ true,
+ first_subnet_id, last_subnet_id));
+ query->start();
+ return(query);
+}
+
size_t
MySqlLeaseMgr::wipeLeases4(const SubnetID& /*subnet_id*/) {
isc_throw(NotImplemented, "wipeLeases4 is not implemented for MySQL backend");
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h
index db87cf812b..fb2a427659 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.h
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.h
@@ -365,22 +365,66 @@ public:
///
/// It creates an instance of a MySqlLeaseStatsQuery4 and then
/// invokes its start method, which fetches its statistical data
- /// result set by executing the RECOUNT_LEASE_STATS4 query.
+ /// result set by executing the ALL_LEASE_STATS4 query.
/// The query object is then returned.
///
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery4();
+ /// @brief Creates and runs the IPv4 lease stats query for a single subnet
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery4 for a single subnet
+ /// query and then invokes its start method in which the query constructs its
+ /// statistical data result set. The query object is then returned.
+ ///
+ /// @param subnet_id id of the subnet for which stats are desired
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID& subnet_id);
+
+ /// @brief Creates and runs the IPv4 lease stats query for a single subnet
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery4 for a subnet range
+ /// query and then invokes its start method in which the query constructs its
+ /// statistical data result set. The query object is then returned.
+ ///
+ /// @param first_subnet_id first subnet in the range of subnets
+ /// @param last_subnet_id last subnet in the range of subnets
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID& first_subnet_id,
+ const SubnetID& last_subnet_id);
+
/// @brief Creates and runs the IPv6 lease stats query
///
/// It creates an instance of a MySqlLeaseStatsQuery6 and then
/// invokes its start method, which fetches its statistical data
- /// result set by executing the RECOUNT_LEASE_STATS6 query.
+ /// result set by executing the ALL_LEASE_STATS6 query.
/// The query object is then returned.
///
/// @return The populated query as a pointer to an LeaseStatsQuery
virtual LeaseStatsQueryPtr startLeaseStatsQuery6();
+ /// @brief Creates and runs the IPv6 lease stats query for a single subnet
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery6 for a single subnet
+ /// query and then invokes its start method in which the query constructs its
+ /// statistical data result set. The query object is then returned.
+ ///
+ /// @param subnet_id id of the subnet for which stats are desired
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID& subnet_id);
+
+ /// @brief Creates and runs the IPv6 lease stats query for a single subnet
+ ///
+ /// It creates an instance of a MySqlLeaseStatsQuery6 for a subnet range
+ /// query and then invokes its start method in which the query constructs its
+ /// statistical data result set. The query object is then returned.
+ ///
+ /// @param first_subnet_id first subnet in the range of subnets
+ /// @param last_subnet_id last subnet in the range of subnets
+ /// @return A populated LeaseStatsQuery
+ virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_id,
+ const SubnetID& last_subnet_id);
+
/// @brief Removes specified IPv4 leases.
///
/// This rather dangerous method is able to remove all leases from specified
@@ -478,8 +522,12 @@ public:
INSERT_LEASE6, // Add entry to lease6 table
UPDATE_LEASE4, // Update a Lease4 entry
UPDATE_LEASE6, // Update a Lease6 entry
- RECOUNT_LEASE4_STATS, // Fetches IPv4 address statistics
- RECOUNT_LEASE6_STATS, // Fetches IPv6 address statistics
+ ALL_LEASE4_STATS, // Fetches IPv4 lease statistics
+ SUBNET_LEASE4_STATS, // Fetched IPv4 lease stats for a single subnet.
+ SUBNET_RANGE_LEASE4_STATS, // Fetched IPv4 lease stats for a subnet range.
+ ALL_LEASE6_STATS, // Fetches IPv6 lease statistics
+ SUBNET_LEASE6_STATS, // Fetched IPv6 lease stats for a single subnet.
+ SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
NUM_STATEMENTS // Number of statements
};
diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
index cae09c8147..bcf64b8ad7 100644
--- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
@@ -2873,7 +2873,16 @@ GenericLeaseMgrTest::checkQueryAgainstRowSet(const LeaseStatsQueryPtr& query,
<< " state: " << row.lease_state_
<< " count: " << row.state_count_;
} else {
- ++rows_matched;
+ if (row.state_count_ != (*found_row).state_count_) {
+ ADD_FAILURE() << "row count wrong for "
+ << " id: " << row.subnet_id_
+ << " type: " << row.lease_type_
+ << " state: " << row.lease_state_
+ << " count: " << row.state_count_
+ << "; expected: " << (*found_row).state_count_;
+ } else {
+ ++rows_matched;
+ }
}
}
@@ -2963,7 +2972,6 @@ GenericLeaseMgrTest::testLeaseStatsQuery4() {
{
SCOPED_TRACE("SINGLE SUBNET");
// Add expected rows for Subnet 2
- expected_rows.insert(LeaseStatsRow(2, Lease::STATE_DEFAULT, 0));
expected_rows.insert(LeaseStatsRow(2, Lease::STATE_DECLINED, 1));
// Start the query
ASSERT_NO_THROW(query = lmptr_->startSubnetLeaseStatsQuery4(2));
@@ -3110,7 +3118,6 @@ GenericLeaseMgrTest::testLeaseStatsQuery6() {
// Add expected row for Subnet 2
expected_rows.insert(LeaseStatsRow(2, Lease::TYPE_NA, Lease::STATE_DEFAULT, 2));
expected_rows.insert(LeaseStatsRow(2, Lease::TYPE_NA, Lease::STATE_DECLINED, 1));
- expected_rows.insert(LeaseStatsRow(2, Lease::TYPE_PD, Lease::STATE_DEFAULT, 0));
// Start the query
ASSERT_NO_THROW(query = lmptr_->startSubnetLeaseStatsQuery6(2));
// Verify contents
@@ -3123,7 +3130,6 @@ GenericLeaseMgrTest::testLeaseStatsQuery6() {
// Add expected rows for Subnet 3
expected_rows.insert(LeaseStatsRow(3, Lease::TYPE_NA, Lease::STATE_DEFAULT, 2));
expected_rows.insert(LeaseStatsRow(3, Lease::TYPE_NA, Lease::STATE_DECLINED, 1));
- expected_rows.insert(LeaseStatsRow(3, Lease::TYPE_PD, Lease::STATE_DEFAULT, 0));
// Start the query
ASSERT_NO_THROW(query = lmptr_->startSubnetRangeLeaseStatsQuery6(2,3));
// Verify contents
diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
index a92791ed51..dcacbc403e 100644
--- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
@@ -106,9 +106,7 @@ public:
/// 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.
-
TEST(MySqlOpenTest, OpenDatabase) {
-
// Schema needs to be created for the test to work.
destroyMySQLSchema(true);
createMySQLSchema(true);
@@ -161,9 +159,15 @@ TEST(MySqlOpenTest, OpenDatabase) {
MYSQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
+#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.
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
+#endif
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
@@ -189,6 +193,7 @@ TEST(MySqlOpenTest, OpenDatabase) {
// Tidy up after the test
destroyMySQLSchema(true);
+ LeaseMgrFactory::destroy();
}
/// @brief Check the getType() method
@@ -553,14 +558,14 @@ public:
}
virtual std::string invalidConnectString() {
- return (connectionString(MYSQL_VALID_TYPE, VALID_NAME, INVALID_HOST,
+ return (connectionString(MYSQL_VALID_TYPE, INVALID_NAME, VALID_HOST,
VALID_USER, VALID_PASSWORD));
}
};
// Verifies that db lost callback is not invoked on an open failure
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailure) {
- testDbLostCallback();
+ testNoCallbackOnOpenFailure();
}
// Verifies that loss of connectivity to MySQL is handled correctly.
@@ -568,4 +573,14 @@ TEST_F(MySQLLeaseMgrDbLostCallbackTest, testDbLostCallback) {
testDbLostCallback();
}
+// Tests v4 lease stats query variants.
+TEST_F(MySqlLeaseMgrTest, leaseStatsQuery4) {
+ testLeaseStatsQuery4();
+}
+
+// Tests v6 lease stats query variants.
+TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6) {
+ testLeaseStatsQuery6();
+}
+
} // namespace