From: Francis Dupont Date: Fri, 11 Oct 2019 23:04:53 +0000 (+0200) Subject: [392-search-of-reservations-by-hostname] Addressed comments X-Git-Tag: Kea-1.7.1~70 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9b5fc564660787136a59adbfb2772e1dc925f65;p=thirdparty%2Fkea.git [392-search-of-reservations-by-hostname] Addressed comments --- diff --git a/doc/sphinx/arm/hooks.rst b/doc/sphinx/arm/hooks.rst index 7e3cd5ee39..9f8dba39a0 100644 --- a/doc/sphinx/arm/hooks.rst +++ b/doc/sphinx/arm/hooks.rst @@ -1231,7 +1231,7 @@ The subnet-id Parameter Prior to diving into the individual commands, it is worth discussing the parameter, ``subnet-id``. Currently this parameter is mandatory for all of the -commands supplied by this library at the exception of +commands supplied by this library with the exception of reservation-get-by-hostname where it is optional. In previous versions of Kea, reservations had to belong to a specific subnet; as of Kea 1.5.0, reservations may @@ -1687,7 +1687,7 @@ returns some IPv4 hosts: ] }, "result": 0, - "text": "72 IPv4 host(s) found." + "text": "5 IPv4 host(s) found." } The response returned by ``reservation-get-by-hostname`` can be long diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc index 49521aebe4..00988ffb10 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.cc +++ b/src/lib/dhcpsrv/cql_host_data_source.cc @@ -1503,6 +1503,7 @@ CqlHostExchange::prepareExchange(const HostPtr& host, // lower_case_hostname: text lower_case_hostname_ = host->getLowerHostname(); if (lower_case_hostname_.size() > HOSTNAME_MAX_LEN) { + // Should never happen... isc_throw(BadValue, "CqlHostExchange::prepareExchange(): lower " "case hostname " << lower_case_hostname_ << " of length " << lower_case_hostname_.size() diff --git a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc index bf4602b928..d4fbcf7e96 100644 --- a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc @@ -339,14 +339,14 @@ TEST_F(CqlHostDataSourceTest, getAllbyHostname) { // Verifies that IPv4 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(CqlHostDataSourceTest, getAllbyHostname4) { - testGetAllbyHostname4(); +TEST_F(CqlHostDataSourceTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(); } // Verifies that IPv6 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(CqlHostDataSourceTest, getAllbyHostname6) { - testGetAllbyHostname6(); +TEST_F(CqlHostDataSourceTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(); } // Verifies that IPv4 host reservations in the same subnet can be retrieved diff --git a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc index 573cd24297..4cd15159dd 100644 --- a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc @@ -145,8 +145,8 @@ protected: /// inserted. /// @param data_source2 Host data source to which second reservation is /// inserted. - void testGetAllbyHostname4(BaseHostDataSource& data_source1, - BaseHostDataSource& data_source2); + void testGetAllbyHostnameSubnet4(BaseHostDataSource& data_source1, + BaseHostDataSource& data_source2); /// @brief This test verifies that HostMgr returns all reservations for the /// specified hostname and DHCPv6 subnet. @@ -158,8 +158,8 @@ protected: /// inserted. /// @param data_source2 Host data source to which second reservation is /// inserted. - void testGetAllbyHostname6(BaseHostDataSource& data_source1, - BaseHostDataSource& data_source2); + void testGetAllbyHostnameSubnet6(BaseHostDataSource& data_source1, + BaseHostDataSource& data_source2); /// @brief This test verifies that HostMgr returns all reservations for the /// specified DHCPv4 subnet by pages. @@ -456,8 +456,8 @@ HostMgrTest::testGetAllbyHostname(BaseHostDataSource& data_source1, } void -HostMgrTest::testGetAllbyHostname4(BaseHostDataSource& data_source1, - BaseHostDataSource& data_source2) { +HostMgrTest::testGetAllbyHostnameSubnet4(BaseHostDataSource& data_source1, + BaseHostDataSource& data_source2) { // Initially, no reservations should be present. ConstHostCollection hosts = HostMgr::instance().getAllbyHostname4("host", SubnetID(1)); @@ -505,8 +505,8 @@ HostMgrTest::testGetAllbyHostname4(BaseHostDataSource& data_source1, } void -HostMgrTest::testGetAllbyHostname6(BaseHostDataSource& data_source1, - BaseHostDataSource& data_source2) { +HostMgrTest::testGetAllbyHostnameSubnet6(BaseHostDataSource& data_source1, + BaseHostDataSource& data_source2) { // Initially, no reservations should be present. ConstHostCollection hosts = HostMgr::instance().getAllbyHostname6("host", SubnetID(1)); @@ -982,15 +982,15 @@ TEST_F(HostMgrTest, getAllbyHostname) { // This test verifies that HostMgr returns all reservations for the specified // hostname and DHCPv4 subnet. The reservations are defined in the server's // configuration. -TEST_F(HostMgrTest, getAllbyHostname4) { - testGetAllbyHostname4(*getCfgHosts(), *getCfgHosts()); +TEST_F(HostMgrTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(*getCfgHosts(), *getCfgHosts()); } // This test verifies that HostMgr returns all reservations for the specified // hostname and DHCPv6 subnet. The reservations are defined in the server's // configuration. TEST_F(HostMgrTest, getAllbyHostname6) { - testGetAllbyHostname4(*getCfgHosts(), *getCfgHosts()); + testGetAllbyHostnameSubnet4(*getCfgHosts(), *getCfgHosts()); } // This test verifies that HostMgr returns all reservations for the @@ -1246,15 +1246,15 @@ TEST_F(MySQLHostMgrTest, getAllbyHostname) { // This test verifies that reservations for a particular hostname and // DHCPv4 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(MySQLHostMgrTest, getAllbyHostname4) { - testGetAllbyHostname4(*getCfgHosts(), HostMgr::instance()); +TEST_F(MySQLHostMgrTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular hostname and // DHCPv6 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(MySQLHostMgrTest, getAllbyHostname6) { - testGetAllbyHostname6(*getCfgHosts(), HostMgr::instance()); +TEST_F(MySQLHostMgrTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular subnet can @@ -1391,15 +1391,15 @@ TEST_F(PostgreSQLHostMgrTest, getAllbyHostname) { // This test verifies that reservations for a particular hostname and // DHCPv4 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(PostgreSQLHostMgrTest, getAllbyHostname4) { - testGetAllbyHostname4(*getCfgHosts(), HostMgr::instance()); +TEST_F(PostgreSQLHostMgrTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular hostname and // DHCPv6 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(PostgreSQLHostMgrTest, getAllbyHostname6) { - testGetAllbyHostname6(*getCfgHosts(), HostMgr::instance()); +TEST_F(PostgreSQLHostMgrTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular subnet can @@ -1517,15 +1517,15 @@ TEST_F(CQLHostMgrTest, getAllbyHostname) { // This test verifies that reservations for a particular hostname and // DHCPv4 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(CQLHostMgrTest, getAllbyHostname4) { - testGetAllbyHostname4(*getCfgHosts(), HostMgr::instance()); +TEST_F(CQLHostMgrTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular hostname and // DHCPv6 subnet can be retrieved from the configuration file and a // database simultaneously. -TEST_F(CQLHostMgrTest, getAllbyHostname6) { - testGetAllbyHostname6(*getCfgHosts(), HostMgr::instance()); +TEST_F(CQLHostMgrTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(*getCfgHosts(), HostMgr::instance()); } // This test verifies that reservations for a particular subnet can diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index e6e8b4506c..54f294ad51 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -328,14 +328,14 @@ TEST_F(MySqlHostDataSourceTest, getAllbyHostname) { // Verifies that IPv4 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(MySqlHostDataSourceTest, getAllbyHostname4) { - testGetAllbyHostname4(); +TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(); } // Verifies that IPv6 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(MySqlHostDataSourceTest, getAllbyHostname6) { - testGetAllbyHostname6(); +TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(); } // Verifies that IPv4 host reservations in the same subnet can be retrieved diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index c456940cf0..e8e149d482 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -314,14 +314,14 @@ TEST_F(PgSqlHostDataSourceTest, getAllbyHostname) { // Verifies that IPv4 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(PgSqlHostDataSourceTest, getAllbyHostname4) { - testGetAllbyHostname4(); +TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet4) { + testGetAllbyHostnameSubnet4(); } // Verifies that IPv6 host reservations with the same hostname and in // the same subnet can be retrieved -TEST_F(PgSqlHostDataSourceTest, getAllbyHostname6) { - testGetAllbyHostname6(); +TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet6) { + testGetAllbyHostnameSubnet6(); } // Verifies that IPv4 host reservations in the same subnet can be retrieved diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index b3e1c14429..6638a3423d 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -525,7 +525,7 @@ GenericHostDataSourceTest::testGetAllbyHostname() { } void -GenericHostDataSourceTest::testGetAllbyHostname4() { +GenericHostDataSourceTest::testGetAllbyHostnameSubnet4() { // Make sure we have a pointer to the host data source. ASSERT_TRUE(hdsptr_); @@ -549,7 +549,9 @@ GenericHostDataSourceTest::testGetAllbyHostname4() { HostPtr host4 = HostDataSourceUtils::initializeHost4("192.0.2.4", id); host4->setHostname("host.example.com"); - // Set them in the same subnets. + HostPtr host5 = HostDataSourceUtils::initializeHost4("192.0.2.5", id); + + // Set them in the same subnet at the exception of host5. SubnetID subnet4 = host1->getIPv4SubnetID(); host2->setIPv4SubnetID(subnet4); host3->setIPv4SubnetID(subnet4); @@ -564,6 +566,7 @@ GenericHostDataSourceTest::testGetAllbyHostname4() { ASSERT_NO_THROW(hdsptr_->add(host2)); ASSERT_NO_THROW(hdsptr_->add(host3)); ASSERT_NO_THROW(hdsptr_->add(host4)); + ASSERT_NO_THROW(hdsptr_->add(host5)); // Retrieve unknown name. ConstHostCollection from_hds = hdsptr_->getAllbyHostname4("foo", subnet4); @@ -606,7 +609,7 @@ GenericHostDataSourceTest::testGetAllbyHostname4() { } void -GenericHostDataSourceTest::testGetAllbyHostname6() { +GenericHostDataSourceTest::testGetAllbyHostnameSubnet6() { // Make sure we have a pointer to the host data source. ASSERT_TRUE(hdsptr_); @@ -630,7 +633,9 @@ GenericHostDataSourceTest::testGetAllbyHostname6() { HostPtr host4 = HostDataSourceUtils::initializeHost6("2001:db8::4", id, false); host4->setHostname("host.example.com"); - // Set them in the same subnets. + HostPtr host5 = HostDataSourceUtils::initializeHost6("2001:db8::5", id, false); + + // Set them in the same subnet at the exception of host5. SubnetID subnet4 = host1->getIPv4SubnetID(); host2->setIPv4SubnetID(subnet4); host3->setIPv4SubnetID(subnet4); @@ -645,6 +650,7 @@ GenericHostDataSourceTest::testGetAllbyHostname6() { ASSERT_NO_THROW(hdsptr_->add(host2)); ASSERT_NO_THROW(hdsptr_->add(host3)); ASSERT_NO_THROW(hdsptr_->add(host4)); + ASSERT_NO_THROW(hdsptr_->add(host5)); // Retrieve unknown name. ConstHostCollection from_hds = hdsptr_->getAllbyHostname6("foo", subnet6); diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h index 7c4103f872..7686cf5447 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h @@ -212,13 +212,13 @@ public: /// hostname and in the same subnet can be retrieved properly. /// /// Uses gtest macros to report failures. - void testGetAllbyHostname4(); + void testGetAllbyHostnameSubnet4(); /// @brief Test that Verifies that IPv6 host reservations with the same /// hostname and in the same subnet can be retrieved properly. /// /// Uses gtest macros to report failures. - void testGetAllbyHostname6(); + void testGetAllbyHostnameSubnet6(); /// @brief Test that Verifies that pages of host reservations in the /// same subnet can be retrieved properly.