2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#549] address review comments

This commit is contained in:
Andrei Pavel
2023-04-19 19:19:44 +03:00
parent afc1d93279
commit c8048badbb
18 changed files with 60 additions and 34 deletions

View File

@@ -112,7 +112,7 @@ As with other update commands, this command overwrites all the contents of the
entry. If the client class previously had a resource assigned to it, and the entry. If the client class previously had a resource assigned to it, and the
``class-update`` command is missing the resource, it is deleted from the server ``class-update`` command is missing the resource, it is deleted from the server
configuration. If an incremental update of the class is desired, then this can configuration. If an incremental update of the class is desired, then this can
be achieved by doing a `class-get <command-class-get_>`_ to get the full picture be achieved by doing a `class-get <command-class-get_>`_ to get the current state
of the client class, picking the client class out of the response, modifying it of the client class, picking the client class out of the response, modifying it
to the required outcome, and then issuing the ``client-update`` command with the to the required outcome, and then issuing the ``client-update`` command with the
resulting client class attached. resulting client class attached.

View File

@@ -144,7 +144,7 @@ address can be assigned like so:
} }
} }
But it can also take many more parameters, for example: It can also take many more parameters, for example:
.. code-block:: json .. code-block:: json
@@ -750,7 +750,7 @@ address can be assigned like so:
} }
} }
But it can also take many more parameters, for example: It can also take many more parameters, for example:
.. code-block:: json .. code-block:: json
@@ -838,7 +838,7 @@ As with other update and set commands, this command overwrites all the contents
of the entry. If the host previously had a resource assigned to it, and the of the entry. If the host previously had a resource assigned to it, and the
``reservation-update`` command is missing the resource, it is deleted from the ``reservation-update`` command is missing the resource, it is deleted from the
database. If an incremental update of the host is desired, then this can be database. If an incremental update of the host is desired, then this can be
achieved by doing a ``reservation-get-by-id`` to get the full picture of the achieved by doing a ``reservation-get-by-id`` to get the current state of the
host, picking the host out of the response, modifying it to the required host, picking the host out of the response, modifying it to the required
outcome, and then issuing the ``reservation-update`` command with the resulting outcome, and then issuing the ``reservation-update`` command with the resulting
host attached. host attached.

View File

@@ -908,7 +908,7 @@ entry. If the lease previously had a resource assigned to it, and the
deleted from the lease database. If an incremental update of the lease is deleted from the lease database. If an incremental update of the lease is
desired, then this can be achieved by doing a desired, then this can be achieved by doing a
`lease4-get <command-lease4-get_>`_ / `lease6-get <command-lease6-get_>`_ `lease4-get <command-lease4-get_>`_ / `lease6-get <command-lease6-get_>`_
command to get the full picture of the lease, picking the lease out of the command to get the current state of the lease, picking the lease out of the
response, modifying it to the required outcome, and then issuing the response, modifying it to the required outcome, and then issuing the
``lease4-update``/``lease6-update`` command with the resulting lease attached. ``lease4-update``/``lease6-update`` command with the resulting lease attached.

View File

@@ -466,7 +466,7 @@ The response to this command has the following structure:
} }
As with other update commands, this command overwrites all the contents of the As with other update commands, this command overwrites all the contents of the
entry. If the IPv4 subnet previously had a resource assigned to it, and the entry. If the IPv6 subnet previously had a resource assigned to it, and the
``subnet6-update`` command is missing the resource, it is deleted from the ``subnet6-update`` command is missing the resource, it is deleted from the
server configuration. If an incremental update of the subnet is desired, then server configuration. If an incremental update of the subnet is desired, then
this can be achieved with `subnet6-delta-add <command-subnet6-delta-add_>`_. this can be achieved with `subnet6-delta-add <command-subnet6-delta-add_>`_.

View File

@@ -33,7 +33,7 @@ public:
/// @brief lease4-add, lease6-add command handler /// @brief lease4-add, lease6-add command handler
/// ///
/// This command attempts to add a lease. /// This command attempts to add a lease.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -169,7 +169,7 @@ public:
/// @brief lease4-get, lease6-get command handler /// @brief lease4-get, lease6-get command handler
/// ///
/// This command attempts to retrieve a lease that match selected criteria. /// This command attempts to retrieve a lease that match selected criteria.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -346,7 +346,7 @@ public:
/// ///
/// This command attempts to delete an IPv4 lease that match selected /// This command attempts to delete an IPv4 lease that match selected
/// criteria. /// criteria.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. If the lease is deleted successfully, then a call /// argument accordingly. If the lease is deleted successfully, then a call
/// to @ref isc::dhcp::queueNCR() is issued, which to generate an /// to @ref isc::dhcp::queueNCR() is issued, which to generate an
@@ -384,7 +384,7 @@ public:
/// @brief lease6-del command handler /// @brief lease6-del command handler
/// ///
/// This command attempts to delete a lease that match selected criteria. /// This command attempts to delete a lease that match selected criteria.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. If the lease is deleted successfully, then a call /// argument accordingly. If the lease is deleted successfully, then a call
/// to @ref isc::dhcp::queueNCR() is issued, which to generate an /// to @ref isc::dhcp::queueNCR() is issued, which to generate an
@@ -427,7 +427,7 @@ public:
/// specified will replace existing lease. The only condition is that /// specified will replace existing lease. The only condition is that
/// the IP address must not change. If you want to change the IP address, /// the IP address must not change. If you want to change the IP address,
/// please use lease4-del and lease4-add instead. /// please use lease4-del and lease4-add instead.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -458,7 +458,7 @@ public:
/// specified will replace existing lease. The only condition is that /// specified will replace existing lease. The only condition is that
/// the IP address must not change. If you want to change the IP address, /// the IP address must not change. If you want to change the IP address,
/// please use lease6-del and lease6-add instead. /// please use lease6-del and lease6-add instead.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -490,7 +490,7 @@ public:
/// subnet. Currently the leases are removed from the database, /// subnet. Currently the leases are removed from the database,
/// without any processing (like calling hooks or doing DDNS /// without any processing (like calling hooks or doing DDNS
/// cleanups). /// cleanups).
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -514,7 +514,7 @@ public:
/// subnet. Currently the leases are removed from the database, /// subnet. Currently the leases are removed from the database,
/// without any processing (like calling hooks or doing DDNS /// without any processing (like calling hooks or doing DDNS
/// cleanups). /// cleanups).
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -537,7 +537,7 @@ public:
/// This command attempts to resend the DDNS updates for the IPv4 lease that /// This command attempts to resend the DDNS updates for the IPv4 lease that
/// matches the selection criteria. /// matches the selection criteria.
/// ///
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -562,7 +562,7 @@ public:
/// This command attempts to resend the DDNS updates for the IPv6 lease that /// This command attempts to resend the DDNS updates for the IPv6 lease that
/// matches the selection criteria. /// matches the selection criteria.
/// ///
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///
@@ -587,7 +587,7 @@ public:
/// This commands attempts to write the lease database to a CSV file. /// This commands attempts to write the lease database to a CSV file.
/// Currently it is supported only by the memfile database and /// Currently it is supported only by the memfile database and
/// should be reserved to emergency situations. /// should be reserved to emergency situations.
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// ///

View File

@@ -31,7 +31,7 @@ public:
/// ///
/// 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). /// more subnets based upon subnet selection criteria (or lack thereof).
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// arguments accordingly. /// arguments accordingly.
/// { /// {
@@ -75,7 +75,7 @@ public:
/// ///
/// 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). /// more subnets based upon subnet selection criteria (or lack thereof).
/// It extracts the command name and arguments from the given Callouthandle, /// It extracts the command name and arguments from the given CalloutHandle,
/// attempts to process them, and then set's the handle's "response" /// attempts to process them, and then set's the handle's "response"
/// argument accordingly. /// argument accordingly.
/// { /// {

View File

@@ -170,7 +170,7 @@ createCommand(const std::string& command,
std::string std::string
parseCommand(ConstElementPtr& arg, ConstElementPtr command) { parseCommand(ConstElementPtr& arg, ConstElementPtr command) {
if (!command) { if (!command) {
isc_throw(CtrlChannelError, "No command specified"); isc_throw(CtrlChannelError, "no command specified");
} }
if (command->getType() != Element::map) { if (command->getType() != Element::map) {
isc_throw(CtrlChannelError, "invalid command: expected toplevel entry to be a map, got " isc_throw(CtrlChannelError, "invalid command: expected toplevel entry to be a map, got "

View File

@@ -462,8 +462,6 @@ public:
/// @brief Attempts to update an existing host entry. /// @brief Attempts to update an existing host entry.
/// ///
/// @param host the host up to date with the requested changes /// @param host the host up to date with the requested changes
///
/// @return true if deletion was successful, false if the host was not there.
virtual void update(HostPtr const& host) = 0; virtual void update(HostPtr const& host) = 0;
/// @brief Return backend type /// @brief Return backend type
@@ -480,7 +478,7 @@ public:
/// @return Parameters of the backend. /// @return Parameters of the backend.
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const { virtual isc::db::DatabaseConnection::ParameterMap getParameters() const {
return (isc::db::DatabaseConnection::ParameterMap()); return (isc::db::DatabaseConnection::ParameterMap());
}; }
/// @brief Commit Transactions /// @brief Commit Transactions
/// ///

View File

@@ -960,7 +960,7 @@ CfgHosts::add(const HostPtr& host) {
" is added to the configuration"); " is added to the configuration");
} }
// At least one subnet ID must be used // At least one subnet ID must be used.
if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED && if (host->getIPv4SubnetID() == SUBNET_ID_UNUSED &&
host->getIPv6SubnetID() == SUBNET_ID_UNUSED) { host->getIPv6SubnetID() == SUBNET_ID_UNUSED) {
isc_throw(BadValue, "must not use both IPv4 and IPv6 subnet ids of" isc_throw(BadValue, "must not use both IPv4 and IPv6 subnet ids of"

View File

@@ -590,6 +590,10 @@ public:
const uint8_t* identifier_begin, const size_t identifier_len); const uint8_t* identifier_begin, const size_t identifier_len);
/// @brief Implements @ref BaseHostDataSource::update() for config hosts. /// @brief Implements @ref BaseHostDataSource::update() for config hosts.
///
/// Attempts to update an existing host entry.
///
/// @param host the host up to date with the requested changes
void update(HostPtr const& host); void update(HostPtr const& host);
/// @brief Return backend type /// @brief Return backend type

View File

@@ -556,6 +556,10 @@ public:
const uint8_t* identifier_begin, const size_t identifier_len); const uint8_t* identifier_begin, const size_t identifier_len);
/// @brief Implements @ref BaseHostDataSource::update() for alternate sources. /// @brief Implements @ref BaseHostDataSource::update() for alternate sources.
///
/// Attempts to update an existing host entry.
///
/// @param host the host up to date with the requested changes
void update(HostPtr const& host); void update(HostPtr const& host);
/// @brief Return backend type /// @brief Return backend type

View File

@@ -404,6 +404,10 @@ public:
const asiolink::IOAddress& address) const; const asiolink::IOAddress& address) const;
/// @brief Implements @ref BaseHostDataSource::update() for MySQL. /// @brief Implements @ref BaseHostDataSource::update() for MySQL.
///
/// Attempts to update an existing host entry.
///
/// @param host the host up to date with the requested changes
void update(HostPtr const& host); void update(HostPtr const& host);
/// @brief Return backend type /// @brief Return backend type

View File

@@ -452,6 +452,10 @@ public:
const asiolink::IOAddress& address) const; const asiolink::IOAddress& address) const;
/// @brief Implements @ref BaseHostDataSource::update() for PostgreSQL. /// @brief Implements @ref BaseHostDataSource::update() for PostgreSQL.
///
/// Attempts to update an existing host entry.
///
/// @param host the host up to date with the requested changes
void update(HostPtr const& host); void update(HostPtr const& host);
/// @brief Return backend type /// @brief Return backend type

View File

@@ -1445,6 +1445,7 @@ TEST_F(PgSqlHostDataSourceTest, updateMultiThreading) {
MultiThreadingTest mt(true); MultiThreadingTest mt(true);
testUpdate(); testUpdate();
} }
/// @brief Test fixture class for validating @c HostMgr using /// @brief Test fixture class for validating @c HostMgr using
/// PostgreSQL as alternate host data source. /// PostgreSQL as alternate host data source.
class PgSQLHostMgrTest : public HostMgrTest { class PgSQLHostMgrTest : public HostMgrTest {

View File

@@ -377,11 +377,20 @@ MemHostDataSource::del6(const SubnetID& subnet_id,
void void
MemHostDataSource::update(HostPtr const& host) { MemHostDataSource::update(HostPtr const& host) {
for (auto h = store_.begin(); h != store_.end(); ++h) { bool deleted(false);
if ((*h)->getHostId() == host->getHostId()) { if (host->getIPv4SubnetID() != SUBNET_ID_UNUSED) {
store_.erase(h); vector<uint8_t> const& identifier(host->getIdentifier());
break; deleted = del4(host->getIPv4SubnetID(), host->getIdentifierType(), identifier.data(),
} identifier.size());
} else if (host->getIPv6SubnetID() != SUBNET_ID_UNUSED) {
vector<uint8_t> const& identifier(host->getIdentifier());
deleted = del6(host->getIPv6SubnetID(), host->getIdentifierType(), identifier.data(),
identifier.size());
} else {
isc_throw(HostNotFound, "Mandatory 'subnet-id' parameter missing.");
}
if (!deleted) {
isc_throw(HostNotFound, "Host not updated (not found).");
} }
store_.push_back(host); store_.push_back(host);
} }

View File

@@ -258,6 +258,10 @@ public:
const uint8_t* identifier_begin, const size_t identifier_len); const uint8_t* identifier_begin, const size_t identifier_len);
/// @brief Implements @ref BaseHostDataSource::update() for memory hosts. /// @brief Implements @ref BaseHostDataSource::update() for memory hosts.
///
/// Attempts to update an existing host entry.
///
/// @param host the host up to date with the requested changes
void update(HostPtr const& host); void update(HostPtr const& host);
/// @brief Return backend type /// @brief Return backend type

View File

@@ -5,7 +5,7 @@
"This command adds a new host reservation. The reservation may include IPv4 addresses, IPv6 addresses, IPv6 prefixes, various identifiers, a class the client will be assigned to, DHCPv4 and DHCPv6 options, and more." "This command adds a new host reservation. The reservation may include IPv4 addresses, IPv6 addresses, IPv6 prefixes, various identifiers, a class the client will be assigned to, DHCPv4 and DHCPv6 options, and more."
], ],
"cmd-comment": [ "cmd-comment": [
"Note that ip-address, client-id, next-server, server-hostname, and boot-file-name are IPv4-specific. duid, ip-addresses, and prefixes are IPv6-specific." "Note that ip-address, client-id, next-server, server-hostname, and boot-file-name are IPv4-specific. ip-addresses, and prefixes are IPv6-specific."
], ],
"cmd-syntax": [ "cmd-syntax": [
"{", "{",
@@ -13,7 +13,6 @@
" \"arguments\": {", " \"arguments\": {",
" \"reservation\": {", " \"reservation\": {",
" \"boot-file-name\": <string>,", " \"boot-file-name\": <string>,",
" \"comment\": <string>,",
" \"client-id\": <string>,", " \"client-id\": <string>,",
" \"circuit-id\": <string>,", " \"circuit-id\": <string>,",
" \"duid\": <string>,", " \"duid\": <string>,",

View File

@@ -1,11 +1,11 @@
{ {
"access": "write", "access": "write",
"avail": "2.4.0", "avail": "2.3.7",
"brief": [ "brief": [
"This command updates an existing host reservation. The reservation has to include host identifiers and a subnet identifier and may include IPv4 addresses, IPv6 addresses, IPv6 prefixes, various identifiers, a class the client will be assigned to, DHCPv4 and DHCPv6 options, and more." "This command updates an existing host reservation. The reservation has to include host identifiers and a subnet identifier and may include IPv4 addresses, IPv6 addresses, IPv6 prefixes, various identifiers, a class the client will be assigned to, DHCPv4 and DHCPv6 options, and more."
], ],
"cmd-comment": [ "cmd-comment": [
"Note that ip-address, client-id, next-server, server-hostname, and boot-file-name are IPv4-specific. duid, ip-addresses, and prefixes are IPv6-specific." "Note that ip-address, client-id, next-server, server-hostname, and boot-file-name are IPv4-specific. ip-addresses, and prefixes are IPv6-specific."
], ],
"cmd-syntax": [ "cmd-syntax": [
"{", "{",
@@ -13,7 +13,6 @@
" \"arguments\": {", " \"arguments\": {",
" \"reservation\": {", " \"reservation\": {",
" \"boot-file-name\": <string>,", " \"boot-file-name\": <string>,",
" \"comment\": <string>,",
" \"client-id\": <string>,", " \"client-id\": <string>,",
" \"circuit-id\": <string>,", " \"circuit-id\": <string>,",
" \"duid\": <string>,", " \"duid\": <string>,",