Browse Source

[master] MySQL and PostgreSQL backends now support HR client classes

    Merges in trac4279.
Thomas Markwalder 8 years ago
parent
commit
6990ab9d54

+ 0 - 1
src/lib/dhcpsrv/mysql_host_data_source.cc

@@ -304,7 +304,6 @@ public:
             strncpy(dhcp6_client_classes_, classes6_txt.c_str(), CLIENT_CLASSES_MAX_LEN - 1);
             bind_[8].buffer = dhcp6_client_classes_;
             bind_[8].buffer_length = classes6_txt.length();
-            bind_[8].buffer_length = sizeof(host->getClientClasses6());
 
         } catch (const std::exception& ex) {
             isc_throw(DbOperationError,

+ 160 - 4
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc

@@ -327,10 +327,9 @@ GenericHostDataSourceTest::compareReservations6(IPv6ResrvRange resrv1,
 }
 
 void
-GenericHostDataSourceTest::compareClientClasses(const ClientClasses& /*classes1*/,
-                                                const ClientClasses& /*classes2*/) {
-    /// @todo: Implement client classes comparison.
-    ///        This is part of the work for #4213.
+GenericHostDataSourceTest::compareClientClasses(const ClientClasses& classes1,
+                                                const ClientClasses& classes2) {
+    EXPECT_TRUE(std::equal(classes1.begin(), classes1.end(), classes2.begin()));
 }
 
 void
@@ -1152,6 +1151,163 @@ void GenericHostDataSourceTest::testOptionsReservations46(const bool formatted)
     ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
 }
 
+void
+GenericHostDataSourceTest::testMultipleClientClasses4() {
+    ASSERT_TRUE(hdsptr_);
+
+    // Create the Host object.
+    HostPtr host = initializeHost4("192.0.2.5", Host::IDENT_HWADDR);
+
+    // Add v4 classes to the host.
+    for (int i = 0; i < 4; ++i) {
+        std::ostringstream os;
+        os << "class4_" << i;
+        host->addClientClass4(os.str());
+    }
+
+    // Add the host.
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // Subnet id will be used in quries to the database.
+    SubnetID subnet_id = host->getIPv4SubnetID();
+
+    // Fetch the host via:
+    // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
+    ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
+    ASSERT_EQ(1, hosts_by_id.size());
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+
+    // Fetch the host via:
+    // getAll(const Host::IdentifierType, const uint8_t* identifier_begin,
+    //       const size_t identifier_len) const;
+    hosts_by_id = hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
+                                  host->getIdentifier().size());
+    ASSERT_EQ(1, hosts_by_id.size());
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+
+    // Fetch the host via
+    // getAll4(const asiolink::IOAddress& address) const;
+    hosts_by_id = hdsptr_->getAll4(IOAddress("192.0.2.5"));
+    ASSERT_EQ(1, hosts_by_id.size());
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+
+    // Fetch the host via
+    // get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
+    //     const DuidPtr& duid = DuidPtr()) const;
+    ConstHostPtr from_hds = hdsptr_->get4(subnet_id, host->getHWAddress());
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+
+    // Fetch the host via
+    // get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
+    //     const uint8_t* identifier_begin, const size_t identifier_len) const;
+    from_hds = hdsptr_->get4(subnet_id, host->getIdentifierType(), &host->getIdentifier()[0],
+                             host->getIdentifier().size());
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+
+    // Fetch the host via:
+    // get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
+    from_hds = hdsptr_->get4(subnet_id, IOAddress("192.0.2.5"));
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+}
+
+void
+GenericHostDataSourceTest::testMultipleClientClasses6() {
+    ASSERT_TRUE(hdsptr_);
+
+    // Create the Host object.
+    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+
+    // Add v6 classes to the host.
+    for (int i = 0; i < 4; ++i) {
+        std::ostringstream os;
+        os << "class6_" << i;
+        host->addClientClass6(os.str());
+    }
+
+    // Add the host.
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // Subnet id will be used in quries to the database.
+    SubnetID subnet_id = host->getIPv6SubnetID();
+
+    // Fetch the host via:
+    // getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid = DuidPtr()) const;
+    ConstHostCollection hosts_by_id = hdsptr_->getAll(host->getHWAddress());
+    ASSERT_EQ(1, hosts_by_id.size());
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+
+    // getAll(const Host::IdentifierType& identifier_type,
+    //        const uint8_t* identifier_begin,
+    //        const size_t identifier_len) const;
+    hosts_by_id = hdsptr_->getAll(host->getIdentifierType(), &host->getIdentifier()[0],
+                                  host->getIdentifier().size());
+    ASSERT_EQ(1, hosts_by_id.size());
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, *hosts_by_id.begin()));
+
+    // get6(const SubnetID& subnet_id, const DuidPtr& duid,
+    //      const HWAddrPtr& hwaddr = HWAddrPtr()) const;
+    ConstHostPtr from_hds = hdsptr_->get6(subnet_id, DuidPtr(), host->getHWAddress());
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+
+    // Fetch the host via:
+    // get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
+    //     const uint8_t* identifier_begin, const size_t identifier_len) const;
+    from_hds = hdsptr_->get6(subnet_id, Host::IDENT_HWADDR,
+                                           &host->getIdentifier()[0],
+                                           host->getIdentifier().size());
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+
+    // Fetch the host via:
+    // get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
+    from_hds = hdsptr_->get6(IOAddress("2001:db8::1"), 128);
+    ASSERT_TRUE(from_hds);
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+}
+
+void
+GenericHostDataSourceTest::testMultipleClientClassesBoth() {
+    /// Add host reservation with a multiple v4 and v6 client-classes,
+    /// retrieve it and make sure that all client classes are retrieved
+    /// properly.
+    ASSERT_TRUE(hdsptr_);
+
+    // Create the Host object.
+    HostPtr host = initializeHost6("2001:db8::1", Host::IDENT_HWADDR, false);
+
+    // Add v4 classes to the host.
+    for (int i = 0; i < 4; ++i) {
+        std::ostringstream os;
+        os << "class4_" << i;
+        host->addClientClass4(os.str());
+    }
+
+    // Add v6 classes to the host.
+    for (int i = 0; i < 4; ++i) {
+        std::ostringstream os;
+        os << "class6_" << i;
+        host->addClientClass6(os.str());
+    }
+
+    // Add the host.
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // Subnet id will be used in quries to the database.
+    SubnetID subnet_id = host->getIPv6SubnetID();
+
+    // Fetch the host from the source.
+    ConstHostPtr from_hds = hdsptr_->get6(subnet_id, Host::IDENT_HWADDR,
+                                           &host->getIdentifier()[0],
+                                           host->getIdentifier().size());
+    ASSERT_TRUE(from_hds);
+
+    // Verify they match.
+    ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
+}
 
 }; // namespace test
 }; // namespace dhcp

+ 22 - 1
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h

@@ -137,7 +137,7 @@ public:
     /// @param classes1 first list of client classes
     /// @param classes2 second list of client classes
     void compareClientClasses(const ClientClasses& classes1,
-                              const ClientClasses& classes2);                           
+                              const ClientClasses& classes2);
 
     /// @brief Compares options within two configurations.
     ///
@@ -475,6 +475,27 @@ public:
     /// should be stored in the textual format in the database.
     void testOptionsReservations46(const bool formatted);
 
+    /// @brief Test that multiple client classes for IPv4 can be inserted and
+    /// retrieved for a given host reservation.
+    ///
+    /// Uses gtest macros to report failures.
+    ///
+    void testMultipleClientClasses4();
+
+    /// @brief Test that multiple client classes for IPv6 can be inserted and
+    /// retrieved for a given host reservation.
+    ///
+    /// Uses gtest macros to report failures.
+    ///
+    void testMultipleClientClasses6();
+
+    /// @brief Test that multiple client classes for both IPv4 and IPv6 can
+    /// be inserted and retrieved for a given host reservation.
+    ///
+    /// Uses gtest macros to report failures.
+    ///
+    void testMultipleClientClassesBoth();
+
     /// @brief Returns DUID with identical content as specified HW address
     ///
     /// This method does not have any sense in real life and is only useful

+ 12 - 19
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc

@@ -351,29 +351,22 @@ TEST_F(MySqlHostDataSourceTest, multipleReservationsDifferentOrder){
     testMultipleReservationsDifferentOrder();
 }
 
-// Test verifies if multiple client classes for IPv4 can be stored.
-TEST_F(MySqlHostDataSourceTest, DISABLED_multipleClientClasses4) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v4 client-classes, retrieve it and
-    /// make sure that all client classes are retrieved properly.
+// Test that multiple client classes for IPv4 can be inserted and
+// retrieved for a given host reservation.
+TEST_F(MySqlHostDataSourceTest, multipleClientClasses4) {
+    testMultipleClientClasses4();
 }
 
-// Test verifies if multiple client classes for IPv6 can be stored.
-TEST_F(MySqlHostDataSourceTest, DISABLED_multipleClientClasses6) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v6 client-classes, retrieve it and
-    /// make sure that all client classes are retrieved properly.
+// Test that multiple client classes for IPv6 can be inserted and
+// retrieved for a given host reservation.
+TEST_F(MySqlHostDataSourceTest, multipleClientClasses6) {
+    testMultipleClientClasses6();
 }
 
-// Test verifies if multiple client classes for both IPv4 and IPv6 can be stored.
-TEST_F(MySqlHostDataSourceTest, DISABLED_multipleClientClassesBoth) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v4 and v6 client-classes, retrieve
-    /// it and make sure that all client classes are retrieved properly. Also,
-    /// check that the classes are not confused.
+// Test that multiple client classes for both IPv4 and IPv6 can
+// be inserted and retrieved for a given host reservation.
+TEST_F(MySqlHostDataSourceTest, multipleClientClassesBoth) {
+    testMultipleClientClassesBoth();
 }
 
 // Test if the same host can have reservations in different subnets (with the

+ 12 - 19
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc

@@ -311,29 +311,22 @@ TEST_F(PgSqlHostDataSourceTest, multipleReservationsDifferentOrder){
     testMultipleReservationsDifferentOrder();
 }
 
-// Test verifies if multiple client classes for IPv4 can be stored.
-TEST_F(PgSqlHostDataSourceTest, DISABLED_multipleClientClasses4) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v4 client-classes, retrieve it and
-    /// make sure that all client classes are retrieved properly.
+// Test that multiple client classes for IPv4 can be inserted and
+// retrieved for a given host reservation.
+TEST_F(PgSqlHostDataSourceTest, multipleClientClasses4) {
+    testMultipleClientClasses4();
 }
 
-// Test verifies if multiple client classes for IPv6 can be stored.
-TEST_F(PgSqlHostDataSourceTest, DISABLED_multipleClientClasses6) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v6 client-classes, retrieve it and
-    /// make sure that all client classes are retrieved properly.
+// Test that multiple client classes for IPv6 can be inserted and
+// retrieved for a given host reservation.
+TEST_F(PgSqlHostDataSourceTest, multipleClientClasses6) {
+    testMultipleClientClasses6();
 }
 
-// Test verifies if multiple client classes for both IPv4 and IPv6 can be stored.
-TEST_F(PgSqlHostDataSourceTest, DISABLED_multipleClientClassesBoth) {
-    /// @todo: Implement this test as part of #4213.
-
-    /// Add host reservation with a multiple v4 and v6 client-classes, retrieve
-    /// it and make sure that all client classes are retrieved properly. Also,
-    /// check that the classes are not confused.
+// Test that multiple client classes for both IPv4 and IPv6 can
+// be inserted and retrieved for a given host reservation.
+TEST_F(PgSqlHostDataSourceTest, multipleClientClassesBoth) {
+    testMultipleClientClassesBoth();
 }
 
 // Test if the same host can have reservations in different subnets (with the