]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3681_rebase' (Common MySQL Connection class)
authorTomek Mrugalski <tomasz@isc.org>
Fri, 9 Oct 2015 21:28:19 +0000 (23:28 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 9 Oct 2015 21:28:19 +0000 (23:28 +0200)
Conflicts:
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/schema_mysql_copy.h

21 files changed:
1  2 
configure.ac
src/bin/admin/scripts/mysql/Makefile.am
src/bin/admin/scripts/mysql/dhcpdb_create.mysql
src/bin/admin/tests/mysql_tests.sh.in
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/lease.cc
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/lease_mgr_factory.cc
src/lib/dhcpsrv/lease_mgr_factory.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.h
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/schema_mysql_copy.h

diff --cc configure.ac
index 9dbd0eedc0ddfcb13ca33eaa8e315ceaca66d878,97a20dcabac8692930460257fd3bc040cd272608..9dbd0eedc0ddfcb13ca33eaa8e315ceaca66d878
mode 100644,100755..100755
index 419474510f36f287da453ec99164a47208cd85e1,e91622b88f01438c2594a732666fd620e25d0d7d..419474510f36f287da453ec99164a47208cd85e1
mode 100644,100755..100755
index c30b463ffa2a57d133c3060f904631e44c7f3db7,fd7b42b7f8cf0272d4113d5c9b2b4e0ec9115b56..c30b463ffa2a57d133c3060f904631e44c7f3db7
mode 100644,100755..100755
index c9c2b8d9295f6cd676396e1bd69e29e823a958d7,f8f1d776dd7a2845de27d360671d092c405d0baa..6a29ad3a4f24331081a2ec72728c3a2a4a4212e3
mode 100644,100755..100755
Simple merge
index 854cec4f4c550b977f0113ec1fc5533b07f3bcf4,616974852d6bd50baae58ef297a4197d94dd8ed5..854cec4f4c550b977f0113ec1fc5533b07f3bcf4
mode 100644,100755..100755
index 4574c45e930af806e8d2d3841c358241c02ab7d3,d7536a9d12ece055da2946c82aebb8d460a1663b..7e1024a103a8532dd32dd1cfd42f8060979a2880
mode 100644,100755..100755
@@@ -127,15 -116,9 +106,9 @@@ public
      // If I'm still alive I'll be too old to care. You fix it.
      static const time_t MAX_DB_TIME;
  
-     /// Database configuration parameter map
-     typedef std::map<std::string, std::string> ParameterMap;
      /// @brief Constructor
      ///
-     /// @param parameters A data structure relating keywords and values
-     ///        concerned with the database.
-     LeaseMgr(const ParameterMap& parameters)
-         : parameters_(parameters)
 -    LeaseMgr() : io_service_(new asiolink::IOService())
++    LeaseMgr()
      {}
  
      /// @brief Destructor
      /// @todo: Add host management here
      /// As host reservation is outside of scope for 2012, support for hosts
      /// is currently postponed.
--
-     /// @brief returns value of the parameter
-     virtual std::string getParameter(const std::string& name) const;
--
- private:
-     /// @brief list of parameters passed in dbconfig
 -    /// @brief Returns the interval at which the @c IOService events should
 -    /// be released.
--    ///
-     /// That will be mostly used for storing database name, username,
-     /// password and other parameters required for DB access. It is not
-     /// intended to keep any DHCP-related parameters.
-     ParameterMap parameters_;
 -    /// The implementations of this class may install the timers which
 -    /// periodically trigger event handlers defined for them. Depending
 -    /// on the intervals specified for these timers the @c IOService::poll,
 -    /// @c IOService::run etc. have to be executed to allow the timers
 -    /// for checking whether they have already expired and the handler
 -    /// must be executed. Running the @c IOService with a lower interval
 -    /// would cause the desynchronization of timers with the clock.
 -    ///
 -    /// @return A maximum interval in seconds at which the @c IOService
 -    /// should be executed. A value of 0 means that no timers are installed
 -    /// and that there is no requirement for the @c IOService to be
 -    /// executed at any specific interval.
 -    virtual uint32_t getIOServiceExecInterval() const {
 -        return (0);
 -    }
 -
 -    /// @brief Returns a reference to the @c IOService object used
 -    /// by the Lease Manager.
 -    const asiolink::IOServicePtr& getIOService() const {
 -        return (io_service_);
 -    }
 -
 -
 -private:
 -
 -    /// @brief Pointer to the IO service object used by the derived classes
 -    /// to trigger interval timers.
 -    asiolink::IOServicePtr io_service_;
 -
  };
  
  }; // end of isc::dhcp namespace
index 2216d6e30df0209af0366e6852deda3c8a0ffe8e,a754e35a322a93981ad22dd77f5e545f2be601d2..6e656e28dd32bcc48238b33d2ff6975366198f7a
mode 100644,100755..100755
index 2f47e2831416d9038232be5375305ce2a102dc9f,e718d4388cd69bdbb68ff86706febe6d8061402f..e96450561a1986ed30f8779f896d583a551cb461
mode 100644,100755..100755
  #define LEASE_MGR_FACTORY_H
  
  #include <dhcpsrv/lease_mgr.h>
+ #include <dhcpsrv/database_connection.h>
  #include <exceptions/exceptions.h>
  
 +#include <boost/scoped_ptr.hpp>
 +
  #include <string>
  
  namespace isc {
index 9072ba72ba956ae7fc0bc172a604eb85b88df1a8,876907c318a16577c90e2b1a6ee1a84abc0f0fa4..df28c7d4ae632609cf3dd629d930764940ae0b73
mode 100644,100755..100755
@@@ -17,7 -17,7 +17,8 @@@
  #include <dhcpsrv/dhcpsrv_log.h>
  #include <dhcpsrv/lease_file_loader.h>
  #include <dhcpsrv/memfile_lease_mgr.h>
 +#include <dhcpsrv/timer_mgr.h>
+ #include <dhcpsrv/database_connection.h>
  #include <exceptions/exceptions.h>
  #include <util/pid_file.h>
  #include <util/process_spawn.h>
@@@ -244,16 -221,13 +245,16 @@@ LFCSetup::getExitStatus() const 
      return (process_->getExitStatus(pid_));
  }
  
 -Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters):
 -        lfc_setup_(new LFCSetup(boost::bind(&Memfile_LeaseMgr::lfcCallback, this),
 -                              *getIOService())),
 -        conn_(parameters)
 +// Explicit definition of class static constants.  Values are given in the
 +// declaration so they're not needed here.
 +const int Memfile_LeaseMgr::MAJOR_VERSION;
 +const int Memfile_LeaseMgr::MINOR_VERSION;
 +
- Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters)
-     : LeaseMgr(parameters), lfc_setup_()
++Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters)
++    : LeaseMgr(), lfc_setup_(), conn_(parameters)
      {
      // Check the universe and use v4 file or v6 file.
-     std::string universe = getParameter("universe");
+     std::string universe = conn_.getParameter("universe");
      if (universe == "4") {
          std::string file4 = initLeaseFilePath(V4);
          if (!file4.empty()) {
@@@ -840,8 -689,8 +841,8 @@@ std::strin
  Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
      std::string persist_val;
      try {
-         persist_val = getParameter("persist");
+         persist_val = conn_.getParameter("persist");
 -    } catch (const Exception& ex) {
 +    } catch (const Exception&) {
          // If parameter persist hasn't been specified, we use a default value
          // 'yes'.
          persist_val = "true";
  
      std::string lease_file;
      try {
-         lease_file = getParameter("name");
+         lease_file = conn_.getParameter("name");
 -    } catch (const Exception& ex) {
 +    } catch (const Exception&) {
          lease_file = getDefaultLeaseFilePath(u);
      }
      return (lease_file);
@@@ -944,8 -793,8 +945,8 @@@ voi
  Memfile_LeaseMgr::lfcSetup() {
      std::string lfc_interval_str = "0";
      try {
-         lfc_interval_str = getParameter("lfc-interval");
+         lfc_interval_str = conn_.getParameter("lfc-interval");
 -    } catch (const std::exception& ex) {
 +    } catch (const std::exception&) {
          // Ignore and default to 0.
      }
  
index 2e94f9c7691cbf07db9f9517aab48b7835e46826,e5995c80234de6693af283fd4beb95b4f88d5f9c..f4c8e1f31d00dbab2be536010f77ac5ff75feed8
mode 100644,100755..100755
index cdd82f3c2234b314b069242b5a2c9446188791c5,e1e8bb360f832b9bcdf130feed865ce61d7be2f0..7308ce3d489f968cfc06541de98ff3b81e7bad44
mode 100644,100755..100755
@@@ -2168,10 -1817,10 +1951,9 @@@ MySqlLeaseMgr::deleteLeaseCommon(Statem
  
      // See how many rows were affected.  Note that the statement may delete
      // multiple rows.
-     return (static_cast<uint64_t>(mysql_stmt_affected_rows(statements_[stindex])));
 -    return (mysql_stmt_affected_rows(conn_.statements_[stindex]) > 0);
++    return (static_cast<uint64_t>(mysql_stmt_affected_rows(conn_.statements_[stindex])));
  }
  
--
  bool
  MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
      LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
index f6f8068e588c7de37614685d7d9f49c02d524ca7,1e25ed4826c5534079458ab7df3f3b6165034fa2..98b5aab12a80a5a4fca92cba3beb93893801324c
mode 100644,100755..100755
Simple merge
Simple merge
index 2267667e61d939d3cc8cf708239ed33203b41ede,fedeeb5bc7c87e19efb28fcc7fb2ebff0935e2f0..d96d1dfae54d15922421a418c59c790004308787
@@@ -80,8 -73,8 +80,9 @@@ libdhcpsrv_unittests_SOURCES += csv_lea
  libdhcpsrv_unittests_SOURCES += d2_client_unittest.cc
  libdhcpsrv_unittests_SOURCES += d2_udp_unittest.cc
  libdhcpsrv_unittests_SOURCES += daemon_unittest.cc
+ libdhcpsrv_unittests_SOURCES += database_connection_unittest.cc
  libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc
 +libdhcpsrv_unittests_SOURCES += expiration_config_parser_unittest.cc
  libdhcpsrv_unittests_SOURCES += host_mgr_unittest.cc
  libdhcpsrv_unittests_SOURCES += host_unittest.cc
  libdhcpsrv_unittests_SOURCES += host_reservation_parser_unittest.cc
index 75d4238b828e36824a23447a6af56fc8725f0ba1,0e1cf7282e03c5eb90f2461cbb759ed6727afd7e..75d4238b828e36824a23447a6af56fc8725f0ba1
mode 100644,100755..100755
index cb93bbe09af7bb306ff7f9b6898659188ee518e9,5e60fe3262f4f3af3978637b98ff2933e09d72bc..ae07e98520dba5bce71f4ba8bf75fdcdf36f809a
mode 100644,100755..100755
@@@ -125,31 -133,86 +133,111 @@@ const char* create_statement[] = 
      "UPDATE schema_version SET version=\"2\", minor=\"0\";",
      // Schema upgrade to 2.0 ends here.
  
+     // Schema upgrade to 3.0 starts here.
+     "CREATE TABLE IF NOT EXISTS hosts ("
+         "host_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+         "dhcp_identifier VARBINARY(128) NOT NULL,"
+         "dhcp_identifier_type TINYINT NOT NULL,"
+         "dhcp4_subnet_id INT UNSIGNED NULL,"
+         "dhcp6_subnet_id INT UNSIGNED NULL,"
+         "ipv4_address INT UNSIGNED NULL,"
+         "hostname VARCHAR(255) NULL,"
+         "dhcp4_client_classes VARCHAR(255) NULL,"
+         "dhcp6_client_classes VARCHAR(255) NULL,"
+         "PRIMARY KEY (host_id),"
+         "INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC),"
+         "INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC)"
+     ")  ENGINE=INNODB",
+     "CREATE TABLE IF NOT EXISTS ipv6_reservations ("
+         "reservation_id INT NOT NULL AUTO_INCREMENT,"
+         "address VARCHAR(39) NOT NULL,"
+         "prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128,"
+         "type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0,"
+         "dhcp6_iaid INT UNSIGNED NULL,"
+         "host_id INT UNSIGNED NOT NULL,"
+         "PRIMARY KEY (reservation_id),"
+         "INDEX fk_ipv6_reservations_host_idx (host_id ASC),"
+         "CONSTRAINT fk_ipv6_reservations_Host FOREIGN KEY (host_id)"
+             "REFERENCES hosts (host_id)"
+             "ON DELETE NO ACTION ON UPDATE NO ACTION"
+     ")  ENGINE=INNODB",
+     "CREATE TABLE IF NOT EXISTS dhcp4_options ("
+         "option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+         "code TINYINT UNSIGNED NOT NULL,"
+         "value BLOB NULL,"
+         "formatted_value TEXT NULL,"
+         "space VARCHAR(128) NULL,"
+         "persistent TINYINT(1) NOT NULL DEFAULT 0,"
+         "dhcp_client_class VARCHAR(128) NULL,"
+         "dhcp4_subnet_id INT NULL,"
+         "host_id INT UNSIGNED NULL,"
+         "PRIMARY KEY (option_id),"
+         "UNIQUE INDEX option_id_UNIQUE (option_id ASC),"
+         "INDEX fk_options_host1_idx (host_id ASC),"
+         "CONSTRAINT fk_options_host1 FOREIGN KEY (host_id)"
+             "REFERENCES hosts (host_id)"
+             "ON DELETE NO ACTION ON UPDATE NO ACTION"
+     ")  ENGINE=INNODB",
+     "CREATE TABLE IF NOT EXISTS dhcp6_options ("
+         "option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
+         "code INT UNSIGNED NOT NULL,"
+         "value BLOB NULL,"
+         "formatted_value TEXT NULL,"
+         "space VARCHAR(128) NULL,"
+         "persistent TINYINT(1) NOT NULL DEFAULT 0,"
+         "dhcp_client_class VARCHAR(128) NULL,"
+         "dhcp6_subnet_id INT NULL,"
+         "host_id INT UNSIGNED NULL,"
+         "PRIMARY KEY (option_id),"
+         "UNIQUE INDEX option_id_UNIQUE (option_id ASC),"
+         "INDEX fk_options_host1_idx (host_id ASC),"
+         "CONSTRAINT fk_options_host10 FOREIGN KEY (host_id)"
+             "REFERENCES hosts (host_id)"
+             "ON DELETE NO ACTION ON UPDATE NO ACTION"
+     ")  ENGINE=INNODB",
+     //"DELIMITER $$ ",
+     "CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW "
+     "BEGIN "
+     "DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id; "
+     "END ",
+     //"$$ ",
+     //"DELIMITER ;",
+     "UPDATE schema_version SET version = '3', minor = '0';",
+     // This line concludes database upgrade to version 3.0.
 +    // Schema upgrade to 4.0 starts here.
 +    "ALTER TABLE lease4 "
 +        "ADD COLUMN state INT UNSIGNED DEFAULT 0",
 +
 +    "ALTER TABLE lease6 "
 +        "ADD COLUMN state INT UNSIGNED DEFAULT 0",
 +
 +    "CREATE INDEX lease4_by_state_expire ON lease4 (state, expire)",
 +    "CREATE INDEX lease6_by_state_expire ON lease6 (state, expire)",
 +
 +    // Production schema includes the lease_state table which maps
 +    // the lease states to their names. This is not used in the unit tests
 +    // so it is commented out.
 +
 +    /*"CREATE TABLE IF NOT EXISTS lease_state (",
 +        "state INT UNSIGNED PRIMARY KEY NOT NULL,"
 +        "name VARCHAR(64) NOT NULL);",
 +
 +    "INSERT INTO lease_state VALUES (0, \"default\");",
 +    "INSERT INTO lease_state VALUES (1, \"declined\");",
 +    "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");",*/
 +
 +
 +    // Schema upgrade to 4.0 ends here.
 +
      NULL
  };