Commit 12ebb96c authored by Francis Dupont's avatar Francis Dupont

[master] Merged trac5584 (user context for leases)

parents 5dcb1744 9591b8fa
......@@ -1492,6 +1492,7 @@ AC_CONFIG_FILES([Makefile
src/share/database/scripts/Makefile
src/share/database/scripts/cql/Makefile
src/share/database/scripts/cql/upgrade_1.0_to_2.0.sh
src/share/database/scripts/cql/upgrade_2.0_to_3.0.sh
src/share/database/scripts/mysql/Makefile
src/share/database/scripts/mysql/upgrade_1.0_to_2.0.sh
src/share/database/scripts/mysql/upgrade_2.0_to_3.0.sh
......@@ -1501,6 +1502,7 @@ AC_CONFIG_FILES([Makefile
src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh
src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh
src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh
src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh
src/share/database/scripts/pgsql/Makefile
src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
src/share/database/scripts/pgsql/upgrade_2.0_to_3.0.sh
......@@ -1508,6 +1510,7 @@ AC_CONFIG_FILES([Makefile
src/share/database/scripts/pgsql/upgrade_3.1_to_3.2.sh
src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh
src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh
src/share/database/scripts/pgsql/upgrade_4.0_to_5.0.sh
tools/Makefile
tools/path_replacer.sh
])
......
......@@ -475,6 +475,7 @@ $ <userinput>ls -l /usr/local/lib/hooks/*.so</userinput>
errors, like adding a lease with subnet-id that does not exist in
the configuration or configuring a lease to use an address that is
outside of the subnet to which it is supposed to belong.
It provides a way to manage user contexts associated with leases.
</entry>
</row>
......@@ -720,7 +721,7 @@ path/base-name.CCYYMMDD.txt
An entry is a single string with no embedded end-of-line markers,
a prepended timestamp and has the following sections:
<screen>
timestamp address duration device-id {client-info} {relay-info}
timestamp address duration device-id {client-info} {relay-info} {user-context}
</screen>
</para>
<para>
......@@ -754,6 +755,9 @@ timestamp address duration device-id {client-info} {relay-info}
options: 1, 2 and 6) if present.
The circuit id and remote id are presented as hex strings
</para></listitem>
<listitem><para>
user-context - the optional user context associated to the lease.
</para></listitem>
</itemizedlist>
</para>
<para>
......@@ -835,7 +839,7 @@ with hardware address: 1a:1b:1c:1d:1e:1f, client-id: 1234567890
An entry is a single string with no embedded end-of-line markers,
a prepended timestamp and has the following sections:
<screen>
timestamp address duration device-id {relay-info}*
timestamp address duration device-id {relay-info}* {user-context}
</screen>
</para>
<para>
......@@ -868,6 +872,9 @@ timestamp address duration device-id {relay-info}*
topology. Nevertheless, this is useful information to better scope
down the location of the device, so it is being recorded, if present.
</para></listitem>
<listitem><para>
user-context - the optional user context associated to the lease.
</para></listitem>
</itemizedlist>
</para>
<para>
......@@ -1063,20 +1070,7 @@ Examples:
Please refer to <xref linkend="mysql-database"/> for MySQL,
to <xref linkend="pgsql-database"/> for PostgreSQL or
to <xref linkend="cql-database"/> for Cassandra CQL.
Scripts are in
<filename><replaceable>path-to-kea</replaceable>/share/kea/legal_log/scripts</filename> directory, for instance the PostgreSQL create schema
command is:
<screen>
$ <userinput>psql -d <replaceable>database-name</replaceable> -U <replaceable>user-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/legal_log/scripts/pgsql/legldb_create.pgsql</userinput>
Password for user <replaceable>user-name</replaceable>:
START TRANSACTION
CREATE TABLE
CREATE INDEX
CREATE TABLE
INSERT 0 1
COMMIT
$
</screen>
The logs table is part of the Kea database schemas.
</para>
<para>
Configuration parameters are extended by standard lease database
......@@ -1671,6 +1665,8 @@ An example deletion by (subnet-id, identifier-type, identifier) looks as follows
errors, like adding a lease with subnet-id that does not exist in the
configuration or configuring a lease to use an address that is outside
of the subnet to which it is supposed to belong.
It provides a not programmatic way to manage user contexts
associated to leases.
<note>
<para>This library may only be loaded by <command>kea-dhcp4</command>
......@@ -1875,6 +1871,11 @@ The commands can take a number of additional optional parameters:
configured for the subnet corresponding to the specified subnet-id
is used. This parameter is not used in IPv4.</para>
</listitem>
<listitem>
<para><command>user-context</command> - specifies the user
context to be associated with this lease. It must be a
JSON map.</para>
</listitem>
</itemizedlist>
</para>
......@@ -1894,7 +1895,8 @@ The commands can take a number of additional optional parameters:
"expire": 12345678,
"fqdn-fwd": true,
"fqdn-rev": true,
"hostname": "urania.example.org"
"hostname": "urania.example.org",
"user-context": { "version": 1 }
}
}
</screen>
......@@ -3136,6 +3138,7 @@ both the command and the response.
host reservations, control socket, dhcp ddns, loggers and server id.
These are supported in both DHCPv4 and DHCPv6 at the exception
of server id which is DHCPv6 only.
Kea 1.5 added user contexts assocated with leases.
</para>
</section>
......
......@@ -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,hwaddr,hwtype,hwaddr_source,user_context
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 7.0
${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 -> 7.0)
# 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 -> 7.0)
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 7.0
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 "7.0" ${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 "5.0" ${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_5_0() {
# Verify upgraded schema reports version 5.0.
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 "5.0" ${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 5.0 upgrade
pgsql_upgrade_3_0_to_5_0
# 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=$?
......
......@@ -84,11 +84,11 @@ protected:
cstr_ = base_dir + "/" + "config_file"; // config
v4_hdr_ = "address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
"fqdn_fwd,fqdn_rev,hostname,state\n";
"fqdn_fwd,fqdn_rev,hostname,state,user_context\n";
v6_hdr_ = "address,duid,valid_lifetime,expire,subnet_id,"
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state\n";
"fqdn_rev,hostname,hwaddr,state,user_context\n";
// and remove any outstanding test files
removeTestFile();
......@@ -398,27 +398,27 @@ TEST_F(LFCControllerTest, launch4) {
// We have several entries for different leases, the naming is:
// <lease letter>_<version#>
string a_1 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,200,8,1,1,host.example.com,1\n";
"200,200,8,1,1,host.example.com,1,\n";
string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,500,8,1,1,host.example.com,1\n";
"200,500,8,1,1,host.example.com,1,\n";
string a_3 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,800,8,1,1,host.example.com,1\n";
"200,800,8,1,1,host.example.com,1,{ \"foo\": true }\n";
string b_1 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
"100,100,7,0,0,,1\n";
"100,100,7,0,0,,1,{ \"bar\": false }\n";
string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
"100,135,7,0,0,,1\n";
"100,135,7,0,0,,1,\n";
string b_3 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,"
"100,150,7,0,0,,1\n";
"100,150,7,0,0,,1,\n";
// This one should be invalid, no hardware address and state is not declined
string c_1 = "192.0.2.3,,a:11:01:04,"
"200,200,8,1,1,host.example.com,0\n";
"200,200,8,1,1,host.example.com,0,\n";
string d_1 = "192.0.2.5,16:17:18:19:1a:bc,,"
"200,200,8,1,1,host.example.com,1\n";
"200,200,8,1,1,host.example.com,1,\n";
string d_2 = "192.0.2.5,16:17:18:19:1a:bc,,"
"0,200,8,1,1,host.example.com,1\n";
"0,200,8,1,1,host.example.com,1,\n";
// Subtest 1: both previous and copy available.
// Create the test previous file
......@@ -553,27 +553,29 @@ TEST_F(LFCControllerTest, launch6) {
// We have several entries for different leases, the naming is:
// <lease letter>_<version#>.
string a_1 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,200,8,100,0,7,0,1,1,host.example.com,,1\n";
string a_2 = "2001:db8:1::1,,200,200,8,100,0,7,0,1,1,host.example.com,,1\n";
"200,200,8,100,0,7,0,1,1,host.example.com,,1,\n";
string a_2 = "2001:db8:1::1,,200,200,8,100,0,7,0,1,1,"
"host.example.com,,1,\n";
string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,400,8,100,0,7,0,1,1,host.example.com,,1\n";
"200,400,8,100,0,7,0,1,1,host.example.com,,1,\n";
string a_4 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"0,200,8,100,0,7,0,1,1,host.example.com,,1\n";
"0,200,8,100,0,7,0,1,1,host.example.com,,1,"
"{ \"foo\": true }\n";
string b_1 = "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";
"300,300,6,150,0,8,0,0,0,,,1,{ \"bar\": false }\n";
string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
"300,800,6,150,0,8,0,0,0,,,1\n";
"300,800,6,150,0,8,0,0,0,,,1,\n";
string b_3 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05,"
"300,1000,6,150,0,8,0,0,0,,,1\n";
"300,1000,6,150,0,8,0,0,0,,,1,\n";
string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"100,200,8,0,2,16,64,0,0,,,1\n";
"100,200,8,0,2,16,64,0,0,,,1,\n";
string c_2 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"100,400,8,0,2,16,64,0,0,,,1\n";
"100,400,8,0,2,16,64,0,0,,,1,\n";
string d_1 = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"200,600,8,100,0,7,0,1,1,host.example.com,,1\n";
"200,600,8,100,0,7,0,1,1,host.example.com,,1,\n";
// Subtest 1: bot previous and copy available
// Create the test previous file
......
......@@ -110,6 +110,30 @@ Lease4Parser::parse(ConstSrvConfigPtr& cfg,
"values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
}
// Handle user context.
ConstElementPtr ctx = lease_info->get("user-context");
if (ctx && (ctx->getType() != Element::map)) {
isc_throw(BadValue, "Invalid user context '" << ctx->str()
<< "' is not a JSON map.");
}
// Handle comment.
ConstElementPtr comment = lease_info->get("comment");
if (comment) {
if (ctx && ctx->contains("comment")) {
isc_throw(BadValue, "Duplicated comment entry '" << comment->str()
<< "' in user context '" << ctx->str() << "'");
}
ElementPtr copied;
if (ctx) {
copied = copy(ctx, 0);
} else {
copied = Element::createMap();
}
copied->set("comment", comment);
ctx = copied;
}
// Let's fabricate some data and we're ready to go.
uint32_t t1 = subnet->getT1();
uint32_t t2 = subnet->getT2();
......@@ -118,6 +142,7 @@ Lease4Parser::parse(ConstSrvConfigPtr& cfg,
cltt, subnet_id,
fqdn_fwd, fqdn_rev, hostname));
l->state_ = state;
l->setContext(ctx);
// Retrieve the optional flag indicating if the lease must be created when it
// doesn't exist during the update.
......@@ -251,6 +276,30 @@ Lease6Parser::parse(ConstSrvConfigPtr& cfg,
"values are: 0 (default), 1 (declined) and 2 (expired-reclaimed)");
}
// Handle user context.
ConstElementPtr ctx = lease_info->get("user-context");
if (ctx && (ctx->getType() != Element::map)) {
isc_throw(BadValue, "Invalid user context '" << ctx->str()
<< "' is not a JSON map.");
}
// Handle comment.
ConstElementPtr comment = lease_info->get("comment");
if (comment) {
if (ctx && ctx->contains("comment")) {
isc_throw(BadValue, "Duplicated comment entry '" << comment->str()
<< "' in user context '" << ctx->str() << "'");
}
ElementPtr copied;
if (ctx) {
copied = copy(ctx, 0);
} else {
copied = Element::createMap();
}
copied->set("comment", comment);
ctx = copied;
}
// Let's fabricate some data and we're ready to go.
uint32_t t1 = subnet->getT1();
uint32_t t2 = subnet->getT2();
......@@ -260,6 +309,7 @@ Lease6Parser::parse(ConstSrvConfigPtr& cfg,
hwaddr_ptr, prefix_len));
l->cltt_ = cltt;
l->state_ = state;
l->setContext(ctx);
// Retrieve the optional flag indicating if the lease must be created when it
// doesn't exist during the update.
......
......@@ -29,7 +29,8 @@ namespace lease_cmds {
/// "fqdn-fwd": true,
/// "fqdn-rev": true,
/// "hostname": "myhost.example.org",
/// "state": 0
/// "state": 0,