Commit 66f4a42a authored by Francis Dupont's avatar Francis Dupont

[5584] Checkpoint: core code and test done

parent 5336c37e
......@@ -490,9 +490,9 @@ cql_dump() {
# Get the query appropriate to lease version. Explicitly specify all columns
# so that they are returned in expected order.
if [ $dump_type -eq 4 ]; then
dump_query="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM lease4"
dump_query="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context FROM lease4"
elif [ $dump_type -eq 6 ]; then
dump_query="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM lease6"
dump_query="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state,user_context FROM lease6"
else
log_error "lease-dump: lease type ( -4 or -6 ) needs to be specified"
usage
......
#!/bin/sh
# Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -40,11 +40,11 @@ cql_lease_init_test() {
assert_eq 0 $? "schema_version table check failed, expected exit code: %d, actual: %d"
# Check lease4 table
cql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state FROM lease4;"
cql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease4;"
assert_eq 0 $? "lease4 table check failed, expected exit code: %d, actual: %d"
# Check lease6 table
cql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state FROM lease6;"
cql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease6;"
assert_eq 0 $? "lease6 table check failed, expected exit code: %d, actual: %d"
# Check lease6_types table
......@@ -82,7 +82,7 @@ cql_lease_version_test() {
# Verify that kea-admin lease-version returns the correct version.
version=$($keaadmin lease-version cql -u $db_user -p $db_password -n $db_name)
assert_str_eq "2.0" $version "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "3.0" $version "Expected kea-admin to return %s, returned value was %s"
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
......@@ -152,16 +152,16 @@ cql_lease4_dump_test() {
# 1436173267 corresponds to 2015-06-06 11:01:07
insert_cql="\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
fqdn_fwd, fqdn_rev, hostname, state, user_context)\
VALUES(-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,\
'one.example.com', 0);\
'one.example.com', 0, '');\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
VALUES(-1073741301,NULL,textAsBlob('123'),40,1433464245,50,true,true,'', 1);\
fqdn_fwd, fqdn_rev, hostname, state, user_context)\
VALUES(-1073741301,NULL,textAsBlob('123'),40,1433464245,50,true,true,'', 1, '');\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
fqdn_fwd, fqdn_rev, hostname, state, user_context)\
VALUES(-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,\
'three.example.com', 2);"
'three.example.com', 2, '');"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease4 failed, expected exit code %d, actual %d"
......@@ -222,19 +222,19 @@ cql_lease6_dump_test() {
insert_cql="\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
hwaddr, hwtype, hwaddr_source, state, user_context)\
VALUES('2001:db8::10',textAsBlob('20'),30,1430694930,40,50,1,60,70,true,true,\
'one.example.com',textAsBlob('80'),90,16,0);\
'one.example.com',textAsBlob('80'),90,16,0,'');\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
hwaddr, hwtype, hwaddr_source, state, user_context)\
VALUES('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true,\
'',textAsBlob('80'),90,1,1);\
'',textAsBlob('80'),90,1,1,'');\
INSERT INTO lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
hwaddr, hwtype, hwaddr_source, state, user_context)\
VALUES('2001:db8::12',textAsBlob('21'),30,1436173267,40,50,1,60,70,true,true,\
'three.example.com',textAsBlob('80'),90,4,2);"
'three.example.com',textAsBlob('80'),90,4,2,'');"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease6 failed, expected exit code %d, actual %d"
......
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state
-1073741302,0x3230,0x3330,40,1430694930,50,True,True,one.example.com,0
-1073741301,null,0x313233,40,1433464245,50,True,True,,1
-1073741300,0x3232,null,40,1436173267,50,True,True,three.example.com,2
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
-1073741302,0x3230,0x3330,40,1430694930,50,True,True,one.example.com,0,
-1073741301,null,0x313233,40,1433464245,50,True,True,,1,
-1073741300,0x3232,null,40,1436173267,50,True,True,three.example.com,2,
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
2001:db8::12,0x3231,30,1436173267,40,50,1,60,70,True,True,three.example.com,0x3830,90,4,2
2001:db8::11,null,30,1433464245,40,50,1,60,70,True,True,,0x3830,90,1,1
2001:db8::10,0x3230,30,1430694930,40,50,1,60,70,True,True,one.example.com,0x3830,90,16,0
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state,user_context
2001:db8::12,0x3231,30,1436173267,40,50,1,60,70,True,True,three.example.com,0x3830,90,4,2,
2001:db8::11,null,30,1433464245,40,50,1,60,70,True,True,,0x3830,90,1,1,
2001:db8::10,0x3230,30,1430694930,40,50,1,60,70,True,True,one.example.com,0x3830,90,16,0,
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state
0.0.0.10,3230,3330,40,2015-01-01 01:15:30,50,1,1,one.example.com,default
0.0.0.11,,313233,40,2015-02-02 02:30:45,50,1,1,,declined
0.0.0.12,3232,,40,2015-03-03 11:01:07,50,1,1,three.example.com,expired-reclaimed
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
0.0.0.10,3230,3330,40,2015-01-01 01:15:30,50,1,1,one.example.com,default,
0.0.0.11,,313233,40,2015-02-02 02:30:45,50,1,1,,declined,
0.0.0.12,3232,,40,2015-03-03 11:01:07,50,1,1,three.example.com,expired-reclaimed,
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default
11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,HWADDR_SOURCE_RAW,declined
12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,HWADDR_SOURCE_DUID,expired-reclaimed
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state,user_context
10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default,
11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,HWADDR_SOURCE_RAW,declined,
12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,HWADDR_SOURCE_DUID,expired-reclaimed,
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state
0.0.0.10,20,30,40,<timestamp1>,50,1,1,one.example.com,default
0.0.0.11,,013233,40,<timestamp2>,50,1,1,,declined
0.0.0.12,22,,40,<timestamp3>,50,1,1,three.example.com,expired-reclaimed
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
0.0.0.10,20,30,40,<timestamp1>,50,1,1,one.example.com,default,
0.0.0.11,,013233,40,<timestamp2>,50,1,1,,declined,
0.0.0.12,22,,40,<timestamp3>,50,1,1,three.example.com,expired-reclaimed,
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,state,hwaddr,hwtype,hwaddr_source
10,20,30,<timestamp1>,40,50,IA_TA,60,70,1,1,one.example.com,default,80,90,HWADDR_SOURCE_REMOTE_ID
11,,30,<timestamp2>,40,50,IA_TA,60,70,1,1,,declined,80,90,HWADDR_SOURCE_RAW
12,21,30,<timestamp3>,40,50,IA_TA,60,70,1,1,three.example.com,expired-reclaimed,80,90,HWADDR_SOURCE_DUID
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,state,user_context,hwaddr,hwtype,hwaddr_source
10,20,30,<timestamp1>,40,50,IA_TA,60,70,1,1,one.example.com,default,,80,90,HWADDR_SOURCE_REMOTE_ID
11,,30,<timestamp2>,40,50,IA_TA,60,70,1,1,,declined,,80,90,HWADDR_SOURCE_RAW
12,21,30,<timestamp3>,40,50,IA_TA,60,70,1,1,three.example.com,expired-reclaimed,,80,90,HWADDR_SOURCE_DUID
......@@ -258,7 +258,7 @@ mysql_upgrade_test() {
assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
# Ok, we have a 1.0 database. Let's upgrade it to 6.0
# Ok, we have a 1.0 database. Let's upgrade it to 6.1
${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
......@@ -449,9 +449,30 @@ EOF
# lease4/6_stats changes are tested separately
# Verify upgraded schema reports version 6.0
#table: user_context to lease4 and lease6 (upgrade 6.0 -> 6.1)
# verify that lease4 table includes user_context
qry="select user_context from lease4";
count=`mysql_execute "${qry}"`
ERRCODE=$?
assert_eq 0 $ERRCODE "select user_context from lease4 failed. (expected status code %d, returned %d)"
# verify that lease6 table includes user_context
qry="select user_context from lease6";
count=`mysql_execute "${qry}"`
ERRCODE=$?
assert_eq 0 $ERRCODE "select user_context from lease6 failed. (expected status code %d, returned %d)"
#table: logs (upgrade 6.0 -> 6.1)
mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
SELECT timestamp, address, log FROM logs;
EOF
ERRCODE=$?
assert_eq 0 $ERRCODE "logs table is missing or broken. (expected status code %d, returned %d)"
# Verify upgraded schema reports version 6.1
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "6.0" ${version} "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "6.1" ${version} "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
mysql_wipe
......@@ -492,9 +513,9 @@ mysql_lease4_dump_test() {
# Insert the reference record
insert_sql="\
insert into lease4 values(10,20,30,40,'2015-01-01 01:15:30',50,1,1,'one.example.com', 0);\
insert into lease4 values(11,NULL,123,40,'2015-02-02 02:30:45',50,1,1,'', 1);\
insert into lease4 values(12,22,NULL,40,'2015-03-03 11:01:07',50,1,1,'three.example.com', 2);"
insert into lease4 values(10,20,30,40,'2015-01-01 01:15:30',50,1,1,'one.example.com', 0,NULL);\
insert into lease4 values(11,NULL,123,40,'2015-02-02 02:30:45',50,1,1,'', 1,NULL);\
insert into lease4 values(12,22,NULL,40,'2015-03-03 11:01:07',50,1,1,'three.example.com', 2,NULL);"
mysql_execute "$insert_sql"
ERRCODE=$?
......@@ -552,9 +573,9 @@ mysql_lease6_dump_test() {
# Insert the reference record
insert_sql="\
insert into lease6 values(10,20,30,'2015-04-04 01:15:30',40,50,1,60,70,1,1,'one.example.com',80,90,16,0);\
insert into lease6 values(11,NULL,30,'2015-05-05 02:30:45',40,50,1,60,70,1,1,'',80,90,1,1);\
insert into lease6 values(12,21,30,'2015-06-06 11:01:07',40,50,1,60,70,1,1,'three.example.com',80,90,4,2);"
insert into lease6 values(10,20,30,'2015-04-04 01:15:30',40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
insert into lease6 values(11,NULL,30,'2015-05-05 02:30:45',40,50,1,60,70,1,1,'',80,90,1,1,NULL);\
insert into lease6 values(12,21,30,'2015-06-06 11:01:07',40,50,1,60,70,1,1,'three.example.com',80,90,4,2,NULL);"
mysql_execute "$insert_sql"
ERRCODE=$?
......
......@@ -80,11 +80,11 @@ pgsql_lease_init_test() {
assert_eq 0 $? "schema_version table check failed, expected exit code: %d, actual: %d"
# Check lease4 table
RESULT=`pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state FROM lease4;"`
RESULT=`pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease4;"`
assert_eq 0 $? "lease4 table check failed, expected exit code: %d, actual: %d"
# Check lease6 table
RESULT=`pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state FROM lease6;"`
RESULT=`pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease6;"`
assert_eq 0 $? "lease6 table check failed, expected exit code: %d, actual: %d"
# Check lease6_types table
......@@ -120,7 +120,7 @@ pgsql_lease_version_test() {
# Verify that kea-admin lease-version returns the correct version
version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name)
assert_str_eq "4.0" ${version} "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "4.1" ${version} "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
pgsql_wipe
......@@ -230,10 +230,25 @@ pgsql_upgrade_2_0_to_3_0() {
assert_eq 1 "$output" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
}
pgsql_upgrade_3_0_to_4_0() {
# Verify upgraded schema reports version 4.0.
pgsql_upgrade_3_0_to_4_1() {
# Verify upgraded schema reports version 4.1.
version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "4.0" ${version} "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "4.1" ${version} "Expected kea-admin to return %s, returned value was %s"
# Added user_context to lease4
output=`pgsql_execute "select user_context from lease4;"`
ERRCODE=$?
assert_eq 0 $ERRCODE "lease4 is missing user_context column. (expected status code %d, returned %d)"
# Added user_context to lease6
output=`pgsql_execute "select user_context from lease6;"`
ERRCODE=$?
assert_eq 0 $ERRCODE "lease6 is missing user_context column. (expected status code %d, returned %d)"
# Added logs table
output=`pgsql_execute "select timestamp, address, log from logs;"`
ERRCODE=$?
assert_eq 0 $ERRCODE "logs table is missing or broken. (expected status code %d, returned %d)"
}
pgsql_upgrade_test() {
......@@ -255,8 +270,8 @@ pgsql_upgrade_test() {
# Check 2.0 to 3.0 upgrade
pgsql_upgrade_2_0_to_3_0
# Check 3.0 to 4.0 upgrade
pgsql_upgrade_3_0_to_4_0
# Check 3.0 to 4.1 upgrade
pgsql_upgrade_3_0_to_4_1
# Let's wipe the whole database
pgsql_wipe
......@@ -328,9 +343,9 @@ pgsql_lease4_dump_test() {
# Insert the reference records
insert_sql="\
insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one.example.com', 0);\
insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','', 1);\
insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com', 2);"
insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one.example.com', 0, '');\
insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','', 1, '');\
insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com', 2, '');"
pgsql_execute "$insert_sql"
ERRCODE=$?
......@@ -423,9 +438,9 @@ pgsql_lease6_dump_test() {
# Insert the reference records
insert_sql="\
insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','one.example.com', 0,decode('80','hex'),90,16);\
insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','', 1,decode('80','hex'),90,1);\
insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com', 2,decode('80','hex'),90,4);"
insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','one.example.com', 0,decode('80','hex'),90,16,'');\
insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','', 1,decode('80','hex'),90,1,'');\
insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com', 2,decode('80','hex'),90,4,'');"
pgsql_execute "$insert_sql"
ERRCODE=$?
......
......@@ -676,8 +676,10 @@ CqlLease4Exchange::retrieve() {
ConstElementPtr ctx;
if (!user_context_.empty()) {
ctx = Element::fromJSON(user_context_);
isc_throw(BadValue, "user context '" << user_context_
<< "' is not a JSON map");
if (!ctx || (ctx->getType() != Element::map)) {
isc_throw(BadValue, "user context '" << user_context_
<< "' is not a JSON map");
}
}
Lease4Ptr result(new Lease4(addr4, hwaddr, client_id_.data(),
......@@ -1424,8 +1426,10 @@ CqlLease6Exchange::retrieve() {
ConstElementPtr ctx;
if (!user_context_.empty()) {
ctx = Element::fromJSON(user_context_);
isc_throw(BadValue, "user context '" << user_context_
<< "' is not a JSON map");
if (!ctx ||(ctx->getType() != Element::map)) {
isc_throw(BadValue, "user context '" << user_context_
<< "' is not a JSON map");
}
}
// Create the lease and set the cltt (after converting from the
......
......@@ -545,7 +545,7 @@ Lease6::toText() const {
<< "State: " << statesToText(state_) << "\n";
if (getContext()) {
stream << "User context: " << getContext() << "\n";
stream << "User context: " << getContext()->str() << "\n";
}
return (stream.str());
......@@ -566,7 +566,7 @@ Lease4::toText() const {
<< "State: " << statesToText(state_) << "\n";
if (getContext()) {
stream << "User context: " << getContext() << "\n";
stream << "User context: " << getContext()->str() << "\n";
}
return (stream.str());
......
......@@ -15,6 +15,7 @@
using namespace isc;
using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::util;
......@@ -105,7 +106,7 @@ CSVLeaseFile4Test::writeSampleFile() const {
"host.example.com,0,\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");
"0,0,,1,{ \"foobar\": true }\n");
}
// This test checks the capability to read and parse leases from the file.
......@@ -143,6 +144,7 @@ TEST_F(CSVLeaseFile4Test, parse) {
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("host.example.com", lease->hostname_);
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
EXPECT_FALSE(lease->getContext());
}
// Second lease is malformed - HW address is empty when state
......@@ -174,6 +176,8 @@ TEST_F(CSVLeaseFile4Test, parse) {
EXPECT_FALSE(lease->fqdn_rev_);
EXPECT_TRUE(lease->hostname_.empty());
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
ASSERT_TRUE(lease->getContext());
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
// There are no more leases. Reading should cause no error, but the returned
......@@ -216,11 +220,12 @@ TEST_F(CSVLeaseFile4Test, recreate) {
checkStats(lf, 0, 0, 0, 1, 1, 0);
}
// Create second lease, with non-NULL client id.
// Create second lease, with non-NULL client id and user context.
lease.reset(new Lease4(IOAddress("192.0.3.10"),
hwaddr1_,
CLIENTID, sizeof(CLIENTID),
100, 60, 90, 0, 7));
lease->setContext(Element::fromJSON("{ \"foobar\": true }"));
{
SCOPED_TRACE("Second write");
ASSERT_NO_THROW(lf.append(*lease));
......@@ -235,7 +240,7 @@ TEST_F(CSVLeaseFile4Test, recreate) {
"192.0.3.2,00:01:02:03:04:05,,200,200,8,1,1,host.example.com,"
"2,\n"
"192.0.3.10,0d:0e:0a:0d:0b:0e:0e:0f,01:02:03:04,100,100,7,0,"
"0,,0,\n",
"0,,0,{ \"foobar\": true }\n",
io_.readFile());
}
......@@ -253,9 +258,9 @@ TEST_F(CSVLeaseFile4Test, mixedSchemaload) {
// schema 2.0 record - has state
"192.0.2.2,06:07:08:09:2a:bc,,200,200,8,1,1,"
"two.example.com,1\n"
// schema 2.0 record - has state
// schema 2.1 record - has state and user context
"192.0.2.3,06:07:08:09:3a:bc,,200,200,8,1,1,"
"three.example.com,2\n"
"three.example.com,2,{ \"foobar\": true }\n"
);
// Open the lease file.
......@@ -283,6 +288,7 @@ TEST_F(CSVLeaseFile4Test, mixedSchemaload) {
EXPECT_EQ("one.example.com", lease->hostname_);
// Verify that added state is DEFAULT
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
EXPECT_FALSE(lease->getContext());
}
{
......@@ -302,6 +308,7 @@ TEST_F(CSVLeaseFile4Test, mixedSchemaload) {
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("two.example.com", lease->hostname_);
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
EXPECT_FALSE(lease->getContext());
}
{
......@@ -321,6 +328,8 @@ TEST_F(CSVLeaseFile4Test, mixedSchemaload) {
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
EXPECT_EQ(Lease::STATE_EXPIRED_RECLAIMED, lease->state_);
ASSERT_TRUE(lease->getContext());
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
}
......@@ -384,6 +393,7 @@ TEST_F(CSVLeaseFile4Test, downGrade) {
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
EXPECT_EQ(Lease::STATE_EXPIRED_RECLAIMED, lease->state_);
EXPECT_FALSE(lease->getContext());
}
}
......
......@@ -15,6 +15,7 @@
using namespace isc;
using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::util;
......@@ -107,7 +108,7 @@ CSVLeaseFile6Test::writeSampleFile() const {
"2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,300,300,6,150,"
"0,8,0,0,0,,,1,\n"
"3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,0,200,8,0,2,"
"16,64,0,0,,,1,\n");
"16,64,0,0,,,1,{ \"foobar\": true }\n");
}
// This test checks the capability to read and parse leases from the file.
......@@ -147,6 +148,8 @@ TEST_F(CSVLeaseFile6Test, parse) {
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("host.example.com", lease->hostname_);
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
EXPECT_FALSE(lease->getContext());
}
// Second lease is malformed - DUID is empty.
......@@ -178,6 +181,8 @@ TEST_F(CSVLeaseFile6Test, parse) {
EXPECT_FALSE(lease->fqdn_fwd_);
EXPECT_FALSE(lease->fqdn_rev_);
EXPECT_TRUE(lease->hostname_.empty());
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
EXPECT_FALSE(lease->getContext());
}
// Reading the fourth lease should be successful.
......@@ -201,6 +206,9 @@ TEST_F(CSVLeaseFile6Test, parse) {
EXPECT_FALSE(lease->fqdn_fwd_);
EXPECT_FALSE(lease->fqdn_rev_);
EXPECT_TRUE(lease->hostname_.empty());
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
ASSERT_TRUE(lease->getContext());
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
// There are no more leases. Reading should cause no error, but the returned
......@@ -260,6 +268,7 @@ TEST_F(CSVLeaseFile6Test, recreate) {
7, 150, 300, 40, 70, 10, false, false,
"", HWAddrPtr(), 64));
lease->cltt_ = 0;
lease->setContext(Element::fromJSON("{ \"foobar\": true }"));
{
SCOPED_TRACE("Third write");
ASSERT_NO_THROW(lf.append(*lease));
......@@ -274,7 +283,7 @@ TEST_F(CSVLeaseFile6Test, recreate) {
"2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05"
",300,300,6,150,0,8,128,0,0,,,0,\n"
"3000:1:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"300,300,10,150,2,7,64,0,0,,,0,\n",
"300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true }\n",
io_.readFile());
}
......@@ -296,7 +305,12 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) {
// schema 3.0 record - has hwaddr and state
"2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:03,"
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1\n");
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1\n"
// schema 3.1 record - has hwaddr, state and user context
"2001:db8:1::4,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:03,"
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1,"
"{ \"foobar\": true }\n");
// Open the lease file.
CSVLeaseFile6 lf(filename_);
......@@ -326,6 +340,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) {
EXPECT_FALSE(lease->hwaddr_);
// Verify that added state is STATE_DEFAULT
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
EXPECT_FALSE(lease->getContext());
}
{
......@@ -351,6 +366,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) {
EXPECT_EQ("01:02:03:04:05", lease->hwaddr_->toText(false));
// Verify that added state is STATE_DEFAULT
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
EXPECT_FALSE(lease->getContext());
}
{
......@@ -375,6 +391,33 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) {
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("0a:0b:0c:0d:0e", lease->hwaddr_->toText(false));
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
EXPECT_FALSE(lease->getContext());
}
{
SCOPED_TRACE("Forth lease valid");
EXPECT_TRUE(lf.next(lease));
ASSERT_TRUE(lease);
// Verify that the lease attributes are correct.
EXPECT_EQ("2001:db8:1::4", lease->addr_.toText());
ASSERT_TRUE(lease->duid_);
EXPECT_EQ("00:01:02:03:04:05:06:0a:0b:0c:0d:0e:03", lease->duid_->toText());
EXPECT_EQ(200, lease->valid_lft_);
EXPECT_EQ(0, lease->cltt_);
EXPECT_EQ(8, lease->subnet_id_);
EXPECT_EQ(100, lease->preferred_lft_);
EXPECT_EQ(Lease::TYPE_NA, lease->type_);
EXPECT_EQ(7, lease->iaid_);
EXPECT_EQ(0, lease->prefixlen_);
EXPECT_TRUE(lease->fqdn_fwd_);
EXPECT_TRUE(lease->fqdn_rev_);
EXPECT_EQ("three.example.com", lease->hostname_);
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("0a:0b:0c:0d:0e", lease->hwaddr_->toText(false));
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
ASSERT_TRUE(lease->getContext());
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
}
......@@ -412,10 +455,10 @@ TEST_F(CSVLeaseFile6Test, downGrade) {
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,"
"hwaddr,state,user_context,FUTURE_COL\n"
// schema 3.0 record - has hwaddr and state
// schema 3.1 record - has hwaddr, state and user context
"2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:03,"
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1,,"
"BOGUS\n");
"200,200,8,100,0,7,0,1,1,three.example.com,0a:0b:0c:0d:0e,1,"
"{ \"foobar\": true },BOGUS\n");
// Open should succeed in the event someone is downgrading.
CSVLeaseFile6 lf(filename_);
......@@ -448,6 +491,8 @@ TEST_F(CSVLeaseFile6Test, downGrade) {
ASSERT_TRUE(lease->hwaddr_);
EXPECT_EQ("0a:0b:0c:0d:0e", lease->hwaddr_->toText(false));
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
ASSERT_TRUE(lease->getContext());
EXPECT_EQ("{ \"foobar\": true }", lease->getContext()->str());
}
}
......
......@@ -22,6 +22,7 @@
using namespace std;
using namespace isc::asiolink;
using namespace isc::data;
namespace isc {
namespace dhcp {
......@@ -156,6 +157,8 @@ GenericLeaseMgrTest::initializeLease4(std::string address) {
lease->fqdn_rev_ = false;
lease->fqdn_fwd_ = false;
lease->hostname_ = "otherhost.example.com.";
lease->setContext(Element::fromJSON("{ \"foo\": true }"));
} else if (address == straddress4_[6]) {
lease->hwaddr_.reset(new HWAddr(vector<uint8_t>(6, 0x6e), HTYPE_ETHER));
// Same ClientId as straddress4_1
......@@ -177,6 +180,7 @@ GenericLeaseMgrTest::initializeLease4(std::string address) {
lease->fqdn_rev_ = true;
lease->fqdn_fwd_ = true;
lease->hostname_ = "myhost.example.com.";
lease->setContext(Element::fromJSON("{ \"bar\": false }"));
} else {
// Unknown address, return an empty pointer.
......@@ -288,6 +292,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) {
lease->fqdn_fwd_ = false;
lease->fqdn_rev_ = true;
lease->hostname_ = "hostname.example.com.";
lease->setContext(Element::fromJSON("{ \"foo\": true }"));
} else if (address == straddress6_[6]) {
// Same DUID as straddress6_1
......@@ -317,6 +322,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) {
lease->fqdn_fwd_ = false;
lease->fqdn_rev_ = true;
lease->hostname_ = "hostname.example.com.";
lease->setContext(Element::fromJSON("{ \"bar\": false }"));
} else {
// Unknown address, return an empty pointer.
......@@ -533,6 +539,17 @@ GenericLeaseMgrTest::testGetLease4HWAddr2() {
// Should be three leases, matching leases[1], [3] and [5].
ASSERT_EQ(3, returned.size());
// Check the lease[5] (and only this one) has an user context.
size_t contexts = 0;
for (Lease4Collection::const_iterator i = returned.begin();
i != returned.end(); ++i) {
if ((*i)->getContext()) {
++contexts;
EXPECT_EQ("{ \"foo\": true }", (*i)->getContext()->str());
}
}
EXPECT_EQ(1, contexts);
// Easiest way to check is to look at the addresses.
vector<string> addresses;
for (Lease4Collection::const_iterator i = returned.begin();
......@@ -708,6 +725,7 @@ void
GenericLeaseMgrTest::testBasicLease4() {
// Get the leases to be used for the test.
vector<Lease4Ptr> leases = createLeases4();
leases[2]->setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
// Start the tests. Add three leases to the database, read them back and
// check they are what we think they are.
......@@ -785,6 +803,7 @@ void
GenericLeaseMgrTest::testBasicLease6() {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
leases[2]->setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
// Start the tests. Add three leases to the database, read them back and
// check they are what we think they are.
......@@ -1123,6 +1142,17 @@ GenericLeaseMgrTest::testGetLease4ClientId2() {
// Should be four leases, matching leases[1], [4], [5] and [6].
ASSERT_EQ(4, returned.size());
// Check the lease[5] (and only this one) has an user context.
size_t contexts = 0;
for (Lease4Collection::const_iterator i = returned.begin();
i != returned.end(); ++i) {
if ((*i)->getContext()) {
++contexts;
EXPECT_EQ("{ \"foo\": true }", (*i)->getContext()->str());
}
}
EXPECT_EQ(1, contexts);