From: Tomek Mrugalski Date: Fri, 9 Oct 2015 21:28:19 +0000 (+0200) Subject: [master] Merge branch 'trac3681_rebase' (Common MySQL Connection class) X-Git-Tag: trac3874_base~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=884d8bb4a55d3d7b1b8f3f01efb312bd8dec399b;p=thirdparty%2Fkea.git [master] Merge branch 'trac3681_rebase' (Common MySQL Connection class) 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 --- 884d8bb4a55d3d7b1b8f3f01efb312bd8dec399b diff --cc configure.ac index 9dbd0eedc0,97a20dcaba..9dbd0eedc0 mode 100644,100755..100755 --- a/configure.ac +++ b/configure.ac diff --cc src/bin/admin/scripts/mysql/Makefile.am index 419474510f,e91622b88f..419474510f mode 100644,100755..100755 --- a/src/bin/admin/scripts/mysql/Makefile.am +++ b/src/bin/admin/scripts/mysql/Makefile.am diff --cc src/bin/admin/scripts/mysql/dhcpdb_create.mysql index c30b463ffa,fd7b42b7f8..c30b463ffa mode 100644,100755..100755 --- a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql +++ b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql diff --cc src/bin/admin/tests/mysql_tests.sh.in index c9c2b8d929,f8f1d776dd..6a29ad3a4f mode 100644,100755..100755 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in diff --cc src/lib/dhcpsrv/lease.cc index 854cec4f4c,616974852d..854cec4f4c mode 100644,100755..100755 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc diff --cc src/lib/dhcpsrv/lease_mgr.h index 4574c45e93,d7536a9d12..7e1024a103 mode 100644,100755..100755 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@@ -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 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 @@@ -425,17 -364,40 +398,6 @@@ /// @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 diff --cc src/lib/dhcpsrv/lease_mgr_factory.cc index 2216d6e30d,a754e35a32..6e656e28dd mode 100644,100755..100755 --- a/src/lib/dhcpsrv/lease_mgr_factory.cc +++ b/src/lib/dhcpsrv/lease_mgr_factory.cc diff --cc src/lib/dhcpsrv/lease_mgr_factory.h index 2f47e28314,e718d4388c..e96450561a mode 100644,100755..100755 --- a/src/lib/dhcpsrv/lease_mgr_factory.h +++ b/src/lib/dhcpsrv/lease_mgr_factory.h @@@ -16,10 -16,9 +16,11 @@@ #define LEASE_MGR_FACTORY_H #include + #include #include +#include + #include namespace isc { diff --cc src/lib/dhcpsrv/memfile_lease_mgr.cc index 9072ba72ba,876907c318..df28c7d4ae mode 100644,100755..100755 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@@ -17,7 -17,7 +17,8 @@@ #include #include #include +#include + #include #include #include #include @@@ -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"; @@@ -858,8 -707,8 +859,8 @@@ 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. } diff --cc src/lib/dhcpsrv/memfile_lease_mgr.h index 2e94f9c769,e5995c8023..f4c8e1f31d mode 100644,100755..100755 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h diff --cc src/lib/dhcpsrv/mysql_lease_mgr.cc index cdd82f3c22,e1e8bb360f..7308ce3d48 mode 100644,100755..100755 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@@ -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(mysql_stmt_affected_rows(statements_[stindex]))); - return (mysql_stmt_affected_rows(conn_.statements_[stindex]) > 0); ++ return (static_cast(mysql_stmt_affected_rows(conn_.statements_[stindex]))); } -- bool MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) { LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, diff --cc src/lib/dhcpsrv/mysql_lease_mgr.h index f6f8068e58,1e25ed4826..98b5aab12a mode 100644,100755..100755 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h diff --cc src/lib/dhcpsrv/tests/Makefile.am index 2267667e61,fedeeb5bc7..d96d1dfae5 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@@ -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 diff --cc src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 75d4238b82,0e1cf7282e..75d4238b82 mode 100644,100755..100755 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc diff --cc src/lib/dhcpsrv/tests/schema_mysql_copy.h index cb93bbe09a,5e60fe3262..ae07e98520 mode 100644,100755..100755 --- a/src/lib/dhcpsrv/tests/schema_mysql_copy.h +++ b/src/lib/dhcpsrv/tests/schema_mysql_copy.h @@@ -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 };