Commit 9b19d774 authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[5058] CSVLeaseFile4 now properly loads declined leases

src/lib/dhcpsrv/csv_lease_file4.cc
    CSVLeaseFile4::next() - modified to produce a read error
    if the hardware address is empty and the lease state
    is NOT declined.

    CSVLeaseFile4::readHWAddr() - no longer throws an exception
    if the hardware address is empty

src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc
src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
    Changed test lease data so invalid records do not
    have lease state of declined
parent 8ce85344
......@@ -97,6 +97,12 @@ CSVLeaseFile4::next(Lease4Ptr& lease) {
// Get the HW address. It should never be empty and the readHWAddr checks
// that.
HWAddr hwaddr = readHWAddr(row);
uint32_t state = readState(row);
if (hwaddr.hwaddr_.empty() && state != Lease::STATE_DECLINED) {
isc_throw(isc::BadValue, "A blank hardware address is only"
" valid for declined leases");
}
lease.reset(new Lease4(readAddress(row),
HWAddrPtr(new HWAddr(hwaddr)),
client_id_vec.empty() ? NULL : &client_id_vec[0],
......@@ -108,7 +114,7 @@ CSVLeaseFile4::next(Lease4Ptr& lease) {
readFqdnFwd(row),
readFqdnRev(row),
readHostname(row)));
lease->state_ = readState(row);
lease->state_ = state;
} catch (std::exception& ex) {
// bump the read error count
......@@ -152,10 +158,6 @@ CSVLeaseFile4::readAddress(const CSVRow& row) {
HWAddr
CSVLeaseFile4::readHWAddr(const CSVRow& row) {
HWAddr hwaddr = HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")));
if (hwaddr.hwaddr_.empty()) {
isc_throw(isc::BadValue, "hardware address in the lease file"
" must not be empty");
}
return (hwaddr);
}
......
......@@ -103,7 +103,7 @@ CSVLeaseFile4Test::writeSampleFile() const {
"fqdn_fwd,fqdn_rev,hostname,state\n"
"192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,"
"host.example.com,0\n"
"192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com,1\n"
"192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com,0\n"
"192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,100,100,7,"
"0,0,,1\n");
}
......@@ -145,7 +145,8 @@ TEST_F(CSVLeaseFile4Test, parse) {
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
}
// Second lease is malformed - HW address is empty.
// Second lease is malformed - HW address is empty when state
// is not delcined.
{
SCOPED_TRACE("Second lease malformed");
EXPECT_FALSE(lf.next(lease));
......
......@@ -181,7 +181,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite4) {
"100,135,7,0,0,,1\n";
std::string c_1 = "192.0.2.3,,a:11:01:04,"
"200,200,8,1,1,host.example.com,1\n";
"200,200,8,1,1,host.example.com,0\n";
// Create lease file with leases for 192.0.2.1, 192.0.3.15. The lease
// entry for the 192.0.2.3 is invalid (lacks HW address) and should
......@@ -427,7 +427,7 @@ TEST_F(LeaseFileLoaderTest, loadMaxErrors) {
std::string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,500,8,1,1,host.example.com,1\n";
std::string b_1 = "192.0.2.3,,a:11:01:04,200,200,8,1,1,host.example.com,1\n";
std::string b_1 = "192.0.2.3,,a:11:01:04,200,200,8,1,1,host.example.com,0\n";
std::string c_1 = "192.0.2.10,01:02:03:04:05:06,,200,300,8,1,1,,1\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment