From: Thomas Markwalder Date: Tue, 15 May 2018 17:33:50 +0000 (-0400) Subject: [5589] Addressed review comments except for unit tests not loading library X-Git-Tag: trac5549a_base~21^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4a614f4d14c5849b74125df61f98e4ebb2aba04;p=thirdparty%2Fkea.git [5589] Addressed review comments except for unit tests not loading library Too numerous to mention. --- diff --git a/doc/guide/hooks-stat-cmds.xml b/doc/guide/hooks-stat-cmds.xml index 02afe088b9..988ed91c78 100644 --- a/doc/guide/hooks-stat-cmds.xml +++ b/doc/guide/hooks-stat-cmds.xml @@ -7,7 +7,8 @@ statistics in deployments running multiple Kea servers that use shared lease back end. The in-memory statistics kept by individual servers only track lease changes made by that server. Thus in a - deployment with multiple servers, these statistics are incomplete. + deployment with multiple servers (e.g. two kea-dhcp6 servers using the + same PostgreSQL database for lease storage), these statistics are incomplete. In Kea 1.4, the MySQL and PostgreSQL back ends were modified to track lease allocation changes as they occur via database triggers. Additionally, all four lease back ends were extended to support retrieving lease @@ -111,9 +112,7 @@ The following command would fetch lease statistcis for all known subnets from kea-dhcp4 server: { - "command": "stat-lease4-get", - "arguments": { - } + "command": "stat-lease4-get" } @@ -170,22 +169,12 @@ subnet-id - ID of the subnet total-addresses - total number of addresses - available for DHCPv4 management. In other words, this is the sum of all - addresses in all configured pools. This statistic changes only during - configuration changes. Note it does not take into account any addresses that - may be reserved due to host reservation. - - assigned-addresses - number of assigned - addresses in a given subnet. It increases every time a new lease is - allocated (as a result of receiving a DHCPREQUEST message) and is decreased - every time a lease is released (a DHCPRELEASE message is received) or expires. - - declined-addresses - number of IPv4 addresses - that are currently declined in a given subnet, so is a count of the number - of leases currently unavailable. Once a lease is recovered, this statistic - will be decreased. Ideally, this statistic should be zero. If this statistic - is non-zero (or worse increasing), a network administrator should investigate - if there is a misbehaving device in his network. + available for DHCPv4 management in the subnet. In other words, this is the sum of all + addresses in all the configured pools in the subnet. + assigned-addresses - number of addresses + in the subnet that are currently assigned to a client. + declined-addresses - number of addresses + in the subnet that are currently declined and are thus unavailable for assignment. @@ -193,35 +182,17 @@ subnet-id - ID of the subnet total-nas - number of NA addresses available - for DHCPv6 management for a given subnet. In other words, this is the - sum of all addresses in all configured pools. This statistic changes - only during configuration changes. Note that it does not take into account - any addresses that may be reserved due to host reservation. - + for DHCPv6 management in the subnet. In other words, this is the sum of all + the NA addresses in the all configured NA pools in the subnet. assigned-nas - number of NA addresses in a - the subnet that are assigned. This statistic increases every time a new - lease is allocated (as a result of receiving a REQUEST message) and is - decreased every time a lease is released (a RELEASE message is received) - or expires. - - declined-nas - number of IPv6 addresses that - are currently declined and so counts the number of leases currently - unavailable. Once a lease is recovered, this statistic will be decreased. - Ideally, this statistic should be zero. If this statistic is non-zero - (or worse, increasing), the network administrator should investigate if - there is a misbehaving device in the network. - - total-pds - total number of PD prefixes available - of DHCPv6 management for a given subnet. In other words, this is the sum - of all prefixes in all configured pools. This statistic changes only during - configuration changes. Note it does not take into account any prefixes that - may be reserved due to host reservation. - - assigned-pds - number of PD prefixes in a given - subnet that are assigned. This statistic increases every time a new lease is - allocated (as a result of receiving a REQUEST message) and is decreased every - time a lease is released (a RELEASE message is received) or expires. - + the subnet that are currently assigned to a client. + declined-nas - number of NA addresses that + are currently declined and are thus unavailable for assignment. + total-pds - total number of prefixes available + of DHCPv6 management in the subnet. In other words, this is the sum of all prefixes + in all the configured prefix pools in the subnet. + assigned-pds - number of prefixes in the subnet + that are currently assigned to a client. rows - a list of rows, one per subnet ID. Each row @@ -245,7 +216,8 @@ "result-set": { "columns": [ "subnet-id", "total-addresses", "assigned-addresses", "declined-addresses" ] "rows": [ - [ 10, 256, 111, 0 ], [ 20, 4098, 2034, 4 ] + [ 10, 256, 111, 0 ], + [ 20, 4098, 2034, 4 ] ], "timestamp": "2018-05-04 15:03:37.000000" } @@ -254,7 +226,9 @@ - The response to a DHCPv6 command might look as follows: + The response to a DHCPv6 command might look as follows (subnet 10 has no + prefix pools, subnet 20 has no NA pools, and subnet 30 has both NA and PD + pools): { "result": 0, @@ -263,8 +237,9 @@ "result-set": { "columns": [ "subnet-id", "total-nas", "assigned-nas", "declined-nas", "total-pds", "assigned-pds" ] "rows": [ - [ 10, 256, 111, 0 ], - [ 20, 4098, 2034, 4 ] + [ 10, 4096, 2400, 3, 0, 0], + [ 20, 0, 0, 0, 1048, 233 ] + [ 30, 256, 60, 0, 1048, 15 ] ], "timestamp": "2018-05-04 15:03:37.000000" } diff --git a/doc/guide/logging.xml b/doc/guide/logging.xml index 412b0f0c72..a9f41e4a70 100644 --- a/doc/guide/logging.xml +++ b/doc/guide/logging.xml @@ -313,6 +313,15 @@ + + + kea-dhcp4.stat-cmds-hooks - this logger is used + to log messages related to operation of the Stats Cmds hooks library. + In general these will pertain to loading and unloading the library, + as well as execution of commands by the library. + + + kea-dhcp6 - the root logger for the DHCPv6 diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds.cc b/src/hooks/dhcp/stat_cmds/stat_cmds.cc index 513699a728..d8aa0a5223 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds.cc @@ -60,6 +60,25 @@ public: /// @brief Denotes the query selection mode all, subnet, /// or subnet range LeaseStatsQuery::SelectMode select_mode_; + + /// @brief Generate a string version of the contents + std::string toText() { + std::stringstream os; + switch (select_mode_) { + case LeaseStatsQuery::ALL_SUBNETS: + os << "[all subnets]"; + break; + case LeaseStatsQuery::SINGLE_SUBNET: + os << "[subnet-id=" << first_subnet_id_ << "]"; + break; + case LeaseStatsQuery::SUBNET_RANGE: + os << "[subnets " << first_subnet_id_ + << " through " << last_subnet_id_ << "]"; + break; + } + + return (os.str()); + } }; public: @@ -102,8 +121,7 @@ public: /// must fulfill: 0 < first-subnet-id < last-subnet-id /// -# subnet-id and subnet-range are mutually exclusive Parameters getParameters(const ConstElementPtr& cmd_args); - - /// @brief Executes the lease4 query and constructs the outbound result set +/// @brief Executes the lease4 query and constructs the outbound result set /// /// This method uses the command parameters to identify the range /// of configured subnets. If the range contains no known subnets @@ -195,39 +213,46 @@ public: int LeaseStatCmdsImpl::statLease4GetHandler(CalloutHandle& handle) { ElementPtr result = Element::createMap(); - int response_code; - string txt = "malformed command"; + Parameters params; + ConstElementPtr response; + + // Extract the command and then the parameters try { - // Extract the command and then the parameters extractCommand(handle); - Parameters params = getParameters(cmd_args_); + params = getParameters(cmd_args_); + } catch (const std::exception& ex) { + LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_INVALID) + .arg(ex.what()); + setErrorResponse(handle, ex.what()); + return (1); + } + try { // Now build the result set - txt = "building result"; uint64_t rows = makeResultSet4(result, params); - - // Eureka it worked! - response_code = CONTROL_RESULT_SUCCESS; + LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET) + .arg(params.toText()) + .arg(rows); std::stringstream os; - os << "stat-lease4-get: " << rows << " rows found"; - txt = os.str(); + os << "stat-lease4-get" << params.toText() << ": " << rows << " rows found"; + response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result); } catch (const NotFound& ex) { // Criteria was valid but included no known subnets, // so we return a not found response. - response_code = CONTROL_RESULT_EMPTY; + LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE4_GET_NO_SUBNETS) + .arg(params.toText()) + .arg(ex.what()); std::stringstream os; - os << "stat-lease4-get: " << "no matching data, " << ex.what(); - txt = os.str(); + os << "stat-lease4-get" << params.toText() << ": no matching data, " << ex.what(); + response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result); } catch (const std::exception& ex) { - LOG_ERROR(stat_cmds_logger, STAT_LEASE4_GET_FAILED) - .arg(txt) - .arg(ex.what()); + LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE4_GET_FAILED) + .arg(params.toText()) + .arg(ex.what()); setErrorResponse(handle, ex.what()); return (1); } - LOG_INFO(stat_cmds_logger, STAT_LEASE4_GET).arg(txt); - ConstElementPtr response = createAnswer(response_code, txt, result); setResponse(handle, response); return (0); } @@ -235,40 +260,46 @@ LeaseStatCmdsImpl::statLease4GetHandler(CalloutHandle& handle) { int LeaseStatCmdsImpl::statLease6GetHandler(CalloutHandle& handle) { ElementPtr result = Element::createMap(); - int response_code; - string txt = "malformed command"; + Parameters params; + ConstElementPtr response; + + // Extract the command and then the parameters try { - // Extract the command and then the parameters extractCommand(handle); - Parameters params = getParameters(cmd_args_); + params = getParameters(cmd_args_); + } catch (const std::exception& ex) { + LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_INVALID) + .arg(ex.what()); + setErrorResponse(handle, ex.what()); + return (1); + } + try { // Now build the result set - txt = "building result"; uint64_t rows = makeResultSet6(result, params); - - // Eureka it worked! - response_code = CONTROL_RESULT_SUCCESS; + LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET) + .arg(params.toText()) + .arg(rows); std::stringstream os; - os << "stat-lease6-get: " << rows << " rows found"; - txt = os.str(); + os << "stat-lease6-get" << params.toText() << ": " << rows << " rows found"; + response = createAnswer(CONTROL_RESULT_SUCCESS, os.str(), result); } catch (const NotFound& ex) { // Criteria was valid but included no known subnets, // so we return a not found response. - result = Element::createMap(); - response_code = CONTROL_RESULT_EMPTY; + LOG_INFO(stat_cmds_logger, STAT_CMDS_LEASE6_GET_NO_SUBNETS) + .arg(params.toText()) + .arg(ex.what()); std::stringstream os; - os << "stat-lease6-get: " << "no matching data, " << ex.what(); - txt = os.str(); + os << "stat-lease6-get" << params.toText() << ": no matching data, " << ex.what(); + response = createAnswer(CONTROL_RESULT_EMPTY, os.str(), result); } catch (const std::exception& ex) { - LOG_ERROR(stat_cmds_logger, STAT_LEASE6_GET_FAILED) - .arg(txt) - .arg(ex.what()); + LOG_ERROR(stat_cmds_logger, STAT_CMDS_LEASE6_GET_FAILED) + .arg(params.toText()) + .arg(ex.what()); setErrorResponse(handle, ex.what()); return (1); } - LOG_INFO(stat_cmds_logger, STAT_LEASE6_GET).arg(txt); - ConstElementPtr response = createAnswer(response_code, txt, result); setResponse(handle, response); return (0); } @@ -277,8 +308,14 @@ LeaseStatCmdsImpl::Parameters LeaseStatCmdsImpl::getParameters(const ConstElementPtr& cmd_args) { Parameters params; - if (!cmd_args || cmd_args->getType() != Element::map) { - isc_throw(BadValue, "Parameters missing or are not a map."); + params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS; + if (!cmd_args ) { + // No arguments defaults to ALL_SUBNETS. + return (params); + } + + if (cmd_args->getType() != Element::map) { + isc_throw(BadValue, "'arguments' parameter is not a map"); } params.select_mode_ = LeaseStatsQuery::ALL_SUBNETS; @@ -299,7 +336,7 @@ LeaseStatCmdsImpl::getParameters(const ConstElementPtr& cmd_args) { if (cmd_args->contains("subnet-range")) { if (params.select_mode_ == LeaseStatsQuery::SINGLE_SUBNET) { - isc_throw(BadValue, "Cannot specify both subnet-id and subnet-range"); + isc_throw(BadValue, "cannot specify both subnet-id and subnet-range"); } ConstElementPtr range = cmd_args->get("subnet-range"); @@ -567,7 +604,8 @@ LeaseStatCmdsImpl::createResultSet(const ElementPtr &result_wrapper, result_wrapper->set("result-set", result_set); // Create the timestamp based on time now and add it to the result set. - boost::posix_time::ptime now(boost::posix_time::second_clock::universal_time()); + boost::posix_time::ptime now(boost::posix_time::microsec_clock::universal_time()); + ElementPtr timestamp = Element::create(isc::util::ptimeToText(now)); result_set->set("timestamp", timestamp); @@ -632,8 +670,5 @@ StatCmds::statLease6GetHandler(CalloutHandle& handle) { return(impl.statLease6GetHandler(handle)); } -StatCmds::StatCmds() { -} - }; }; diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds.h b/src/hooks/dhcp/stat_cmds/stat_cmds.h index a67c4756fb..ce63667fef 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds.h +++ b/src/hooks/dhcp/stat_cmds/stat_cmds.h @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018 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 @@ -7,7 +7,6 @@ #ifndef STAT_CMDS_H #define STAT_CMDS_H -#include #include #include @@ -25,14 +24,12 @@ class StatCmdsImpl; /// stat manipulations. class StatCmds { public: - /// @brief Constructor. - /// - /// It creates an instance of the @c StatCmdsImpl. - StatCmds(); + /// @brief Default Constructor. + StatCmds() {}; /// @brief stat-lease4-get command handler /// - /// This command attempts to fetch lease4 statistics for one or + /// This command attempts to fetch lease4 statistics for one or /// more subnets based upon subnet selection criteria (or lack thereof). /// It extracts the command name and arguments from the given Callouthandle, /// attempts to process them, and then set's the handle's "response" @@ -40,10 +37,10 @@ public: /// { /// "command": "stat-lease4-get", /// "arguments": { - /// "subnet-id": x // optional + /// "subnet-id": 10 // optional /// "subnet-range": { // optional - /// "first-subnet-id": x, // id >= x - /// "last-subnet-id": y // id <= x + /// "first-subnet-id": 10, // id >= 10 + /// "last-subnet-id": 50 // id <= 50 /// } /// } /// } @@ -56,7 +53,7 @@ public: /// "arguments": { /// "result-set": { /// "timestamp": "2018-03-22 09:43:30.815371", - /// "columns": ["subnet_id", "total-addresses", + /// "columns": ["subnet_id", "total-addresses", /// "assigned-addresses", "declined-addresses"], /// "rows": [ /// [1, 600, 450, 3], @@ -75,7 +72,7 @@ public: /// @brief stat-lease6-get command handler /// - /// This command attempts to fetch lease6 statistics for one or + /// This command attempts to fetch lease6 statistics for one or /// more subnets based upon subnet selection criteria (or lack thereof). /// It extracts the command name and arguments from the given Callouthandle, /// attempts to process them, and then set's the handle's "response" @@ -83,10 +80,10 @@ public: /// { /// "command": "stat-lease6-get", /// "arguments": { - /// "subnet-id": x // optional + /// "subnet-id": 10 // optional /// "subnet-range": { // optional - /// "first-subnet-id": x, // id >= x - /// "last-subnet-id": y // id <= x + /// "first-subnet-id": 10, // id >= 10 + /// "last-subnet-id": 50 // id <= 50 /// } /// } /// } @@ -99,8 +96,8 @@ public: /// "arguments": { /// "result-set": { /// "timestamp": "2018-03-22 09:43:30.815371", - /// "columns": ["subnet_id", "total-nas", - /// "assigned-nas", "declined-nas", + /// "columns": ["subnet_id", "total-nas", + /// "assigned-nas", "declined-nas", /// "total-pds", "assigned-pds"], /// "rows": [ /// [1, 600, 450, 3, 64, 10], @@ -116,11 +113,6 @@ public: /// @return result of the operation int statLease6GetHandler(hooks::CalloutHandle& handle); -#if 0 -private: - /// Pointer to the actual implementation - boost::shared_ptr impl_; -#endif }; }; diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc b/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc index 25acba20b9..a0da474396 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc @@ -13,8 +13,6 @@ #include #include -using namespace isc::config; -using namespace isc::data; using namespace isc::hooks; using namespace isc::stat_cmds; @@ -49,7 +47,7 @@ int stat_lease6_get(CalloutHandle& handle) { int load(LibraryHandle& handle) { handle.registerCommandCallout("stat-lease4-get", stat_lease4_get); handle.registerCommandCallout("stat-lease6-get", stat_lease6_get); - LOG_INFO(stat_cmds_logger, STAT_CMDS_INIT_OK); + LOG_INFO(stat_cmds_logger, STAT_CMDS_CMDS_INIT_OK); return (0); } @@ -57,7 +55,7 @@ int load(LibraryHandle& handle) { /// /// @return 0 if deregistration was successful, 1 otherwise int unload() { - LOG_INFO(stat_cmds_logger, STAT_CMDS_DEINIT_OK); + LOG_INFO(stat_cmds_logger, STAT_CMDS_CMDS_DEINIT_OK); return (0); } diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds_log.cc b/src/hooks/dhcp/stat_cmds/stat_cmds_log.cc index e495d7c020..8b257da7b3 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds_log.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds_log.cc @@ -9,7 +9,7 @@ namespace isc { namespace stat_cmds { -isc::log::Logger stat_cmds_logger("stat_cmds_hooks"); +isc::log::Logger stat_cmds_logger("stat-cmds-hooks"); } } diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds_messages.mes b/src/hooks/dhcp/stat_cmds/stat_cmds_messages.mes index 4d9a64d2bb..636262a2c0 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds_messages.mes +++ b/src/hooks/dhcp/stat_cmds/stat_cmds_messages.mes @@ -1,35 +1,53 @@ # Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") -% STAT_LEASE4_GET stat-lease4-get command successful (parameters: %1) -The stat-lease4-get command has been successful. Parameters of the command -are logged. +% STAT_CMDS_LEASE4_GET stat-lease4-get command successful, parameters: %1 rows found: %2 +The stat-lease4-get command has been successful. The log will contain +the parameters supplied and the number of rows found. -% STAT_LEASE4_GET_FAILED stat-lease4-get command failed (parameters: %1, reason: %2) -The stat-lease4-get command has failed. Both the reason as well as the -parameters passed are logged. +% STAT_CMDS_LEASE4_GET_FAILED stat-lease4-get command failed: parameters: %1, reason: %2 +The stat-lease4-get command has failed. Both the parameters supplied and +the reason for failure are logged. -% STAT_LEASE6_GET stat-lease4-get command successful (parameters: %1) -The stat-lease4-get command has been successful. Parameters of the command -are logged. +% STAT_CMDS_LEASE4_GET_INVALID stat-lease4-get command is malformed or invalid, reason: %1 +The stat-lease4-get command was either malformed or contained invalid +parameters. A detailed explanation should be logged. -% STAT_LEASE6_GET_FAILED stat-lease4-get command failed (parameters: %1, reason: %2) -The stat-lease4-get command has failed. Both the reason as well as the -parameters passed are logged. +% STAT_CMDS_LEASE4_GET_NO_SUBNETS stat-lease4-get, parameters: %1, %2" +The parameters submitted with stat-lease4-get were valid but excluded all +known subnets. The parameters supplied along with an explanation should +be logged. -% STAT_CMDS_DEINIT_FAILED unloading Stat Commands hooks library failed: %1 +% STAT_CMDS_LEASE6_GET stat-lease6-get command successful, parameters: %1 rows found: %2 +The stat-lease6-get command has been successful. The log will contain +the parameters supplied and the number of rows found. + +% STAT_CMDS_LEASE6_GET_FAILED stat-lease4-get command failed: parameters: %1, reason: %2 +The stat-lease6-get command has failed. Both the parameters supplied and +the reason for failure are logged. + +% STAT_CMDS_LEASE6_GET_INVALID stat-lease6-get command is malformed or invalid, reason: %1 +The stat-lease6-get command was either malformed or contained invalid +parameters. A detailed explanation should be logged. + +% STAT_CMDS_LEASE6_GET_NO_SUBNETS stat-lease6-get, parameters: %1, %2" +The parameters submitted with stat-lease6-get were valid but excluded all +known subnets. The parameters supplied along with an explanation should +be logged. + +% STAT_CMDS_CMDS_DEINIT_FAILED unloading Stat Commands hooks library failed: %1 This error message indicates an error during unloading the Lease Commands hooks library. The details of the error are provided as argument of the log message. -% STAT_CMDS_DEINIT_OK unloading Stat Commands hooks library successful +% STAT_CMDS_CMDS_DEINIT_OK unloading Stat Commands hooks library successful This info message indicates that the Stat Commands hooks library has been removed successfully. -% STAT_CMDS_INIT_FAILED loading Stat Commands hooks library failed: %1 +% STAT_CMDS_CMDS_INIT_FAILED loading Stat Commands hooks library failed: %1 This error message indicates an error during loading the Lease Commands hooks library. The details of the error are provided as argument of the log message. -% STAT_CMDS_INIT_OK loading Stat Commands hooks library successful +% STAT_CMDS_CMDS_INIT_OK loading Stat Commands hooks library successful This info message indicates that the Stat Commands hooks library has been loaded successfully. Enjoy! diff --git a/src/hooks/dhcp/stat_cmds/tests/Makefile.am b/src/hooks/dhcp/stat_cmds/tests/Makefile.am index 60b1fd9287..d8bda8d298 100644 --- a/src/hooks/dhcp/stat_cmds/tests/Makefile.am +++ b/src/hooks/dhcp/stat_cmds/tests/Makefile.am @@ -35,12 +35,18 @@ stat_cmds_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS) stat_cmds_unittests_CXXFLAGS = $(AM_CXXFLAGS) stat_cmds_unittests_LDADD = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la -stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la -stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la stat_cmds_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la stat_cmds_unittests_LDADD += $(LOG4CPLUS_LIBS) diff --git a/src/hooks/dhcp/stat_cmds/tests/run_unittests.cc b/src/hooks/dhcp/stat_cmds/tests/run_unittests.cc index 600d522379..096485fb7a 100644 --- a/src/hooks/dhcp/stat_cmds/tests/run_unittests.cc +++ b/src/hooks/dhcp/stat_cmds/tests/run_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018 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 diff --git a/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc b/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc index 8554d1faac..4a8efbd6e2 100644 --- a/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc +++ b/src/hooks/dhcp/stat_cmds/tests/stat_cmds_unittest.cc @@ -526,13 +526,11 @@ public: /// @brief Creates an IPv6 lease /// - /// Lease parameters: cltt = 12345678, fqdn-fwd = false, fqdn-rev = true, - /// hostname = myhost.example.com, preferred lifetime = 1800, - /// valid lifetime = 3600 - /// /// @param ip_address IP address for the lease. /// @param subnet_id subnet identifier - /// @param state lease state + /// @param state lease state of the lease, defaults to STATE_DEFAULT + /// @param lease_type type of the lease, defaults to TYPE_NA + /// @param prefix_len prefix length of the lease, defaults to 128 void addLease6(const std::string& ip_address, const SubnetID& subnet_id, const int state = Lease::STATE_DEFAULT, const Lease::Type& lease_type = Lease::TYPE_NA, @@ -556,10 +554,16 @@ public: << "cannot add lease6: " << lease->toText(); } - void addPrefix(const std::string& ip_address, const int prefix_len, + /// @brief Creates an IPv6 PD lease + /// + /// @param prefix IP address prefix for the lease. + /// @param prefix_len prefix length of the lease + /// @param subnet_id subnet identifier + /// @param state lease state of the lease, defaults to STATE_DEFAULT + void addPrefix(const std::string& prefix, const int prefix_len, const SubnetID& subnet_id, const int state = Lease::STATE_DEFAULT) { - addLease6(ip_address, subnet_id, state, Lease::TYPE_PD, prefix_len); + addLease6(prefix, subnet_id, state, Lease::TYPE_PD, prefix_len); } /// @brief Pointer to the lease manager @@ -600,6 +604,14 @@ TEST_F(StatCmdsTest, StatLease4GetBadParams) { initLeaseMgr4(); std::vector tests = { + { + "arguments is not a map", + "{\n" + " \"command\": \"stat-lease4-get\",\n" + " \"arguments\": \"not a map\"\n" + "}", + "'arguments' parameter is not a map" + }, { "subnet-id 0", "{\n" @@ -727,6 +739,20 @@ TEST_F(StatCmdsTest, StatLease4GetBadParams) { "}", "'last-subnet-id' must be greater than 'first-subnet-id'" }, + { + "Subnet-Range: all in the middle", + "{\n" + " \"command\": \"stat-lease4-get\",\n" + " \"arguments\": {" + " \"subnet-id\": 10,\n" + " \"subnet-range\": {\n" + " \"first-subnet-id\": 20," + " \"last-subnet-id\": 40" + " }\n" + " }\n" + "}", + "cannot specify both subnet-id and subnet-range" + } }; for (auto test = tests.begin(); test != tests.end(); ++test) { @@ -754,7 +780,29 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " \"arguments\": {" " }\n" "}", - "stat-lease4-get: 5 rows found", + "stat-lease4-get[all subnets]: 5 rows found", + "{\n" + "\"result-set\": {\n" + " \"columns\": [\n" + " \"subnet-id\", \"total-addreses\",\n" + " \"assigned-addreses\", \"declined-addreses\"\n" + " ],\n" + " \"rows\": [\n" + " [ 10, 256, 2, 3 ],\n" + " [ 20, 16, 3, 0 ],\n" + " [ 30, 256, 0, 0 ],\n" + " [ 40, 16, 4, 0 ],\n" + " [ 50, 256, 1, 1 ]\n" + " ],\n" + " \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n" + "}\n" + }, + { + "ALL-Subnets - arguments omitted", + "{\n" + " \"command\": \"stat-lease4-get\"\n" + "}", + "stat-lease4-get[all subnets]: 5 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -779,7 +827,7 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " \"subnet-id\": 20" " }\n" "}", - "stat-lease4-get: 1 rows found", + "stat-lease4-get[subnet-id=20]: 1 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -803,7 +851,7 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " }\n" " }\n" "}", - "stat-lease4-get: 3 rows found", + "stat-lease4-get[subnets 10 through 30]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -829,7 +877,7 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " }\n" " }\n" "}", - "stat-lease4-get: 3 rows found", + "stat-lease4-get[subnets 20 through 40]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -855,7 +903,7 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " }\n" " }\n" "}", - "stat-lease4-get: 3 rows found", + "stat-lease4-get[subnets 30 through 50]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -881,7 +929,7 @@ TEST_F(StatCmdsTest, statLease4GetValid) { " }\n" " }\n" "}", - "stat-lease4-get: 2 rows found", + "stat-lease4-get[subnets 25 through 45]: 2 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -925,7 +973,7 @@ TEST_F(StatCmdsTest, statLease4GetSubnetsNotFound) { " \"subnet-id\": 88" " }\n" "}", - "stat-lease4-get: no matching data, subnet-id: 88 does not exist", + "stat-lease4-get[subnet-id=88]: no matching data, subnet-id: 88 does not exist", "{}" }, { @@ -939,7 +987,7 @@ TEST_F(StatCmdsTest, statLease4GetSubnetsNotFound) { " }\n" " }\n" "}", - "stat-lease4-get: no matching data, selected ID range: 2 through 6 includes no known subnets", + "stat-lease4-get[subnets 2 through 6]: no matching data, selected ID range: 2 through 6 includes no known subnets", "{}" }, { @@ -953,7 +1001,7 @@ TEST_F(StatCmdsTest, statLease4GetSubnetsNotFound) { " }\n" " }\n" "}", - "stat-lease4-get: no matching data, selected ID range: 200 through 600 includes no known subnets", + "stat-lease4-get[subnets 200 through 600]: no matching data, selected ID range: 200 through 600 includes no known subnets", "{}" } }; @@ -974,6 +1022,14 @@ TEST_F(StatCmdsTest, StatLease6GetBadParams) { initLeaseMgr6(); std::vector tests = { + { + "arguments not a map", + "{\n" + " \"command\": \"stat-lease6-get\",\n" + " \"arguments\": \"not a map\"\n" + "}", + "'arguments' parameter is not a map" + }, { "subnet-id 0", "{\n" @@ -1101,6 +1157,20 @@ TEST_F(StatCmdsTest, StatLease6GetBadParams) { "}", "'last-subnet-id' must be greater than 'first-subnet-id'" }, + { + "both subnet and range", + "{\n" + " \"command\": \"stat-lease6-get\",\n" + " \"arguments\": {" + " \"subnet-id\": 10,\n" + " \"subnet-range\": {\n" + " \"first-subnet-id\": 20," + " \"last-subnet-id\": 40" + " }\n" + " }\n" + "}", + "cannot specify both subnet-id and subnet-range" + } }; for (auto test = tests.begin(); test != tests.end(); ++test) { @@ -1128,7 +1198,29 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " \"arguments\": {" " }\n" "}", - "stat-lease6-get: 5 rows found", + "stat-lease6-get[all subnets]: 5 rows found", + "{\n" + "\"result-set\": {\n" + " \"columns\": [\n" + " \"subnet-id\", \"total-nas\", \"assigned-nas\",\n" + " \"declined-nas\", \"total-pds\", \"assigned-pds\"\n" + " ],\n" + " \"rows\": [\n" + " [ 10, 65536, 2, 3, 0, 0 ],\n" + " [ 20, 16777216, 3, 0, 0, 0 ],\n" + " [ 30, 16, 1, 1, 65536, 3 ],\n" + " [ 40, 16777216, 0, 0, 0, 0 ],\n" + " [ 50, 0, 0, 0, 65536, 2 ]\n" + " ],\n" + " \"timestamp\": \"2018-05-04 15:03:37.000000\" }\n" + "}\n" + }, + { + "ALL-Subnets6 arugments omitted", + "{\n" + " \"command\": \"stat-lease6-get\"\n" + "}", + "stat-lease6-get[all subnets]: 5 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1153,7 +1245,7 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " \"subnet-id\": 20" " }\n" "}", - "stat-lease6-get: 1 rows found", + "stat-lease6-get[subnet-id=20]: 1 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1177,7 +1269,7 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " }\n" " }\n" "}", - "stat-lease6-get: 3 rows found", + "stat-lease6-get[subnets 10 through 30]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1203,7 +1295,7 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " }\n" " }\n" "}", - "stat-lease6-get: 3 rows found", + "stat-lease6-get[subnets 20 through 40]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1229,7 +1321,7 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " }\n" " }\n" "}", - "stat-lease6-get: 3 rows found", + "stat-lease6-get[subnets 30 through 50]: 3 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1255,7 +1347,7 @@ TEST_F(StatCmdsTest, statLease6GetValid) { " }\n" " }\n" "}", - "stat-lease6-get: 2 rows found", + "stat-lease6-get[subnets 25 through 45]: 2 rows found", "{\n" "\"result-set\": {\n" " \"columns\": [\n" @@ -1299,7 +1391,7 @@ TEST_F(StatCmdsTest, statLease6GetSubnetsNotFound) { " \"subnet-id\": 88" " }\n" "}", - "stat-lease6-get: no matching data, subnet-id: 88 does not exist", + "stat-lease6-get[subnet-id=88]: no matching data, subnet-id: 88 does not exist", "{}" }, { @@ -1313,7 +1405,7 @@ TEST_F(StatCmdsTest, statLease6GetSubnetsNotFound) { " }\n" " }\n" "}", - "stat-lease6-get: no matching data, selected ID range: 2 through 6 includes no known subnets", + "stat-lease6-get[subnets 2 through 6]: no matching data, selected ID range: 2 through 6 includes no known subnets", "{}" }, { @@ -1327,7 +1419,7 @@ TEST_F(StatCmdsTest, statLease6GetSubnetsNotFound) { " }\n" " }\n" "}", - "stat-lease6-get: no matching data, selected ID range: 200 through 600 includes no known subnets", + "stat-lease6-get[subnets 200 through 600]: no matching data, selected ID range: 200 through 600 includes no known subnets", "{}" } };