2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#805,!5-p] kea-dhcp6 now supports max-row-errors parameter

src/bin/dhcp6/dhcp6_lexer.ll
src/bin/dhcp6/dhcp6_parser.yy
    Added max-row-errors

src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
    TEST_F(LeaseFileLoaderTest, maxRowErrors6) - new unit test
    to verify max-row-errors operation
This commit is contained in:
Thomas Markwalder 2019-08-09 11:18:35 -04:00
parent 331888d203
commit 5caea854fd
10 changed files with 7418 additions and 1222 deletions

View File

@ -590,7 +590,6 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
} }
} }
\"valid-lifetime\" { \"valid-lifetime\" {
switch(driver.ctx_) { switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP4: case isc::dhcp::Parser4Context::DHCP4:

File diff suppressed because it is too large Load Diff

View File

@ -777,6 +777,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
} }
} }
\"max-row-errors\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::LEASE_DATABASE:
return isc::dhcp::Dhcp6Parser::make_MAX_ROW_ERRORS(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("max_row_errors", driver.loc_);
}
}
\"preferred-lifetime\" { \"preferred-lifetime\" {
switch(driver.ctx_) { switch(driver.ctx_) {
case isc::dhcp::Parser6Context::DHCP6: case isc::dhcp::Parser6Context::DHCP6:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -84,6 +84,7 @@ using namespace std;
REQUEST_TIMEOUT "request-timeout" REQUEST_TIMEOUT "request-timeout"
TCP_KEEPALIVE "tcp-keepalive" TCP_KEEPALIVE "tcp-keepalive"
TCP_NODELAY "tcp-nodelay" TCP_NODELAY "tcp-nodelay"
MAX_ROW_ERRORS "max-row-errors"
PREFERRED_LIFETIME "preferred-lifetime" PREFERRED_LIFETIME "preferred-lifetime"
MIN_PREFERRED_LIFETIME "min-preferred-lifetime" MIN_PREFERRED_LIFETIME "min-preferred-lifetime"
@ -691,6 +692,7 @@ database_map_param: database_type
| keyspace | keyspace
| consistency | consistency
| serial_consistency | serial_consistency
| max_row_errors
| unknown_map_entry | unknown_map_entry
; ;
@ -769,6 +771,11 @@ reconnect_wait_time: RECONNECT_WAIT_TIME COLON INTEGER {
ctx.stack_.back()->set("reconnect-wait-time", n); ctx.stack_.back()->set("reconnect-wait-time", n);
}; };
max_row_errors: MAX_ROW_ERRORS COLON INTEGER {
ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("max-row-errors", n);
};
request_timeout: REQUEST_TIMEOUT COLON INTEGER { request_timeout: REQUEST_TIMEOUT COLON INTEGER {
ElementPtr n(new IntElement($3, ctx.loc2pos(@3))); ElementPtr n(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("request-timeout", n); ctx.stack_.back()->set("request-timeout", n);

View File

@ -1,8 +1,12 @@
<<<<<<< HEAD
// A Bison parser, made by GNU Bison 3.4.1. // A Bison parser, made by GNU Bison 3.4.1.
=======
// A Bison parser, made by GNU Bison 3.2.1.
>>>>>>> [#805,!5-p] kea-dhcp6 now supports max-row-errors parameter
// Locations for Bison parsers in C++ // Locations for Bison parsers in C++
// Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. // Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -54,10 +58,9 @@
# endif # endif
# endif # endif
#line 14 "dhcp6_parser.yy" #line 14 "dhcp6_parser.yy" // location.cc:339
namespace isc { namespace dhcp { namespace isc { namespace dhcp {
#line 60 "location.hh" #line 60 "location.hh" // location.cc:339
/// A point in a source file. /// A point in a source file.
class position class position
{ {
@ -317,8 +320,7 @@ namespace isc { namespace dhcp {
return ostr; return ostr;
} }
#line 14 "dhcp6_parser.yy" #line 14 "dhcp6_parser.yy" // location.cc:339
} } // isc::dhcp } } // isc::dhcp
#line 323 "location.hh" #line 322 "location.hh" // location.cc:339
#endif // !YY_PARSER6_LOCATION_HH_INCLUDED #endif // !YY_PARSER6_LOCATION_HH_INCLUDED

View File

@ -1,4 +1,8 @@
<<<<<<< HEAD
// A Bison parser, made by GNU Bison 3.4.1. // A Bison parser, made by GNU Bison 3.4.1.
=======
// A Bison parser, made by GNU Bison 3.2.1.
>>>>>>> [#805,!5-p] kea-dhcp6 now supports max-row-errors parameter
// Starting with Bison 3.2, this file is useless: the structure it // Starting with Bison 3.2, this file is useless: the structure it
// used to define is now defined in "location.hh". // used to define is now defined in "location.hh".

View File

@ -1,4 +1,8 @@
<<<<<<< HEAD
// A Bison parser, made by GNU Bison 3.4.1. // A Bison parser, made by GNU Bison 3.4.1.
=======
// A Bison parser, made by GNU Bison 3.2.1.
>>>>>>> [#805,!5-p] kea-dhcp6 now supports max-row-errors parameter
// Starting with Bison 3.2, this file is useless: the structure it // Starting with Bison 3.2, this file is useless: the structure it
// used to define is now defined with the parser itself. // used to define is now defined with the parser itself.

View File

@ -312,7 +312,7 @@ protected:
}; };
LeaseFileLoaderTest::LeaseFileLoaderTest() LeaseFileLoaderTest::LeaseFileLoaderTest()
: filename_(absolutePath("leases4.csv")), io_(filename_) { : filename_(absolutePath("leases.csv")), io_(filename_) {
CfgMgr::instance().clear(); CfgMgr::instance().clear();
} }
@ -649,72 +649,58 @@ TEST_F(LeaseFileLoaderTest, loadWrite6LeaseRemove) {
} }
} }
// This test verifies that the exception is thrown when the specific // This test verifies that max-row-errors works correctly for
// number of errors in the test data occur during reading of the lease // DHCPv6 lease files
// file. TEST_F(LeaseFileLoaderTest, maxRowErrors6) {
TEST_F(LeaseFileLoaderTest, loadMaxErrors) { // We have 9 rows: 2 that are good, 7 that are flawed (too few fields).
std::string test_str; std::vector<std::string> rows = {
std::string a_1 = "192.0.2.1,06:07:08:09:0a:bc,," "3002::01,00:03:00:01:08:00:27:25:d3:01,30,1565361388,2,20,0,"
"200,200,8,1,1,host.example.com,1,\n"; "11189196,128,0,0,,08:00:27:25:d3:f4,0,\n",
std::string a_2 = "192.0.2.1,06:07:08:09:0a:bc,," "3002::02,00:03:00:01:08:00:27:25:d3:02,30,1565361388,2,20,0\n",
"200,500,8,1,1,host.example.com,1,\n"; "3002::03,00:03:00:01:08:00:27:25:d3:03,30,1565361388,2,20,0\n",
"3002::04,00:03:00:01:08:00:27:25:d3:04,30,1565361388,2,20,0\n",
"3002::05,00:03:00:01:08:00:27:25:d3:05,30,1565361388,2,20,0\n",
"3002::06,00:03:00:01:08:00:27:25:d3:06,30,1565361388,2,20,0\n",
"3002::07,00:03:00:01:08:00:27:25:d3:07,30,1565361388,2,20,0\n",
"3002::08,00:03:00:01:08:00:27:25:d3:08,30,1565361388,2,20,0\n",
"3002::09,00:03:00:01:08:00:27:25:d3:09,30,1565361388,2,20,0,"
"11189196,128,0,0,,08:00:27:25:d3:f4,0,\n"
};
std::string b_1 = "192.0.2.3,,a:11:01:04,200,200,8,1,1,host.example.com," std::ostringstream os;
"0,\n"; os << v6_hdr_;
for (auto row : rows) {
std::string c_1 = "192.0.2.10,01:02:03:04:05:06,,200,300,8,1,1,,1,\n"; os << row;
// Create a lease file for which there is a number of invalid
// entries. b_1 is invalid and gets used multiple times.
test_str = v4_hdr_ + a_1 + b_1 + b_1 + c_1 + b_1 + b_1 + a_2;
io_.writeFile(test_str);
boost::scoped_ptr<CSVLeaseFile4> lf(new CSVLeaseFile4(filename_));
ASSERT_NO_THROW(lf->open());
// Load leases and set the maximum number of errors to 3. This
// should result in an exception because there are 4 invalid entries.
Lease4Storage storage;
ASSERT_THROW(LeaseFileLoader::load<Lease4>(*lf, storage, 3),
util::CSVFileError);
// We should have made 6 attempts to read, with 2 leases read and 4 error
{
SCOPED_TRACE("Read leases 1");
checkStats(*lf, 6, 2, 4, 0, 0, 0);
} }
lf->close(); io_.writeFile(os.str());
boost::scoped_ptr<CSVLeaseFile6> lf(new CSVLeaseFile6(filename_));
ASSERT_NO_THROW(lf->open()); ASSERT_NO_THROW(lf->open());
// Repeat the test, but this time allow for 4 invalid entries. It // Let's limit the number of errors to 5 (we have 7 in the data) and
// should load just fine. // try to load the leases.
storage.clear(); uint32_t max_errors = 5;
ASSERT_NO_THROW(LeaseFileLoader::load<Lease4>(*lf, storage, 4)); Lease6Storage storage;
ASSERT_THROW(LeaseFileLoader::load<Lease6>(*lf, storage, max_errors), util::CSVFileError);
// We should have made 8 attempts to read, with 3 leases read and 4 error // We should have made 7 reads, with 1 lease read, and 6 errors.
{ {
SCOPED_TRACE("Read leases 2"); SCOPED_TRACE("Failed load stats");
checkStats(*lf, 8, 3, 4, 0, 0, 0); checkStats(*lf, 7, 1, 6, 0, 0, 0);
} }
ASSERT_EQ(2, storage.size()); // Now let's disable the error limit and try again.
max_errors = 0;
Lease4Ptr lease = getLease<Lease4Ptr>("192.0.2.1", storage); // Load leases from the file. Note, we have to reopen the file.
ASSERT_TRUE(lease); ASSERT_NO_THROW(lf->open());
EXPECT_EQ(300, lease->cltt_); ASSERT_NO_THROW(LeaseFileLoader::load<Lease6>(*lf, storage, max_errors));
lease = getLease<Lease4Ptr>("192.0.2.10", storage); // We should have made 10 reads, with 2 leases read, and 7 errors.
ASSERT_TRUE(lease);
EXPECT_EQ(100, lease->cltt_);
test_str = v4_hdr_ + a_2 + c_1;
writeLeases<Lease4, CSVLeaseFile4, Lease4Storage>(*lf, storage, test_str);
// We should have made 1 attempts to write, with 1 leases written and 0 errors
{ {
SCOPED_TRACE("Write leases"); SCOPED_TRACE("Good load stats");
checkStats(*lf, 0, 0, 0, 2, 2, 0); checkStats(*lf, 10, 2, 7, 0, 0, 0);
} }
} }