]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Cassandra update
authorAndrei Pavel <andrei.pavel@qualitance.com>
Wed, 14 Dec 2016 13:54:32 +0000 (15:54 +0200)
committerAndrei Pavel <andrei.pavel@qualitance.com>
Wed, 11 Jan 2017 12:14:43 +0000 (14:14 +0200)
Replaced unrecommended backticks with $() in cql_version() in bash scripts.

*_execute() and *_execute_script() functions from src/bin/admin/admin-utils.sh now pass the parameters to the underlying backend binary whenever they are given rather than when there are 2 or more.

Corrected cql_version() return error in src/bin/admin/admin-utils.sh.

Removed redundant "USE" from cql_init() in src/bin/admin/kea-admin.in.

Inserted a newline in src/bin/admin/tests/Makefile.am to separate unrelated targets.

Style changes in cql_*_test() functions in src/bin/admin/tests/cql_tests.sh.in.

src/bin/admin/tests/dhcpdb_create_1.0.cql:
    "perfromance" typo
    Added comment headers
    Added index on expire since it is used in WHERE clauses (further performance testing may be required)
    Removed dhcp4_options and dhcp6_options table since they are not required for Cassandra

Added DROP INDEX in src/share/database/scripts/cql/dhcpdb_drop.cql.

Added sql_common.h
Added cql_exchange.h and cql_exchange.cc which mediate communication with Cassandra.
Added cql_lease_mgr.h and cql_lease_mgr.cc

Parameterized reconnect-wait-time, connect-timeout, request-timeout, tcp-keepalive, tcp-nodelay for Cassandra in kea.conf. Changes are in src/lib/dhcpsrv/cql_connection.cc and src/lib/dhcpsrv/parsers/dbaccess_parser.cc.

Reformated x != NULL into !x as specified in the Kea style guidelines

src/lib/dhcpsrv/cql_connection.cc:
    Added range check for port
    Added CqlConnection:setConsistency
    Added CqlConnection::startTransaction  which is a noop
    Added CqlTransaction method implementations.
    Corrected ending brace of namespace declaration, it doesn't need semicolon.

src/lib/dhcpsrv/cql_connection.h:
    Added explicit on CqlConnection constructor. Unlikely that this class will ever be derived, but it's good practice.
    Changed some comments.
    Added CqlTransaction class definition.

src/lib/dhcpsrv/cql_lease_mgr.cc:
    Formatted the entire code.
    Changed data types to cass_ types.

Added some log messages.

Moved structs, enums and typedefs from src/lib/dhcpsrv/lease_mgr.h to src/lib/dhcpsrv/sql_common.h

Added some missing tests in src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc

20 files changed:
configure.ac
doc/guide/admin.xml
doc/guide/dhcp4-srv.xml
doc/guide/dhcp6-srv.xml
src/bin/admin/tests/dhcpdb_create_1.0.cql
src/lib/dhcpsrv/cql_connection.h
src/lib/dhcpsrv/cql_exchange.h
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/parsers/dbaccess_parser.cc
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/cql_schema.cc
src/lib/dhcpsrv/testutils/cql_schema.h
src/share/database/scripts/cql/Makefile.am
src/share/database/scripts/cql/dhcpdb_create.cql
src/share/database/scripts/cql/dhcpdb_drop.cql
src/share/database/scripts/cql/soft_wipe.cql
src/share/database/scripts/cql/upgrade_1.0_to_2.0.sh.in
src/share/database/scripts/mysql/Makefile.am

index 47d6c16359ea985e2d173d74260a2424cb86d3d3..0dbbe0e05aa19ee7a378b16c4f2963373b1442b4 100644 (file)
@@ -1666,6 +1666,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
                  src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
                  src/share/database/scripts/pgsql/upgrade_2.0_to_3.0.sh
                  src/share/database/scripts/cql/Makefile
+                 src/share/database/scripts/cql/upgrade_1.0_to_2.0.sh
                  tools/Makefile
                  tools/path_replacer.sh
 ])
index f2b7c88e9b86b7f130e22ae36efc3cd747a202e8..f9ee56e2e7dcd7ea9ae441efbafe09f897148420 100644 (file)
               <entry>Memfile</entry>
               <entry>MySQL</entry>
               <entry>PostgreSQL</entry>
-              <entry>CQL(Cassandra)</entry>
+              <entry>CQL (Cassandra)</entry>
             </row>
           </thead>
           <tbody>
               <entry>no</entry>
               <entry>yes</entry>
               <entry>yes</entry>
-              <entry>no</entry>
+              <entry>yes</entry>
             </row>
 
           </tbody>
@@ -409,6 +409,8 @@ $ <userinput>kea-admin lease-upgrade mysql -u <replaceable>database-user</replac
       <title>PostgreSQL</title>
 
       <para>
+        PostgreSQL is able to store leases, host reservations and options
+        defined on a per host basis.
         A PostgreSQL database must be set up if you want Kea to store
         lease and other information in PostgreSQL. This step can be
         safely ignored if you are using other database backends.
@@ -590,7 +592,7 @@ $ <userinput>kea-admin lease-upgrade pgsql -u <replaceable>database-user</replac
       <para>
         Cassandra, or Cassandra Query Language (CQL), is the newest backend
         added to Kea. Since it was added recently and has not undergone as much
-        testing as other backends, it is considered experimental: please use
+        testing as other backends, it is considered experimental. Please use
         with caution. The Casandra backend is currently able to store leases,
         host reservations and options defined on a per host basis.
       </para>
index b59f58c2d47a268f9f32c8202d07df47ee5b2817..c7da52d69f8c5fda9f09101a349efa921c56d091 100644 (file)
@@ -477,8 +477,7 @@ If a timeout is given though, it should be an integer greater than zero.
     purpose, be it lease or hosts information. This arrangement gives the most
     flexibility. Kea can be used to keep leases and host reservations
     separately, but can also point to the same database. Currently the
-    supported hosts database types are MySQL and PostgreSQL. The Cassandra
-    backend does not support host reservations yet.</para>
+    supported hosts database types are MySQL, PostgreSQL and CQL (Cassandra).</para>
 
     <para>Please note that usage of hosts storage is optional. A user can define
     all host reservations in the configuration file. That is the recommended way
@@ -2977,9 +2976,9 @@ It is merely echoed by the server
       <title>Storing Host Reservations in MySQL, PostgreSQL or CQL (Cassandra)</title>
 
       <para>
-        It is possible to store host reservations in MySQL or PostgreSQL database. See
+        It is possible to store host reservations in MySQL, PostgreSQL or Cassandra. See
         <xref linkend="hosts4-storage"/> for information on how to configure Kea to use
-        reservations stored in MySQL or PostgreSQL. Kea does not provide any dedicated
+        reservations stored in MySQL, PostgreSQL or Cassandra. Kea does not provide any dedicated
         tools for managing reservations in a database. The Kea wiki <ulink
         url="http://kea.isc.org/wiki/HostReservationsHowTo" /> provides detailed
         information and examples of how reservations can be inserted into the
index 9c7ca469ce5a273b1123bfae8fe13fc339e08c2a..2a2490da956f8b35f5390a864ef221a9753d3c53 100644 (file)
@@ -1156,7 +1156,7 @@ temporarily override a list of interface names and listen on all interfaces.
 <row><entry>s46-br</entry><entry>90</entry><entry>ipv6-address</entry><entry>false</entry></row>
 <row><entry>s46-dmr</entry><entry>91</entry><entry>ipv6-prefix</entry><entry>false</entry></row>
 <row><entry>s46-v4v6bind</entry><entry>92</entry><entry>record (ipv4-address, ipv6-prefix)</entry><entry>false</entry></row>
-<row><entry>s46-portparams</entry><entry>93</entry><entry>record(uint8, psid)</entry><entry>false</entry></row>
+<row><entry>s46-portparams</entry><entry>93</entry><entry>record (uint8, psid)</entry><entry>false</entry></row>
 <row><entry>s46-cont-mape</entry><entry>94</entry><entry>empty</entry><entry>false</entry></row>
 <row><entry>s46-cont-mapt</entry><entry>95</entry><entry>empty</entry><entry>false</entry></row>
 <row><entry>s46-cont-lw</entry><entry>96</entry><entry>empty</entry><entry>false</entry></row>
@@ -2908,13 +2908,13 @@ should include options from the isc option space:
     with classification using expressions.</para>
     </section>
 
-    <section id="reservations6-mysql-pgsql">
-      <title>Storing Host Reservations in MySQL or PostgreSQL</title>
+    <section id="reservations6-mysql-pgsql-cql">
+      <title>Storing Host Reservations in MySQL, PostgreSQL or CQL (Cassandra)</title>
 
       <para>
-        It is possible to store host reservations in MySQL or PostgreSQL. See <xref
-        linkend="hosts6-storage" /> for information on how to configure Kea to use
-        reservations stored in MySQL or PostgreSQL. Kea does not provide any dedicated
+        It is possible to store host reservations in MySQL, PostgreSQL or Cassandra. See
+        <xref linkend="hosts6-storage" /> for information on how to configure Kea to use
+        reservations stored in MySQL, PostgreSQL or Cassandra. Kea does not provide any dedicated
         tools for managing reservations in a database. The Kea wiki <ulink
         url="http://kea.isc.org/wiki/HostReservationsHowTo" /> provides detailed
         information and examples of how reservations can be inserted into the
@@ -2925,12 +2925,6 @@ should include options from the isc option space:
       arbitrarily set to 4096 bytes.</simpara></note>
     </section>
 
-    <section id="reservations6-cql">
-      <title>Storing Host Reservations in CQL (Cassandra)</title>
-      <para>Kea currently does not support storing reservations in
-      Cassandra (CQL).</para>
-    </section>
-
     <section id="reservations6-tuning">
       <title>Fine Tuning DHCPv6 Host Reservation</title>
 
index 2d6c45a93a573dd612c06c227a5a1aaf79cccfc4..85f9089effcf846f794ee0f63530da90e3fdbad8 100644 (file)
@@ -175,9 +175,8 @@ INSERT INTO lease_state (state, name) VALUES (2, 'expired-reclaimed');
 -- This table is only modified during schema upgrades.  For historical reasons
 -- (related to the names of the columns in the BIND 10 DNS database file), the
 -- first column is called "version" and not "major".
--- Note: This MUST be kept synchronized with
--- src/share/database/scripts/cql/dhcpdb_create.cql which defines the schema for
--- the unit tests.
+-- Note: This MUST be kept in step with src/share/database/scripts/cassandra/dhcpdb_create.cql,
+-- which defines the schema for the unit tests.
 -- -----------------------------------------------------
 -- Table `schema_version`
 -- -----------------------------------------------------
index 9adcbc9c9083d575209589af77bfce4dcdce7bdf..aa6e5a411d730b5ebaa54f11e0ad26f8e6da1015 100644 (file)
@@ -48,7 +48,7 @@ struct CqlTaggedStatement {
 const uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR;
 const uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR;
 
-/// Define CQL schema version: 1.0
+/// Define CQL schema version: 2.0
 const uint32_t CQL_SCHEMA_VERSION_MAJOR = 2;
 const uint32_t CQL_SCHEMA_VERSION_MINOR = 0;
 
index 191dc5fcac4cc7d85eb555c4a9ce8272bb135d90..2d2e5e4b1cc0dec0964841ad89b6ab0e93ac7a20 100644 (file)
@@ -39,7 +39,7 @@ typedef CassError (*CqlBindFunction)(CassStatement* statement,
 ///     SELECT statements.
 typedef CassError (*CqlGetFunction)(const CassValue* value, void* data);
 
-/// @brief Pair containing major and minor versions.
+/// @brief Pair containing major and minor versions
 typedef std::pair<uint32_t, uint32_t> VersionPair;
 
 /// @brief Wrapper over the bind and get functions that interface with Cassandra
index e6b86c5abf349156bc35c5077eae387b4962a490..0b9352a53c9fe3ededdf0ff16ba458a2adfedaab 100644 (file)
@@ -54,7 +54,7 @@ typedef std::vector<cass_byte_t> CassHostIdentifier;
 /// @brief Host identifier converted to Cassandra data type
 typedef std::vector<cass_byte_t> CassOptionBuffer;
 
-/// @brief key for @ref HostMap containing objects which uniquely identify a
+/// @brief key for HostMap containing objects which uniquely identify a
 ///     host: host identifier, host identifier type, subnets for IPv4 and IPv6
 typedef boost::tuple<HostIdentifier,
                      Host::IdentifierType,
@@ -1017,28 +1017,22 @@ CqlHostExchange::retrieve() {
                           host_identifier_type, ipv4_subnet_id, ipv6_subnet_id,
                           ipv4_reservation, hostname_,
                           host_ipv4_client_classes_, host_ipv6_client_classes_);
-    try{
-        host->setHostId(id);
+    host->setHostId(id);
 
-        const IPv6Resrv reservation = retrieveReservation();
-        if (reservation != NULL_IPV6_RESERVATION &&
-            !host->hasReservation(reservation)) {
-            host->addReservation(reservation);
-        }
+    const IPv6Resrv reservation = retrieveReservation();
+    if (reservation != NULL_IPV6_RESERVATION &&
+        !host->hasReservation(reservation)) {
+        host->addReservation(reservation);
+    }
 
-        OptionDescriptorPtr option_descriptor_ptr = retrieveOption();
-        if (option_descriptor_ptr) {
-            if (option_descriptor_ptr->option_->getUniverse() == Option::V4) {
-                host->getCfgOption4()->add(*option_descriptor_ptr, option_space_);
-            } else if (option_descriptor_ptr->option_->getUniverse() ==
-                       Option::V6) {
-                host->getCfgOption6()->add(*option_descriptor_ptr, option_space_);
-            }
+    OptionDescriptorPtr option_descriptor_ptr = retrieveOption();
+    if (option_descriptor_ptr) {
+        if (option_descriptor_ptr->option_->getUniverse() == Option::V4) {
+            host->getCfgOption4()->add(*option_descriptor_ptr, option_space_);
+        } else if (option_descriptor_ptr->option_->getUniverse() ==
+                   Option::V6) {
+            host->getCfgOption6()->add(*option_descriptor_ptr, option_space_);
         }
-    } catch (const std::exception& exception) {
-        LOG_ERROR(dhcpsrv_logger, DHCPSRV_CQL_HOST_RETRIEVE_ERROR)
-            .arg(exception.what());
-        throw;
     }
 
     return reinterpret_cast<void*>(host);
@@ -1291,7 +1285,7 @@ protected:
     /// @param option_space option space for the current denormalized table
     ///     entry's option
     /// @param option_descriptor option descriptor containing information for
-    /// the current denormalized table entry's option
+    ///     the current denormalized table entry's option
     virtual void insertHost(
         const HostPtr& host,
         const OptionalValue<SubnetID>& subnet_id = OptionalValue<SubnetID>(),
@@ -1320,7 +1314,7 @@ private:
 };  // class CqlHostDataSourceImpl
 
 
-/// @brief hash function for @ref HostMap
+/// @brief hash function for HostMap
 ///
 /// @param key being hashed
 ///
@@ -1344,7 +1338,7 @@ hash_value(const HostKey& key) {
     return static_cast<std::size_t>(md5);
 }
 
-/// @brief equals operator for @ref HostKey
+/// @brief equals operator for HostKey
 ///
 /// @param key1 left hand side operand
 /// @param key2 right hand side operand
@@ -1374,6 +1368,9 @@ CqlHostDataSourceImpl::~CqlHostDataSourceImpl() {
 
 void
 CqlHostDataSourceImpl::add(const HostPtr& host) {
+    // Start transaction.
+    CqlTransaction transaction(dbconn_);
+
     // Get option space names and vendor space names and combine them within a
     // single list.
     // For IPv4:
@@ -1407,6 +1404,7 @@ CqlHostDataSourceImpl::add(const HostPtr& host) {
         insertHostWithReservations(host, NULL, option_spaces4, cfg_option4,
                                    option_spaces6, cfg_option6);
     }
+    transaction.commit();
 }
 
 ConstHostPtr
index 8fcf5c8d96ae82400dbb784a5053b8f9b0b19770..bd5c4b9743c72ccf186545091af420c6ca30cbf6 100644 (file)
@@ -590,11 +590,11 @@ private:
     /// declare them as "mutable".)
     /// @brief Exchange object for IPv4
     boost::scoped_ptr<CqlLease4Exchange> exchange4_;
-    /// @brief Exchange object for IPv4
+    /// @brief Exchange object for IPv6
     boost::scoped_ptr<CqlLease6Exchange> exchange6_;
     /// @brief Exchange object for version
     boost::scoped_ptr<CqlVersionExchange> versionExchange_;
-    //// @}
+    /// @}
 };
 
 }  // namespace dhcp
index ca5f9c7eb23736c79851b422ea4643a33b27bff4..32d3d43d6ce86ef17f12813371ea3a07298d3f71 100644 (file)
@@ -172,6 +172,9 @@ with the specified address to the Cassandra backend database.
 A debug message issued when the server is about to add an IPv6 lease
 with the specified address to the Cassandra backend database.
 
+% DHCPSRV_CQL_BEGIN_TRANSACTION committing to Cassandra database.
+The server has issued a begin transaction call.
+
 % DHCPSRV_CQL_COMMIT committing to Cassandra database
 A commit call been issued on the server. For Cassandra, this is a no-op.
 
@@ -261,10 +264,6 @@ subnet ID and hardware address.
 A debug message issued when the server is about to obtain schema version
 information from the Cassandra database.
 
-% DHCPSRV_CQL_HOST_RETRIEVE_ERROR Unable to retrieve host reservation or option: %1
-A host couldn't be fully retrieved. An exception was thrown, but the server
-should continue running.
-
 % DHCPSRV_CQL_ROLLBACK rolling back Cassandra database
 The code has issued a rollback call. For Cassandra, this is
 a no-op.
index 329d0c50e5f0fe8f8387b3521e3466d8d8d364fb..2056b94b830c1b686365b7ff5ccefb31f16d9d66 100644 (file)
@@ -82,6 +82,7 @@ DbAccessParser::build(isc::data::ConstElementPtr config_value) {
                 timeout = param.second->intValue();
                 values_copy[param.first] =
                     boost::lexical_cast<std::string>(timeout);
+
             } else {
                 values_copy[param.first] = param.second->stringValue();
             }
index fa2edfa3a88e4741df35face089ecca546d343c1..a556b9959bb8aa8018a86cef2d9c445d1709816a 100644 (file)
 #include <config.h>
 
 #include <asiolink/io_address.h>
-#include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/cql_connection.h>
 #include <dhcpsrv/cql_lease_mgr.h>
-#include <dhcpsrv/tests/test_utils.h>
+#include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
+#include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/testutils/cql_schema.h>
 #include <exceptions/exceptions.h>
 
@@ -53,7 +53,6 @@ public:
     ///
     /// Deletes everything from the database and opens it.
     CqlLeaseMgrTest() {
-
         // Ensure schema is the correct one.
         destroyCqlSchema(false, true);
         createCqlSchema(false, true);
@@ -95,13 +94,13 @@ public:
         lmptr_ = &(LeaseMgrFactory::instance());
     }
 
-    // This is the CQL implementation for GenericLeaseMgrTest::testGetExpiredLeases4().
+    // This is the CQL implementation for
+    // GenericLeaseMgrTest::testGetExpiredLeases4().
     // The GenericLeaseMgrTest implementation checks for the order of expired
     // leases to be from the most expired to the least expired. Cassandra
     // doesn't support ORDER BY without imposing a EQ / IN restriction on the
     // columns. Because of that, the order check has been excluded.
-    void
-    testCqlGetExpiredLeases4() {
+    void testCqlGetExpiredLeases4() {
         // Get the leases to be used for the test.
         vector<Lease4Ptr> leases = createLeases4();
         // Make sure we have at least 6 leases there.
@@ -118,10 +117,12 @@ public:
                 // valid lifetime to make it expired. The expiration time also
                 // depends on the lease index, so as we can later check that the
                 // leases are ordered by the expiration time.
-                leases[i]->cltt_ = current_time - leases[i]->valid_lft_ - 10 - i;
+                leases[i]->cltt_ =
+                    current_time - leases[i]->valid_lft_ - 10 - i;
 
             } else {
-                // Set current time as cltt for remaining leases. These leases are
+                // Set current time as cltt for remaining leases. These leases
+                // are
                 // not expired.
                 leases[i]->cltt_ = current_time;
             }
@@ -132,19 +133,22 @@ public:
         Lease4Collection expired_leases;
         ASSERT_NO_THROW(lmptr_->getExpiredLeases4(expired_leases, 1000));
         // Leases with even indexes should be returned as expired.
-        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U), expired_leases.size());
+        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U),
+                  expired_leases.size());
 
         // Update current time for the next test.
         current_time = time(NULL);
         // Also, remove expired leases collected during the previous test.
         expired_leases.clear();
 
-        // This time let's reverse the expiration time and see if they will be returned
+        // This time let's reverse the expiration time and see if they will be
+        // returned
         // in the correct order.
         for (size_t i = 0U; i < leases.size(); ++i) {
             // Update the time of expired leases with even indexes.
             if (i % 2U == 0U) {
-                leases[i]->cltt_ = current_time - leases[i]->valid_lft_ - 1000 + i;
+                leases[i]->cltt_ =
+                    current_time - leases[i]->valid_lft_ - 1000 + i;
             } else {
                 // Make sure remaining leases remain unexpired.
                 leases[i]->cltt_ = current_time + 100;
@@ -152,11 +156,13 @@ public:
             ASSERT_NO_THROW(lmptr_->updateLease4(leases[i]));
         }
 
-        // Retrieve expired leases again. The limit of 0 means return all expired
+        // Retrieve expired leases again. The limit of 0 means return all
+        // expired
         // leases.
         ASSERT_NO_THROW(lmptr_->getExpiredLeases4(expired_leases, 0));
         // The same leases should be returned.
-        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U), expired_leases.size());
+        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U),
+                  expired_leases.size());
 
         // Remember expired leases returned.
         std::vector<Lease4Ptr> saved_expired_leases = expired_leases;
@@ -173,7 +179,8 @@ public:
         // Mark every other expired lease as reclaimed.
         for (size_t i = 0U; i < saved_expired_leases.size(); ++i) {
             if (i % 2U != 0U) {
-                saved_expired_leases[i]->state_ = Lease::STATE_EXPIRED_RECLAIMED;
+                saved_expired_leases[i]->state_ =
+                    Lease::STATE_EXPIRED_RECLAIMED;
             }
             ASSERT_NO_THROW(lmptr_->updateLease4(saved_expired_leases[i]));
         }
@@ -190,18 +197,19 @@ public:
         // those that have even index.
         for (Lease4Collection::iterator lease = expired_leases.begin();
              lease != expired_leases.end(); ++lease) {
-            int index = static_cast<int>(std::distance(expired_leases.begin(), lease));
+            int index =
+                static_cast<int>(std::distance(expired_leases.begin(), lease));
             EXPECT_EQ(saved_expired_leases[2 * index]->addr_, (*lease)->addr_);
         }
     }
 
-    // This is the CQL implementation for GenericLeaseMgrTest::testGetExpiredLeases4().
+    // This is the CQL implementation for
+    // GenericLeaseMgrTest::testGetExpiredLeases4().
     // The GenericLeaseMgrTest implementation checks for the order of expired
     // leases to be from the most expired to the least expired. Cassandra
     // doesn't support ORDER BY without imposing a EQ / IN restriction on the
     // columns. Because of that, the order check has been excluded.
-    void
-    testCqlGetExpiredLeases6() {
+    void testCqlGetExpiredLeases6() {
         // Get the leases to be used for the test.
         vector<Lease6Ptr> leases = createLeases6();
         // Make sure we have at least 6 leases there.
@@ -218,10 +226,12 @@ public:
                 // valid lifetime to make it expired. The expiration time also
                 // depends on the lease index, so as we can later check that the
                 // leases are ordered by the expiration time.
-                leases[i]->cltt_ = current_time - leases[i]->valid_lft_ - 10 - i;
+                leases[i]->cltt_ =
+                    current_time - leases[i]->valid_lft_ - 10 - i;
 
             } else {
-                // Set current time as cltt for remaining leases. These leases are
+                // Set current time as cltt for remaining leases. These leases
+                // are
                 // not expired.
                 leases[i]->cltt_ = current_time;
             }
@@ -232,19 +242,22 @@ public:
         Lease6Collection expired_leases;
         ASSERT_NO_THROW(lmptr_->getExpiredLeases6(expired_leases, 1000));
         // Leases with even indexes should be returned as expired.
-        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U), expired_leases.size());
+        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U),
+                  expired_leases.size());
 
         // Update current time for the next test.
         current_time = time(NULL);
         // Also, remove expired leases collected during the previous test.
         expired_leases.clear();
 
-        // This time let's reverse the expiration time and see if they will be returned
+        // This time let's reverse the expiration time and see if they will be
+        // returned
         // in the correct order.
         for (size_t i = 0U; i < leases.size(); ++i) {
             // Update the time of expired leases with even indexes.
             if (i % 2U == 0U) {
-                leases[i]->cltt_ = current_time - leases[i]->valid_lft_ - 1000 + i;
+                leases[i]->cltt_ =
+                    current_time - leases[i]->valid_lft_ - 1000 + i;
 
             } else {
                 // Make sure remaining leases remain unexpired.
@@ -253,11 +266,13 @@ public:
             ASSERT_NO_THROW(lmptr_->updateLease6(leases[i]));
         }
 
-        // Retrieve expired leases again. The limit of 0 means return all expired
+        // Retrieve expired leases again. The limit of 0 means return all
+        // expired
         // leases.
         ASSERT_NO_THROW(lmptr_->getExpiredLeases6(expired_leases, 0));
         // The same leases should be returned.
-        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U), expired_leases.size());
+        ASSERT_EQ(static_cast<size_t>(leases.size() / 2U),
+                  expired_leases.size());
 
         // Remember expired leases returned.
         std::vector<Lease6Ptr> saved_expired_leases = expired_leases;
@@ -274,7 +289,8 @@ public:
         // Mark every other expired lease as reclaimed.
         for (size_t i = 0U; i < saved_expired_leases.size(); ++i) {
             if (i % 2U != 0U) {
-                saved_expired_leases[i]->state_ = Lease::STATE_EXPIRED_RECLAIMED;
+                saved_expired_leases[i]->state_ =
+                    Lease::STATE_EXPIRED_RECLAIMED;
             }
             ASSERT_NO_THROW(lmptr_->updateLease6(saved_expired_leases[i]));
         }
@@ -289,7 +305,8 @@ public:
         // those that have even index.
         for (Lease6Collection::iterator lease = expired_leases.begin();
              lease != expired_leases.end(); ++lease) {
-            int index = static_cast<int>(std::distance(expired_leases.begin(), lease));
+            int index =
+                static_cast<int>(std::distance(expired_leases.begin(), lease));
             EXPECT_EQ(saved_expired_leases[2 * index]->addr_, (*lease)->addr_);
         }
     }
@@ -304,7 +321,6 @@ public:
 /// Unlike other backend implementations, this one doesn't check for lacking
 /// parameters. In that scenario, Cassandra defaults to configured parameters.
 TEST(CqlOpenTest, OpenDatabase) {
-
     // Schema needs to be created for the test to work.
     destroyCqlSchema(false, true);
     createCqlSchema(false, true);
@@ -313,7 +329,7 @@ TEST(CqlOpenTest, OpenDatabase) {
     // If it fails, print the error message.
     try {
         LeaseMgrFactory::create(validCqlConnectionString());
-        EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
+        EXPECT_NO_THROW((void)LeaseMgrFactory::instance());
         LeaseMgrFactory::destroy();
     } catch (const isc::Exception& ex) {
         FAIL() << "*** ERROR: unable to open database, reason:\n"
@@ -325,10 +341,11 @@ TEST(CqlOpenTest, OpenDatabase) {
     // Check that lease manager open the database opens correctly with a longer
     // timeout. If it fails, print the error message.
     try {
-        string connection_string = validCqlConnectionString() + string(" ") +
-                                   string(VALID_TIMEOUT);
+        std::string connection_string = validCqlConnectionString() +
+                                        std::string(" ") +
+                                        std::string(VALID_TIMEOUT);
         LeaseMgrFactory::create(connection_string);
-        EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
+        EXPECT_NO_THROW((void)LeaseMgrFactory::instance());
         LeaseMgrFactory::destroy();
     } catch (const isc::Exception& ex) {
         FAIL() << "*** ERROR: unable to open database, reason:\n"
@@ -344,12 +361,13 @@ TEST(CqlOpenTest, OpenDatabase) {
     // Check that wrong specification of backend throws an exception.
     // (This is really a check on LeaseMgrFactory, but is convenient to
     // perform here.)
-    EXPECT_THROW(LeaseMgrFactory::create(connectionString(
-        NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
+    EXPECT_THROW(
+        LeaseMgrFactory::create(connectionString(NULL, VALID_NAME, VALID_HOST,
+                                                 INVALID_USER, VALID_PASSWORD)),
         InvalidParameter);
-
-    EXPECT_THROW(LeaseMgrFactory::create(connectionString(
-        INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
+    EXPECT_THROW(
+        LeaseMgrFactory::create(connectionString(
+            INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
         InvalidType);
 
     // Check that invalid login data does not cause an exception, CQL should use
@@ -514,7 +532,8 @@ TEST_F(CqlLeaseMgrTest, getLease4ClientIdSubnetId) {
 
 /// @brief Basic Lease4 Checks
 ///
-/// Checks that the addLease, getLease4(by address), getLease4(hwaddr, subnet_id),
+/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,
+/// subnet_id),
 /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
 /// (client-id is optional and may not be present)
 TEST_F(CqlLeaseMgrTest, lease4NullClientId) {
index b03c8a4814f2b3176565443c419a6e2818c4b229..8a4468e39eb08f822fc97476f7ae6716bb67c119 100644 (file)
@@ -5,15 +5,19 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <string>
+
 #include <cassandra.h>
+
 #include <dhcpsrv/cql_connection.h>
 #include <dhcpsrv/testutils/cql_schema.h>
+
+#include <stdlib.h>
+
 #include <gtest/gtest.h>
 
 #include <fstream>
 #include <sstream>
-#include <stdlib.h>
+#include <string>
 
 using namespace std;
 
@@ -25,11 +29,12 @@ const char* CQL_VALID_TYPE = "type=cql";
 
 string
 validCqlConnectionString() {
-    return (connectionString(CQL_VALID_TYPE, VALID_NAME, VALID_HOST,
-                             VALID_USER, VALID_PASSWORD));
+    return (connectionString(CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER,
+                             VALID_PASSWORD));
 }
 
-bool softWipeEnabled() {
+bool
+softWipeEnabled() {
     const char* const env = getenv("KEA_TEST_CASSANDRA_WIPE");
     if (env && (string(env) == string("soft"))) {
         return (true);
@@ -38,26 +43,28 @@ bool softWipeEnabled() {
     return (false);
 }
 
-void destroyCqlSchema(bool force_wipe, bool show_err) {
+void
+destroyCqlSchema(bool force_wipe, bool show_err) {
     if (force_wipe || !softWipeEnabled()) {
         // Do full wipe
         runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_drop.cql", show_err);
     } else {
-
         // do soft wipe (just remove the data, not the structures)
         runCqlScript(DATABASE_SCRIPTS_DIR, "cql/soft_wipe.cql", show_err);
     }
 }
 
-void createCqlSchema(bool force_wipe, bool show_err) {
+void
+createCqlSchema(bool force_wipe, bool show_err) {
     if (force_wipe || !softWipeEnabled()) {
-        runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_create.cql",
-                        show_err);
+        runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_create.cql", show_err);
     }
 }
 
-void runCqlScript(const std::string& path, const std::string& script_name,
-                    bool show_err) {
+void
+runCqlScript(const std::string& path,
+             const std::string& script_name,
+             bool show_err) {
     std::ostringstream cmd;
     cmd << "cqlsh -u keatest -p keatest -k keatest";
     if (!show_err) {
@@ -76,7 +83,6 @@ void runCqlScript(const std::string& path, const std::string& script_name,
     ASSERT_EQ(0, retval) << "runCqlSchema failed:" << cmd.str();
 }
 
-
-};
-};
-};
+}  // namespace test
+}  // namespace dhcp
+}  // namespace isc
index 9b92ea15282150f50b79a782b75452486ec54ded..91377f96dba82b7c0433899710cd2f09de0e6965 100644 (file)
@@ -54,7 +54,7 @@ void createCqlSchema(bool force_wipe, bool show_err = false);
 
 /// @brief Run a CQL script against the CQL unit test database
 ///
-/// Submits the given SQL script to CQL via cqlsh CLI. The output of
+/// Submits the given CQL script to CQL via cqlsh CLI. The output of
 /// stderr is suppressed unless the parameter, show_err is true. The is done
 /// to suppress warnings that might otherwise make test output needlessly
 /// noisy. A gtest assertion occurs if the script fails to execute.
index 8a32f195b14c12b087b71e098da1460d7c82d701..369b371b53b5f052490b14a1c20df696ec315d62 100644 (file)
@@ -3,6 +3,7 @@ SUBDIRS = .
 sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/cql
 sqlscripts_DATA = dhcpdb_create.cql
 sqlscripts_DATA += dhcpdb_drop.cql
+sqlscripts_DATA += upgrade_1.0_to_2.0.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
 
index 3d46022eac1178246655c18ecbdc84d8126f955d..1a1d35bed1c671e1f8b60899ac898c3fb0f0b0bb 100644 (file)
@@ -44,7 +44,7 @@
 -- -----------------------------------------------------
 -- Table `lease4`
 -- -----------------------------------------------------
-CREATE TABLE lease4 (
+CREATE TABLE IF NOT EXISTS lease4 (
     address int,
     hwaddr blob,
     client_id blob,
@@ -59,11 +59,11 @@ CREATE TABLE lease4 (
 );
 
 -- Create search indexes for lease4 table
-CREATE INDEX lease4index1 ON lease4 (client_id);
-CREATE INDEX lease4index2 ON lease4 (subnet_id);
-CREATE INDEX lease4index3 ON lease4 (hwaddr);
-CREATE INDEX lease4index4 ON lease4 (expire);
-CREATE INDEX lease4index5 ON lease4 (state);
+CREATE INDEX IF NOT EXISTS lease4index1 ON lease4 (client_id);
+CREATE INDEX IF NOT EXISTS lease4index2 ON lease4 (subnet_id);
+CREATE INDEX IF NOT EXISTS lease4index3 ON lease4 (hwaddr);
+CREATE INDEX IF NOT EXISTS lease4index4 ON lease4 (expire);
+CREATE INDEX IF NOT EXISTS lease4index5 ON lease4 (state);
 
 -- Holds the IPv6 leases.
 -- N.B. The use of a VARCHAR for the address is temporary for development:
@@ -71,7 +71,7 @@ CREATE INDEX lease4index5 ON lease4 (state);
 -- -----------------------------------------------------
 -- Table `lease6`
 -- -----------------------------------------------------
-CREATE TABLE lease6 (
+CREATE TABLE IF NOT EXISTS lease6 (
     address varchar,
     duid blob,
     valid_lifetime bigint,
@@ -92,12 +92,12 @@ CREATE TABLE lease6 (
 );
 
 -- Create search indexes for lease6 table
-CREATE INDEX lease6index1 ON lease6 (lease_type);
-CREATE INDEX lease6index2 ON lease6 (duid);
-CREATE INDEX lease6index3 ON lease6 (iaid);
-CREATE INDEX lease6index4 ON lease6 (subnet_id);
-CREATE INDEX lease6index5 ON lease6 (expire);
-CREATE INDEX lease6index6 ON lease6 (state);
+CREATE INDEX IF NOT EXISTS lease6index1 ON lease6 (lease_type);
+CREATE INDEX IF NOT EXISTS lease6index2 ON lease6 (duid);
+CREATE INDEX IF NOT EXISTS lease6index3 ON lease6 (iaid);
+CREATE INDEX IF NOT EXISTS lease6index4 ON lease6 (subnet_id);
+CREATE INDEX IF NOT EXISTS lease6index5 ON lease6 (expire);
+CREATE INDEX IF NOT EXISTS lease6index6 ON lease6 (state);
 
 -- ... and a definition of lease6 types.  This table is a convenience for
 -- users of the database - if they want to view the lease table and use the
@@ -107,7 +107,7 @@ CREATE INDEX lease6index6 ON lease6 (state);
 -- -----------------------------------------------------
 -- Table `lease6_types`
 -- -----------------------------------------------------
-CREATE TABLE lease6_types (
+CREATE TABLE IF NOT EXISTS lease6_types (
     lease_type int,                             -- Lease type code.
     name varchar,                               -- Name of the lease type
     PRIMARY KEY (lease_type)
@@ -125,7 +125,7 @@ INSERT INTO lease6_types (lease_type, name) VALUES (2, 'IA_PD');   -- Prefix del
 -- -----------------------------------------------------
 -- Table `lease_hwaddr_source`
 -- -----------------------------------------------------
-CREATE TABLE lease_hwaddr_source (
+CREATE TABLE IF NOT EXISTS lease_hwaddr_source (
     hwaddr_source int,
     name varchar,
     PRIMARY KEY (hwaddr_source)
@@ -158,7 +158,7 @@ INSERT INTO lease_hwaddr_source (hwaddr_source, name) VALUES (64, 'HWADDR_SOURCE
 -- -----------------------------------------------------
 -- Table `lease_state`
 -- -----------------------------------------------------
-CREATE TABLE lease_state (
+CREATE TABLE IF NOT EXISTS lease_state (
     state int,
     name varchar,
     PRIMARY KEY (state)
@@ -176,7 +176,7 @@ INSERT INTO lease_state (state, name) VALUES (2, 'expired-reclaimed');
 -- -----------------------------------------------------
 -- Table `schema_version`
 -- -----------------------------------------------------
-CREATE TABLE schema_version (
+CREATE TABLE IF NOT EXISTS schema_version (
     version int,
     minor int,
     PRIMARY KEY (version)
@@ -191,7 +191,7 @@ INSERT INTO schema_version (version, minor) VALUES (1, 0);
 -- -----------------------------------------------------
 -- Table `host_reservations`
 -- -----------------------------------------------------
-CREATE TABLE host_reservations (
+CREATE TABLE IF NOT EXISTS host_reservations (
     id bigint,
     host_identifier blob,
     host_identifier_type int,
@@ -215,13 +215,13 @@ CREATE TABLE host_reservations (
     option_subnet_id int,
     PRIMARY KEY (id)
 );
-CREATE INDEX host_reservationsindex1 ON host_reservations (host_identifier);
-CREATE INDEX host_reservationsindex2 ON host_reservations (host_identifier_type);
-CREATE INDEX host_reservationsindex3 ON host_reservations (host_ipv4_subnet_id);
-CREATE INDEX host_reservationsindex4 ON host_reservations (host_ipv6_subnet_id);
-CREATE INDEX host_reservationsindex5 ON host_reservations (host_ipv4_address);
-CREATE INDEX host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
-CREATE INDEX host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
+CREATE INDEX IF NOT EXISTS host_reservationsindex1 ON host_reservations (host_identifier);
+CREATE INDEX IF NOT EXISTS host_reservationsindex2 ON host_reservations (host_identifier_type);
+CREATE INDEX IF NOT EXISTS host_reservationsindex3 ON host_reservations (host_ipv4_subnet_id);
+CREATE INDEX IF NOT EXISTS host_reservationsindex4 ON host_reservations (host_ipv6_subnet_id);
+CREATE INDEX IF NOT EXISTS host_reservationsindex5 ON host_reservations (host_ipv4_address);
+CREATE INDEX IF NOT EXISTS host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
+CREATE INDEX IF NOT EXISTS host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
 
 DELETE FROM schema_version WHERE version=1;
 INSERT INTO schema_version (version, minor) VALUES(2, 0);
index 4f2fbee46a4f880d5da1acad8d4ad171000bd9cd..7a93e3df17db7ab0be87626c7ddb1e9acdc55ebb 100644 (file)
@@ -18,11 +18,8 @@ DROP TABLE IF EXISTS lease4;
 DROP TABLE IF EXISTS lease6;
 DROP TABLE IF EXISTS lease6_types;
 DROP TABLE IF EXISTS lease_hwaddr_source;
-DROP TABLE IF EXISTS schema_version;
-DROP TABLE IF EXISTS ipv6_reservations;
-DROP TABLE IF EXISTS hosts;
-DROP TABLE IF EXISTS host_identifier_type;
 DROP TABLE IF EXISTS lease_state;
+DROP TABLE IF EXISTS schema_version;
 DROP TABLE IF EXISTS host_reservations;
 
 DROP INDEX IF EXISTS lease4index1;
index e3dd6c402e48f5199edaf0230eeae2ca05365f49..5c9580843c2f70533554e64bdb85e4388ca6c062 100644 (file)
@@ -19,6 +19,8 @@
 
 TRUNCATE TABLE lease4;
 TRUNCATE TABLE lease6;
-TRUNCATE TABLE hosts;
-TRUNCATE TABLE dhcp4_options;
-TRUNCATE TABLE dhcp6_options;
+TRUNCATE TABLE lease6_types;
+TRUNCATE TABLE lease_hwaddr_source;
+TRUNCATE TABLE lease_state;
+TRUNCATE TABLE schema_version;
+TRUNCATE TABLE host_reservations;
index b08d4f1266486e02c6349953f78020ee691e2076..ac30776527e9683427f7ec72229856176dd8fa4a 100644 (file)
@@ -9,10 +9,10 @@ else
     . @abs_top_builddir@/src/bin/admin/admin-utils.sh
 fi
 
-VERSION=`cql_version "$@"`
+version=$(cql_version "$@")
 
-if [ "$VERSION" != "1.0" ]; then
-    printf "This script upgrades 1.0 to 2.0. Reported version is $VERSION. Skipping upgrade.\n"
+if [ "${version}" != "1.0" ]; then
+    printf "This script upgrades 1.0 to 2.0. Reported version is %s. Skipping upgrade.\n" "${version}"
     exit 0
 fi
 
@@ -20,7 +20,7 @@ cqlsh "$@" <<EOF
 -- This line starts database upgrade to version 2.0
 
 -- -----------------------------------------------------
--- Table `host_reservations`
+-- Table \`host_reservations\`
 -- -----------------------------------------------------
 CREATE TABLE host_reservations (
     id bigint,
@@ -46,13 +46,13 @@ CREATE TABLE host_reservations (
     option_subnet_id int,
     PRIMARY KEY (id)
 );
-CREATE INDEX host_reservationsindex1 ON host_reservations (host_identifier);
-CREATE INDEX host_reservationsindex2 ON host_reservations (host_identifier_type);
-CREATE INDEX host_reservationsindex3 ON host_reservations (host_ipv4_subnet_id);
-CREATE INDEX host_reservationsindex4 ON host_reservations (host_ipv6_subnet_id);
-CREATE INDEX host_reservationsindex5 ON host_reservations (host_ipv4_address);
-CREATE INDEX host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
-CREATE INDEX host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
+CREATE INDEX IF NOT EXISTS host_reservationsindex1 ON host_reservations (host_identifier);
+CREATE INDEX IF NOT EXISTS host_reservationsindex2 ON host_reservations (host_identifier_type);
+CREATE INDEX IF NOT EXISTS host_reservationsindex3 ON host_reservations (host_ipv4_subnet_id);
+CREATE INDEX IF NOT EXISTS host_reservationsindex4 ON host_reservations (host_ipv6_subnet_id);
+CREATE INDEX IF NOT EXISTS host_reservationsindex5 ON host_reservations (host_ipv4_address);
+CREATE INDEX IF NOT EXISTS host_reservationsindex6 ON host_reservations (reserved_ipv6_prefix_address);
+CREATE INDEX IF NOT EXISTS host_reservationsindex7 ON host_reservations (reserved_ipv6_prefix_length);
 
 DELETE FROM schema_version WHERE version=1;
 INSERT INTO schema_version (version, minor) VALUES(2, 0);
index 4bde2fcf3ac4a9f37cebee30119a630ba0b0b6e2..8e8ac1d200dd92b2bdb3d6dc3fc78ce86443308f 100644 (file)
@@ -9,5 +9,4 @@ sqlscripts_DATA += upgrade_3.0_to_4.0.sh
 sqlscripts_DATA += upgrade_4.0_to_4.1.sh
 sqlscripts_DATA += upgrade_4.1_to_5.0.sh
 
-
 EXTRA_DIST = ${sqlscripts_DATA}