From: Andrei Pavel Date: Wed, 8 Jun 2016 07:36:38 +0000 (+0300) Subject: refactored cassandra backend and fixed minor issues X-Git-Tag: trac4283_base~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df16b6f0fbc989a5947d4f760446ace475fce5ea;p=thirdparty%2Fkea.git refactored cassandra backend and fixed minor issues --- diff --git a/src/bin/admin/tests/.gitignore b/src/bin/admin/tests/.gitignore index 78af251d7b..b46230da6f 100644 --- a/src/bin/admin/tests/.gitignore +++ b/src/bin/admin/tests/.gitignore @@ -1,3 +1,4 @@ /memfile_tests.sh /mysql_tests.sh /pgsql_tests.sh +/cql_tests.sh diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 7418e16f96..660b2bf515 100755 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -60,6 +60,36 @@ namespace isc { namespace dhcp { +enum ExchangeDataType { + EXCHANGE_DATA_TYPE_NONE, + EXCHANGE_DATA_TYPE_BOOL, + EXCHANGE_DATA_TYPE_INT32, + EXCHANGE_DATA_TYPE_INT64, + EXCHANGE_DATA_TYPE_TIMESTAMP, + EXCHANGE_DATA_TYPE_STRING, + EXCHANGE_DATA_TYPE_BYTES +}; + +enum ExchangeDataTypeIO { + EXCHANGE_DATA_TYPE_IO_IN, + EXCHANGE_DATA_TYPE_IO_OUT, + EXCHANGE_DATA_TYPE_IO_IN_OUT +}; + +struct ExchangeColumnInfo { + ExchangeColumnInfo () : column_(NULL), type_io_(EXCHANGE_DATA_TYPE_IO_IN), type_(EXCHANGE_DATA_TYPE_NONE) {}; + ExchangeColumnInfo (const char *column, ExchangeDataTypeIO type_io, ExchangeDataType type) : column_(column), type_io_(type_io), type_(type) {}; + const char* column_; + ExchangeDataTypeIO type_io_; + ExchangeDataType type_; +}; + +class SqlExchange { +public: + SqlExchange () {}; + virtual ~SqlExchange() {}; + std::vector parameters_; ///< Column names and types +}; /// @brief Abstract Lease Manager /// /// This is an abstract API for lease database backends. It provides unified diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index 19be2d0a93..849aee5420 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -394,14 +394,19 @@ public: hostname_ = getRawColumnValue(r, row, HOSTNAME_COL); + uint32_t state; + getColumnValue(r, row , STATE_COL, state); + HWAddrPtr hwaddr(new HWAddr(hwaddr_buffer_, hwaddr_length_, HTYPE_ETHER)); - return (Lease4Ptr(new Lease4(addr4_, hwaddr, + Lease4Ptr result(new Lease4(addr4_, hwaddr, client_id_buffer_, client_id_length_, valid_lifetime_, 0, 0, cltt_, subnet_id_, fqdn_fwd_, fqdn_rev_, - hostname_))); + hostname_)); + result->state_ = state; + return (result); } catch (const std::exception& ex) { isc_throw(DbOperationError, "Could not convert data to Lease4, reason: " @@ -588,6 +593,9 @@ public: hostname_ = getRawColumnValue(r, row, HOSTNAME_COL); + uint32_t state; + getColumnValue(r, row , STATE_COL, state); + /// @todo: implement this in #3557. HWAddrPtr hwaddr; @@ -597,6 +605,7 @@ public: subnet_id_, fqdn_fwd_, fqdn_rev_, hostname_, hwaddr, prefix_len_)); result->cltt_ = cltt_; + result->state_ = state; return (result); } catch (const std::exception& ex) { isc_throw(DbOperationError, diff --git a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc index b3af9a2c1b..a817a620a9 100644 --- a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc @@ -101,7 +101,7 @@ TEST(CqlOpenTest, OpenDatabase) { createCqlSchema(false, true); // Check that lease manager open the database opens correctly and tidy up. - // If it fails, print the error message. + // If it fails, print the error message. try { LeaseMgrFactory::create(validCqlConnectionString()); EXPECT_NO_THROW((void) LeaseMgrFactory::instance()); @@ -113,6 +113,21 @@ TEST(CqlOpenTest, OpenDatabase) { << "*** before the CQL tests will run correctly.\n"; } + // 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); + LeaseMgrFactory::create(connection_string); + EXPECT_NO_THROW((void) LeaseMgrFactory::instance()); + LeaseMgrFactory::destroy(); + } catch (const isc::Exception& ex) { + FAIL() << "*** ERROR: unable to open database, reason:\n" + << " " << ex.what() << "\n" + << "*** The test environment is broken and must be fixed\n" + << "*** before the CQL tests will run correctly.\n"; + } + // Check that attempting to get an instance of the lease manager when // none is set throws an exception. EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager); @@ -123,6 +138,7 @@ TEST(CqlOpenTest, OpenDatabase) { 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)), InvalidType); @@ -131,16 +147,27 @@ TEST(CqlOpenTest, OpenDatabase) { EXPECT_THROW(LeaseMgrFactory::create(connectionString( CQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)), DbOpenError); + EXPECT_THROW(LeaseMgrFactory::create(connectionString( CQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)), DbOpenError); + EXPECT_THROW(LeaseMgrFactory::create(connectionString( CQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)), DbOpenError); + EXPECT_THROW(LeaseMgrFactory::create(connectionString( CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)), DbOpenError); + // Check for invalid timeouts + EXPECT_THROW(LeaseMgrFactory::create(connectionString( + CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)), + DbInvalidTimeout); + EXPECT_THROW(LeaseMgrFactory::create(connectionString( + CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)), + DbInvalidTimeout); + // Check for missing parameters EXPECT_THROW(LeaseMgrFactory::create(connectionString( CQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)), diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 1334ac5d32..b31d94868b 100755 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -69,7 +69,7 @@ public: /// Closes the database and re-open it. Anything committed should be /// visible. /// - /// Parameter is ignored for Postgres abckend as the v4 and v6 leases share + /// Parameter is ignored for Postgres backend as the v4 and v6 leases share /// the same database. void reopen(Universe) { LeaseMgrFactory::destroy(); @@ -93,7 +93,7 @@ TEST(PgSqlOpenTest, OpenDatabase) { createPgSQLSchema(true); // Check that lease manager open the database opens correctly and tidy up. - // If it fails, print the error message. + // If it fails, print the error message. try { LeaseMgrFactory::create(validPgSQLConnectionString()); EXPECT_NO_THROW((void) LeaseMgrFactory::instance()); @@ -117,7 +117,7 @@ TEST(PgSqlOpenTest, OpenDatabase) { FAIL() << "*** ERROR: unable to open database, reason:\n" << " " << ex.what() << "\n" << "*** The test environment is broken and must be fixed\n" - << "*** before the MySQL tests will run correctly.\n"; + << "*** before the PostgreSQL tests will run correctly.\n"; } // Check that attempting to get an instance of the lease manager when