]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
fixed unit tests
authorRazvan Becheriu <razvan.becheriu@qualitance.com>
Wed, 21 Feb 2018 17:40:37 +0000 (19:40 +0200)
committerRazvan Becheriu <razvan.becheriu@qualitance.com>
Wed, 21 Feb 2018 17:40:37 +0000 (19:40 +0200)
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc

index 2fecda4c4bfec0938587368d74bca17d3a599cd7..cd786f08e80ad094ac1d535885ef3a9748ef0b76 100644 (file)
@@ -267,6 +267,11 @@ public:
     static constexpr StatementTag INSERT_HOST =
         "INSERT_HOST";
 
+    // Retrieves hosts informations, IPv6 reservations and both IPv4 and IPv6
+    // options associated with the hosts.
+    static constexpr StatementTag GET_HOST =
+        "GET_HOST";
+
     // Retrieves host information, IPv6 reservations and both IPv4 and IPv6
     // options associated with the host.
     static constexpr StatementTag GET_HOST_BY_HOST_ID =
@@ -410,6 +415,7 @@ private:
 };  // CqlHostExchange
 
 constexpr StatementTag CqlHostExchange::INSERT_HOST;
+constexpr StatementTag CqlHostExchange::GET_HOST;
 constexpr StatementTag CqlHostExchange::GET_HOST_BY_HOST_ID;
 constexpr StatementTag CqlHostExchange::GET_HOST_BY_IPV4_ADDRESS;
 constexpr StatementTag CqlHostExchange::GET_HOST_BY_IPV4_SUBNET_ID_AND_HOST_ID;
@@ -461,6 +467,39 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "IF NOT EXISTS "
      }},
 
+    {GET_HOST,
+     {GET_HOST,
+      "SELECT "
+      "id, "
+      "host_identifier, "
+      "host_identifier_type, "
+      "host_ipv4_subnet_id, "
+      "host_ipv6_subnet_id, "
+      "host_ipv4_address, "
+      "host_ipv4_next_server, "
+      "host_ipv4_server_hostname, "
+      "host_ipv4_boot_file_name, "
+      "hostname, "
+      "user_context, "
+      "host_ipv4_client_classes, "
+      "host_ipv6_client_classes, "
+      "reserved_ipv6_prefix_address, "
+      "reserved_ipv6_prefix_length, "
+      "reserved_ipv6_prefix_address_type, "
+      "iaid, "
+      "option_universe, "
+      "option_code, "
+      "option_value, "
+      "option_formatted_value, "
+      "option_space, "
+      "option_is_persistent, "
+      "option_client_class, "
+      "option_subnet_id, "
+      "option_user_context, "
+      "option_scope_id "
+      "FROM host_reservations "
+     }},
+
     {GET_HOST_BY_HOST_ID,
      {GET_HOST_BY_HOST_ID,
       "SELECT "
@@ -1436,6 +1475,12 @@ public:
     virtual ConstHostCollection
     getAll4(const asiolink::IOAddress& address) const;
 
+    /// @brief Implementation of @ref CqlHostDataSource::getAllHosts()
+    ///
+    /// See @ref CqlHostDataSource::getAllHosts() for parameter details.
+    virtual ConstHostCollection
+    getAllHosts() const;
+
     /// @brief Implementation of @ref CqlHostDataSource::getName()
     virtual std::string getName() const;
 
@@ -1905,6 +1950,18 @@ CqlHostDataSourceImpl::getAll4(const asiolink::IOAddress& address) const {
     return (result);
 }
 
+ConstHostCollection
+CqlHostDataSourceImpl::getAllHosts() const {
+
+    // Bind to array.
+    AnyArray where_values;
+
+    // Run statement.
+    ConstHostCollection result = getHostCollection(CqlHostExchange::GET_HOST, where_values);
+
+    return (result);
+}
+
 std::string
 CqlHostDataSourceImpl::getName() const {
     std::string name;
@@ -2227,6 +2284,11 @@ CqlHostDataSource::get6(const SubnetID& subnet_id,
     return (impl_->get6(subnet_id, address));
 }
 
+ConstHostCollection
+CqlHostDataSource::getAllHosts() const {
+    return (impl_->getAllHosts());
+}
+
 std::string
 CqlHostDataSource::getType() const {
     return std::string("cql");
index f9dd970b15be370b43420a597b2ffbb3c1f25a99..da17a4af2cd0ff7a06158d8425e52061aa5aa3bb 100644 (file)
@@ -312,6 +312,14 @@ public:
     get6(const SubnetID& subnet_id,
          const asiolink::IOAddress& address) const override;
 
+    /// @brief Returns a collection of all the hosts.
+    ///
+    /// This method may return multiple @ref Host objects.
+    ///
+    /// @return Collection of const @ref Host objects.
+    virtual ConstHostCollection
+    getAllHosts() const;
+
     /// @brief Returns textual description of the backend.
     ///
     /// @return Description of the backend.
index 314187cfb91c731a197f94c1baf2cdc19690b751..16ebc84b03327f6161330f003de8d6d55a647160 100644 (file)
@@ -108,6 +108,69 @@ public:
         HostDataSourceFactory::create(validCqlConnectionString());
         hdsptr_ = HostDataSourceFactory::getHostDataSourcePtr();
     }
+
+    /// @brief Returns number of IPv4 options currently stored in DB.
+    virtual int countDBOptions4() {
+        int result = 0;
+
+        const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+        ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+        for (ConstHostCollection::const_iterator it = all.begin();
+             it != all.end(); ++it) {
+            ConstCfgOptionPtr cfg_option4 = (*it)->getCfgOption4();
+            std::list<std::string> option_spaces4 = cfg_option4->getOptionSpaceNames();
+            std::list<std::string> vendor_spaces4 = cfg_option4->getVendorIdsSpaceNames();
+            option_spaces4.insert(option_spaces4.end(), vendor_spaces4.begin(),
+                                  vendor_spaces4.end());
+            for (const std::string& space : option_spaces4) {
+                OptionContainerPtr options = cfg_option4->getAll(space);
+                result += options->size();
+            }
+        }
+
+        return (result);
+    }
+
+    /// @brief Returns number of IPv6 options currently stored in DB.
+    virtual int countDBOptions6() {
+        int result = 0;
+
+        const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+        ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+        for (ConstHostCollection::const_iterator it = all.begin();
+             it != all.end(); ++it) {
+            ConstCfgOptionPtr cfg_option6 = (*it)->getCfgOption6();
+            std::list<std::string> option_spaces6 = cfg_option6->getOptionSpaceNames();
+            std::list<std::string> vendor_spaces6 = cfg_option6->getVendorIdsSpaceNames();
+            option_spaces6.insert(option_spaces6.end(), vendor_spaces6.begin(),
+                                  vendor_spaces6.end());
+            for (const std::string& space : option_spaces6) {
+                OptionContainerPtr options = cfg_option6->getAll(space);
+                result += options->size();
+            }
+        }
+
+        return (result);
+    }
+
+    /// @brief Returns number of IPv6 reservations currently stored in DB.
+    virtual int countDBReservations6() {
+        int result = 0;
+
+        const CqlHostDataSource* cql_host_mgr = dynamic_cast<const CqlHostDataSource*>(&(*hdsptr_));
+        ConstHostCollection all = cql_host_mgr->getAllHosts();
+
+        for (ConstHostCollection::const_iterator it = all.begin();
+             it != all.end(); ++it) {
+            IPv6ResrvRange reservations = (*it)->getIPv6Reservations();
+                result += std::distance(reservations.first, reservations.second);
+        }
+
+        return (result);
+    }
+
 };
 
 /// @brief Check that database can be opened
index 3ffd453036808a5ad309bf0530730d168bf979c0..4722a9e3f8877f43de60b617715b2a875523fa78 100644 (file)
@@ -131,7 +131,7 @@ public:
         return (countRowsInTable("dhcp4_options"));
     }
 
-    /// @brief Returns number of IPv4 options currently stored in DB.
+    /// @brief Returns number of IPv6 options currently stored in DB.
     virtual int countDBOptions6() {
         return (countRowsInTable("dhcp6_options"));
     }
index 1d0aac8eeaa3877dd5183c6829cee86c4605c79c..b896cca5e1fe683e3672b5bb95aa855a08cb46b3 100644 (file)
@@ -129,7 +129,7 @@ public:
         return (countRowsInTable("dhcp4_options"));
     }
 
-    /// @brief Returns number of IPv4 options currently stored in DB.
+    /// @brief Returns number of IPv6 options currently stored in DB.
     virtual int countDBOptions6() {
         return (countRowsInTable("dhcp6_options"));
     }