]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3682] Several corrections and compilation fixes.
authorTomek Mrugalski <tomasz@isc.org>
Sun, 18 Oct 2015 22:34:47 +0000 (00:34 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Sun, 18 Oct 2015 22:34:47 +0000 (00:34 +0200)
12 files changed:
src/lib/dhcpsrv/base_host_data_source.h
src/lib/dhcpsrv/database_connection.h
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/host_mgr.h
src/lib/dhcpsrv/hosts_messages.mes
src/lib/dhcpsrv/mysql_connection.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/mysql_host_data_source.h
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc

index 67c5aed5abc8522b50e89f6116c56b9dec9178f0..376a83297279ee95367b1e7f9de0f4f81f5dca41 100644 (file)
@@ -187,6 +187,17 @@ public:
     /// @return Type of the backend.
     virtual std::string getType() const = 0;
 
+    /// @brief Commit Transactions
+    ///
+    /// Commits all pending database operations.  On databases that don't
+    /// support transactions, this is a no-op.
+    virtual void commit() {};
+
+    /// @brief Rollback Transactions
+    ///
+    /// Rolls back all pending database operations.  On databases that don't
+    /// support transactions, this is a no-op.
+    virtual void rollback() {};
 };
 
 }
index 81a8c6f2b6ce71a23cfc43198bdfc282a0ef560d..047943491719a303d63a32f1b887d5dfb17afba7 100755 (executable)
@@ -57,7 +57,11 @@ class DatabaseConnection : public boost::noncopyable {
 public:
 
     /// @brief Defines maximum value for time that can be reliably stored.
-    // If I'm still alive I'll be too old to care. You fix it.
+    ///
+    /// @todo: Is this common for MySQL and Postgres? Maybe we should have
+    /// specific values for each backend?
+    ///
+    /// If I'm still alive I'll be too old to care. You fix it.
     static const time_t MAX_DB_TIME;
 
     /// @brief Database configuration parameter map
index a0ffb976f5ebadcc079c7effcad99c263ade76a4..245bf83fc1dfaed66303ed09cfb0ae4eb95ce399 100644 (file)
 
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/hosts_log.h>
+
+#ifdef HAVE_MYSQL
 #include <dhcpsrv/mysql_host_data_source.h>
+#endif
 
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
@@ -67,15 +71,18 @@ HostDataSourceFactory::create(const std::string& dbaccess) {
         return;
     }
 #endif
+
 #ifdef HAVE_PGSQL
     if (parameters[type] == string("postgresql")) {
         LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_DB).arg(redacted);
-        // set pgsql data source here, when it will be featured
+        isc_throw(NotImplemented, "Sorry, Postgres backend for host reservations "
+                  "is not implemented yet.");
+        // Set pgsql data source here, when it will be implemented.
         return;
     }
 #endif
 
-    // Get here on no match
+    // Get here on no match.
     LOG_ERROR(dhcpsrv_logger, DHCPSRV_UNKNOWN_DB).arg(parameters[type]);
     isc_throw(InvalidType, "Database access parameter 'type' does "
               "not specify a supported database backend");
@@ -86,16 +93,15 @@ HostDataSourceFactory::destroy() {
     // Destroy current host data source instance.  This is a no-op if no host
     // data source is available.
     if (getHostDataSourcePtr()) {
-        LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
-                DHCPSRV_CLOSE_HOST_DATA_SOURCE)
-                        .arg(getHostDataSourcePtr()->getType());
+        LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
+            .arg(getHostDataSourcePtr()->getType());
     }
     getHostDataSourcePtr().reset();
 }
 
 BaseHostDataSource&
 HostDataSourceFactory::instance() {
-       BaseHostDataSource* hdsptr = getHostDataSourcePtr().get();
+    BaseHostDataSource* hdsptr = getHostDataSourcePtr().get();
     if (hdsptr == NULL) {
         isc_throw(NoHostDataSourceManager,
                 "no current host data source instance is available");
index 64dd65ee09b2ce8aeea244a0ea4a674280015b72..6b54804f897c0048f6bb6661785c51f57524c38b 100644 (file)
@@ -38,6 +38,8 @@ namespace dhcp {
 
 using namespace isc::asiolink;
 
+boost::shared_ptr<BaseHostDataSource> HostMgr::alternate_source;
+
 boost::scoped_ptr<HostMgr>&
 HostMgr::getHostMgrPtr() {
     static boost::scoped_ptr<HostMgr> host_mgr_ptr;
@@ -45,21 +47,15 @@ HostMgr::getHostMgrPtr() {
 }
 
 void
-HostMgr::create(const std::string& /*access*/) {
+HostMgr::create(const std::string& access) {
     getHostMgrPtr().reset(new HostMgr());
-/*
-    try {
+
+    if (!access.empty()) {
         HostDataSourceFactory::create(access);
-    } catch (...) {
-        std::cerr << "Unable to open database.";
-        throw;
-    }
-*/
-    //alternate_source = &(HostDataSourceFactory::instance());
-    //alternate_source.reset(&(HostDataSourceFactory::instance()));
 
-    /// @todo Initialize alternate_source here, using the parameter.
-    /// For example: alternate_source.reset(new MysqlHostDataSource(access)).
+        /// @todo Initialize alternate_source here.
+        //alternate_source = HostDataSourceFactory::getHostDataSourcePtr();
+    }
 }
 
 HostMgr&
index 098468c6b2c5656ad1d6373fc999820e14151274..80aac53786b62b249709c23474d99ad3c62d431e 100644 (file)
@@ -216,7 +216,7 @@ private:
     /// @brief Pointer to an alternate host data source.
     ///
     /// If this pointer is NULL, the source is not in use.
-    boost::shared_ptr<BaseHostDataSource> alternate_source;
+    static boost::shared_ptr<BaseHostDataSource> alternate_source;
 
     /// @brief Returns a pointer to the currently used instance of the
     /// @c HostMgr.
index cc3b8545a2132fd07d3f01486aed2a8e3a6c157b..0644b4594d08b7f685ed3dd0d3d026a5914a7e5c 100644 (file)
@@ -19,6 +19,10 @@ This debug message is issued when new host (with reservations) is added to
 the server's configuration. The argument describes the host and its
 reservations in detail.
 
+% HOSTS_CFG_CLOSE_HOST_DATA_SOURCE Closing host data source: %1
+This is a normal message being printed when the server closes host data
+source connection.
+
 % HOSTS_CFG_GET_ALL_ADDRESS4 get all hosts with reservations for IPv4 address %1
 This debug message is issued when starting to retrieve all hosts, holding the
 reservation for the specific IPv4 address, from the configuration. The
index a94e7e253ccef62f266933ff4bc4d344d6c9afdc..fcce51f504e9387ae6355c7d0567e0daffc7e1a8 100755 (executable)
@@ -17,7 +17,7 @@
 
 #include <dhcpsrv/database_connection.h>
 #include <boost/scoped_ptr.hpp>
-#include <mysql.h>
+#include <mysql/mysql.h>
 #include <vector>
 
 namespace isc {
index f5555dba271c0aa02699b9953a14517d9c3df85e..b3958a2a2752a6da64138b71325752105bc98a98 100644 (file)
@@ -970,6 +970,17 @@ std::pair<uint32_t, uint32_t> MySqlHostDataSource::getVersion() const {
        return (std::make_pair(major, minor));
 }
 
+void
+MySqlHostDataSource::commit() {
+    conn_.commit();
+}
+
+
+void
+MySqlHostDataSource::rollback() {
+    conn_.rollback();
+}
+
 
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
index 42f614d30a69e405e525074630cc81f949e45685..65a8627397e556a0156ec6f570c696f85316ed28 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/utility.hpp>
-#include <mysql.h>
+#include <mysql/mysql.h>
 
 namespace isc {
 namespace dhcp {
@@ -32,10 +32,9 @@ class MySqlHostReservationExchange;
 
 /// @brief MySQL Host Data Source
 ///
-/// This class provides the \ref isc::dhcp::BaseHostDataSource interface to the MySQL
+/// This class provides the @ref isc::dhcp::BaseHostDataSource interface to the MySQL
 /// database.  Use of this backend presupposes that a MySQL database is
 /// available and that the Kea schema has been created within it.
-
 class MySqlHostDataSource: public BaseHostDataSource {
 public:
 
@@ -219,6 +218,18 @@ public:
     ///        has failed.
     virtual std::pair<uint32_t, uint32_t> getVersion() const;
 
+    /// @brief Commit Transactions
+    ///
+    /// Commits all pending database operations.  On databases that don't
+    /// support transactions, this is a no-op.
+    virtual void commit();
+
+    /// @brief Rollback Transactions
+    ///
+    /// Rolls back all pending database operations.  On databases that don't
+    /// support transactions, this is a no-op.
+    virtual void rollback();
+
     MySqlConnection* getDatabaseConnection() {
         return &conn_;
     }
index b0c744dc599d3b763ba44d0607e74958ff514bdd..c8b70c7499a59638d72eec1834c0d7930c51698c 100644 (file)
@@ -27,11 +27,12 @@ namespace dhcp {
 namespace test {
 
 GenericHostDataSourceTest::GenericHostDataSourceTest()
-       :hdsptr_(NULL){
+    :hdsptr_(NULL) {
 
 }
 
-GenericHostDataSourceTest::~GenericHostDataSourceTest(){}
+GenericHostDataSourceTest::~GenericHostDataSourceTest() {
+}
 
 
 
index e133406df530e7bd9c4baa1e38c205e46d83efcb..7e4fa5cc576c5d15e1db14a322258eb72b1d4841 100644 (file)
@@ -42,10 +42,8 @@ public:
     /// @brief Virtual destructor.
     virtual ~GenericHostDataSourceTest();
 
-
     /// @brief Pointer to the host data source
     BaseHostDataSource* hdsptr_;
-
 };
 
 }; // namespace test
index ece4422cf68dfe3ebda8fa7d16d69834e68a2b30..0190ea45eb5067dec4e907ee74f2ce72d566f943 100644 (file)
@@ -22,7 +22,6 @@
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/host_data_source_factory.h>
 
-
 #include <gtest/gtest.h>
 
 #include <algorithm>
@@ -58,8 +57,6 @@ const char* INVALID_USER = "user=invaliduser";
 const char* VALID_PASSWORD = "password=keatest";
 const char* INVALID_PASSWORD = "password=invalid";
 
-MySqlHostDataSource* myhdsptr_;
-
 // Given a combination of strings above, produce a connection string.
 string connectionString(const char* type, const char* name, const char* host,
                         const char* user, const char* password) {
@@ -151,7 +148,7 @@ public:
     /// @brief Constructor
     ///
     /// Deletes everything from the database and opens it.
-       MySqlHostDataSourceTest() {
+    MySqlHostDataSourceTest() {
 
         // Ensure schema is the correct one.
         destroySchema();
@@ -168,7 +165,8 @@ public:
                          "*** accompanying exception output.\n";
             throw;
         }
-        myhdsptr_ = (MySqlHostDataSource *) &(HostDataSourceFactory::instance());
+
+        hdsptr_ = &(HostDataSourceFactory::instance());
     }
 
     /// @brief Destructor
@@ -176,7 +174,7 @@ public:
     /// Rolls back all pending transactions.  The deletion of myhdsptr_ will close
     /// the database.  Then reopen it and delete everything created by the test.
     virtual ~MySqlHostDataSourceTest() {
-        myhdsptr_->getDatabaseConnection()->rollback();
+        hdsptr_->rollback();
         HostDataSourceFactory::destroy();
         destroySchema();
     }
@@ -189,21 +187,21 @@ public:
     /// Parameter is ignored for MySQL backend as the v4 and v6 leases share
     /// the same database.
     void reopen(Universe) {
-       HostDataSourceFactory::destroy();
-       HostDataSourceFactory::create(validConnectionString());
-       myhdsptr_ = (MySqlHostDataSource *) &(HostDataSourceFactory::instance());
+        HostDataSourceFactory::destroy();
+        HostDataSourceFactory::create(validConnectionString());
+        hdsptr_ = &(HostDataSourceFactory::instance());
     }
 
 };
 
 /// @brief Check that database can be opened
 ///
-/// This test checks if the MySqlLeaseMgr can be instantiated.  This happens
+/// This test checks if the MySqlHostDataSource can be instantiated.  This happens
 /// only if the database can be opened.  Note that this is not part of the
 /// MySqlLeaseMgr test fixure set.  This test checks that the database can be
 /// opened: the fixtures assume that and check basic operations.
 
-TEST(MySqlOpenTest, OpenDatabase) {
+TEST(MySqlHostDataSource, OpenDatabase) {
 
     // Schema needs to be created for the test to work.
     destroySchema();
@@ -212,7 +210,7 @@ TEST(MySqlOpenTest, OpenDatabase) {
     // Check that lease manager open the database opens correctly and tidy up.
     //  If it fails, print the error message.
     try {
-       HostDataSourceFactory::create(validConnectionString());
+        HostDataSourceFactory::create(validConnectionString());
         EXPECT_NO_THROW((void) HostDataSourceFactory::instance());
         HostDataSourceFactory::destroy();
     } catch (const isc::Exception& ex) {