2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[3884] Addressed review comments

Minor cleanup. Lease dump tests for both MySQL and PostgreSQL
now use multiple timestamps values.
This commit is contained in:
Thomas Markwalder
2015-06-15 11:23:37 -04:00
parent bdac8446d6
commit d6ec7d8068
8 changed files with 101 additions and 56 deletions

View File

@@ -366,12 +366,14 @@ $
<listitem> <listitem>
<para> <para>
Create the database tables using the new user's At this point you are ready to create the database tables.
credentials and the dhcpdb_create.pgsql script supplied This can be done using the <command>kea-admin</command> tool
with Kea. After entering the following command, you as explained in the next section (recommended), or manually.
will be prompted for the new user's password. When the To create the tables manually enter the following command.
command completes you will be returned to the shell Note that PostgreSQL will prompt you to enter the new user's
prompt. You should see output similar to following: password you specified in Step 3. When the command completes
you will be returned to the shell prompt. You should see output
similar to following:
<screen> <screen>
$ <userinput>psql -d <replaceable>database-name</replaceable> -U <replaceable>user-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/scripts/pgsql/dhcpdb_create.pgsql</userinput> $ <userinput>psql -d <replaceable>database-name</replaceable> -U <replaceable>user-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/scripts/pgsql/dhcpdb_create.pgsql</userinput>
Password for user <replaceable>user-name</replaceable>: Password for user <replaceable>user-name</replaceable>:
@@ -434,12 +436,28 @@ host <replaceable>database-name</replaceable> <replaceable>user-name</repl
<section> <section>
<title>Initialize the PostgreSQL Database Using kea-admin</title> <title>Initialize the PostgreSQL Database Using kea-admin</title>
<para> <para>
Support for PostgreSQL in <command>kea-admin</command> is If you elected not to create the tables manually, you can do
currently not implemented. so now by running the <command>kea-admin</command> tool:
<screen>
$ <userinput>kea-admin lease-init pgsql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
</screen>
Do not do this if you already created the tables in manually.
<command>kea-admin</command> implements rudimentary checks:
it will refuse to initialize a database that contains any
existing tables. If you want to start from scratch, you
must remove all data manually. (This process is a manual
operation on purpose to avoid possibly irretrievable mistakes
by <command>kea-admin</command>.)
</para>
</section>
<section id="pgsql-upgrade">
<title>Upgrading a PostgreSQL Database from an Earlier Version of Kea</title>
<para>
Currently, PostgreSQL only supports Kea schema version 1.0 so no upgrades
are available. As upgrades become available, <command>kea-admin</command>
will support them.
</para> </para>
<!-- @todo: document PgSQL upgrade once they are implemented in kea-admin -->
</section> </section>
</section> <!-- end of PostgreSQL sections --> </section> <!-- end of PostgreSQL sections -->
<section> <section>

View File

@@ -24,13 +24,13 @@
# #
# It returns the mysql command exit status to the caller as $? # It returns the mysql command exit status to the caller as $?
mysql_execute() { mysql_execute() {
QUERY=$1
shift
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
QUERY="$1"
shift
mysql -N -B $* -e "${QUERY}" mysql -N -B $* -e "${QUERY}"
retcode=$? retcode=$?
else else
mysql -N -B --user=$db_user --password=$db_password -e "${1}" $db_name mysql -N -B --user=$db_user --password=$db_password -e "${QUERY}" $db_name
retcode="$?" retcode="$?"
fi fi
@@ -90,7 +90,6 @@ pgsql_execute_script() {
return $retcode return $retcode
} }
pgsql_version() { pgsql_version() {
pgsql_execute "SELECT version || '.' || minor FROM schema_version" "$@" pgsql_execute "SELECT version || '.' || minor FROM schema_version" "$@"
return $? return $?

View File

@@ -1,4 +1,4 @@
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
0.0.0.10,3230,3330,40,0000-00-00 00:00:00,50,1,1,one.example.com 0.0.0.10,3230,3330,40,2015-01-01 01:15:30,50,1,1,one.example.com
0.0.0.11,,313233,40,0000-00-00 00:00:00,50,1,1, 0.0.0.11,,313233,40,2015-02-02 02:30:45,50,1,1,
0.0.0.12,3232,,40,0000-00-00 00:00:00,50,1,1,three.example.com 0.0.0.12,3232,,40,2015-03-03 11:01:07,50,1,1,three.example.com
1 address hwaddr client_id valid_lifetime expire subnet_id fqdn_fwd fqdn_rev hostname
2 0.0.0.10 3230 3330 40 0000-00-00 00:00:00 2015-01-01 01:15:30 50 1 1 one.example.com
3 0.0.0.11 313233 40 0000-00-00 00:00:00 2015-02-02 02:30:45 50 1 1
4 0.0.0.12 3232 40 0000-00-00 00:00:00 2015-03-03 11:01:07 50 1 1 three.example.com

View File

@@ -1,4 +1,4 @@
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source
10,3230,30,0000-00-00 00:00:00,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,100 10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,100
11,,30,0000-00-00 00:00:00,40,50,IA_TA,60,70,1,1,,3830,90,100 11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,100
12,3231,30,0000-00-00 00:00:00,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,100 12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,100
1 address duid valid_lifetime expire subnet_id pref_lifetime lease_type iaid prefix_len fqdn_fwd fqdn_rev hostname hwaddr hwtype hwaddr_source
2 10 3230 30 0000-00-00 00:00:00 2015-04-04 01:15:30 40 50 IA_TA 60 70 1 1 one.example.com 3830 90 100
3 11 30 0000-00-00 00:00:00 2015-05-05 02:30:45 40 50 IA_TA 60 70 1 1 3830 90 100
4 12 3231 30 0000-00-00 00:00:00 2015-06-06 11:01:07 40 50 IA_TA 60 70 1 1 three.example.com 3830 90 100

View File

@@ -1,4 +1,4 @@
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
0.0.0.10,20,30,40,<timestamp>,50,1,1,one.example.com 0.0.0.10,20,30,40,<timestamp1>,50,1,1,one.example.com
0.0.0.11,,013233,40,<timestamp>,50,1,1, 0.0.0.11,,013233,40,<timestamp2>,50,1,1,
0.0.0.12,22,,40,<timestamp>,50,1,1,three.example.com 0.0.0.12,22,,40,<timestamp3>,50,1,1,three.example.com
1 address hwaddr client_id valid_lifetime expire subnet_id fqdn_fwd fqdn_rev hostname
2 0.0.0.10 20 30 40 <timestamp> <timestamp1> 50 1 1 one.example.com
3 0.0.0.11 013233 40 <timestamp> <timestamp2> 50 1 1
4 0.0.0.12 22 40 <timestamp> <timestamp3> 50 1 1 three.example.com

View File

@@ -1,4 +1,4 @@
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname
12,21,30,<timestamp>,40,50,IA_TA,60,70,t,t,three.example.com 12,21,30,<timestamp3>,40,50,IA_TA,60,70,t,t,three.example.com
11,,30,<timestamp>,40,50,IA_TA,60,70,t,t, 11,,30,<timestamp2>,40,50,IA_TA,60,70,t,t,
10,20,30,<timestamp>,40,50,IA_TA,60,70,t,t,one.example.com 10,20,30,<timestamp1>,40,50,IA_TA,60,70,t,t,one.example.com
1 address duid valid_lifetime expire subnet_id pref_lifetime lease_type iaid prefix_len fqdn_fwd fqdn_rev hostname
2 12 21 30 <timestamp> <timestamp3> 40 50 IA_TA 60 70 t t three.example.com
3 11 30 <timestamp> <timestamp2> 40 50 IA_TA 60 70 t t
4 10 20 30 <timestamp> <timestamp1> 40 50 IA_TA 60 70 t t one.example.com

View File

@@ -299,9 +299,9 @@ mysql_lease4_dump_test() {
# Insert the reference record # Insert the reference record
insert_sql="\ insert_sql="\
insert into lease4 values(10,20,30,40,0,50,1,1,\"one.example.com\");\ insert into lease4 values(10,20,30,40,\"2015-01-01 01:15:30\",50,1,1,\"one.example.com\");\
insert into lease4 values(11,NULL,123,40,0,50,1,1,\"\");\ insert into lease4 values(11,NULL,123,40,\"2015-02-02 02:30:45\",50,1,1,\"\");\
insert into lease4 values(12,22,NULL,40,0,50,1,1,\"three.example.com\");" insert into lease4 values(12,22,NULL,40,\"2015-03-03 11:01:07\",50,1,1,\"three.example.com\");"
mysql_execute "$insert_sql" mysql_execute "$insert_sql"
ERRCODE=$? ERRCODE=$?
@@ -356,13 +356,13 @@ mysql_lease6_dump_test() {
# Insert the reference record # Insert the reference record
insert_sql="\ insert_sql="\
insert into lease6 values(10,20,30,0,40,50,1,60,70,1,1,\"one.example.com\",80,90,100);\ 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,100);\
insert into lease6 values(11,NULL,30,0,40,50,1,60,70,1,1,\"\",80,90,100);\ insert into lease6 values(11,NULL,30,\"2015-05-05 02:30:45\",40,50,1,60,70,1,1,\"\",80,90,100);\
insert into lease6 values(12,21,30,0,40,50,1,60,70,1,1,\"three.example.com\",80,90,100);" 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,100);"
mysql_execute "$insert_sql" mysql_execute "$insert_sql"
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "insert into lease6 failed, expected exit code %, actual %d" assert_eq 0 $ERRCODE "insert into lease6 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file # Dump lease4 to output_file
${keaadmin} lease-dump mysql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file ${keaadmin} lease-dump mysql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
@@ -372,7 +372,7 @@ insert into lease6 values(12,21,30,0,40,50,1,60,70,1,1,\"three.example.com\",80,
# Compare the dump output to reference file, they should be identical # Compare the dump output to reference file, they should be identical
cmp -s $output_file $ref_file cmp -s $output_file $ref_file
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "dump file does not match reference file, expected exit code %, actual %d" assert_eq 0 $ERRCODE "dump file does not match reference file, expected exit code %d, actual %d"
# remove the output file # remove the output file
rm $output_file rm $output_file

View File

@@ -131,6 +131,20 @@ pgsql_upgrade_test() {
test_finish 0 test_finish 0
} }
# Given a valid timestamp string, returns a timestamp with timezone string
# for the give time localized by the PostgreSQL server.
get_local_time() {
timestamp="$1"
# Expiration field is a "timestamp with timezone" so we need a reference
# time for the machine/DB this test is running upon.
ref_timestamp=`pgsql_execute "SELECT timestamptz '$1';"`
ERRCODE=$?
assert_eq 0 $ERRCODE "reference time query failed for [$timestamp], expected exit code %d, actual %d"
echo $ref_timestamp
}
# Test verifies the ability to dump lease4 data to CSV file # Test verifies the ability to dump lease4 data to CSV file
# The dump output file is compared against a reference file. # The dump output file is compared against a reference file.
# If the dump is successful, the file contents will be the # If the dump is successful, the file contents will be the
@@ -172,11 +186,15 @@ pgsql_lease4_dump_test() {
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d" assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
timestamp1="2015-01-01 01:15:30"
timestamp2="2015-02-02 02:30:45"
timestamp3="2015-03-03 11:01:07"
# Insert the reference records # Insert the reference records
insert_sql="\ insert_sql="\
insert into lease4 values(10,E'\\x20',E'\\x30',40,'2001-01-01 00:00:00',50,'t','t','one.example.com');\ insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one.example.com');\
insert into lease4 values(11,'',E'\\x0123',40,'2001-01-01 00:00:00',50,'t','t','');\ insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','');\
insert into lease4 values(12,E'\\x22','',40,'2001-01-01 00:00:00',50,'t','t','three.example.com');" insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com');"
pgsql_execute "$insert_sql" pgsql_execute "$insert_sql"
ERRCODE=$? ERRCODE=$?
@@ -187,17 +205,20 @@ insert into lease4 values(12,E'\\x22','',40,'2001-01-01 00:00:00',50,'t','t','th
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, status code %d" assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, status code %d"
# Expiration field is a "timestamp with timezone" so we need a reference # Expiration field is a "timestamp with timezone" so we need a localized reference
# time for the machine/DB this test is running upon. # times for the machine/DB this test is running upon.
ref_timestamp=`pgsql_execute "SELECT timestamptz '2001-01-01 00:00:00';"` local_timestamp1=`get_local_time "$timestamp1"`
ERRCODE=$? local_timestamp2=`get_local_time "$timestamp2"`
assert_eq 0 $ERRCODE "reference time query failed, expected exit code %d, actual %d" local_timestamp3=`get_local_time "$timestamp3"`
printf "reference timestamp is [$ref_timestamp]\n"
# Create the comparison file by replacing the <timestamp> tags # Create the comparison file by replacing the <timestamp> tags
# with the local reference timestamp # with the local reference timestamp
sedstr="'s/<timestamp>/$ref_timestamp/g'" sedstr="\
eval sed $sedstr $ref_file >$ref_file_tmp sed 's/<timestamp1>/$local_timestamp1/g' $ref_file | \
sed 's/<timestamp2>/$local_timestamp2/g' | \
sed 's/<timestamp3>/$local_timestamp3/g' "
eval $sedstr >$ref_file_tmp
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d" assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d"
@@ -257,11 +278,15 @@ pgsql_lease6_dump_test() {
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, status code %d" assert_eq 0 $ERRCODE "could not create database, status code %d"
timestamp1="2015-04-04 01:15:30"
timestamp2="2015-02-02 02:30:45"
timestamp3="2015-06-06 11:01:07"
# Insert the reference records # Insert the reference records
insert_sql="\ insert_sql="\
insert into lease6 values(10,E'\\x20',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','one.example.com');\ insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','one.example.com');\
insert into lease6 values(11,'',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','');\ insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','');\
insert into lease6 values(12,E'\\x21',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','three.example.com');" insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com');"
pgsql_execute "$insert_sql" pgsql_execute "$insert_sql"
ERRCODE=$? ERRCODE=$?
@@ -272,17 +297,20 @@ insert into lease6 values(12,E'\\x21',30,'2001-01-01 00:00:00',40,50,1,60,70,'t'
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d" assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d"
# Expiration field is a "timestamp with timezone" so we need a reference # Expiration field is a "timestamp with timezone" so we need a localized reference
# time for the machine/DB this test is running upon. # times for the machine/DB this test is running upon.
ref_timestamp=`pgsql_execute "SELECT timestamptz '2001-01-01 00:00:00';"` local_timestamp1=`get_local_time "$timestamp1"`
ERRCODE=$? local_timestamp2=`get_local_time "$timestamp2"`
assert_eq 0 $ERRCODE "reference time query failed, expected exit code %d, actual %d" local_timestamp3=`get_local_time "$timestamp3"`
printf "reference timestamp is [$ref_timestamp]\n"
# Create the comparison file by replacing the <timestamp> tags # Create the comparison file by replacing the <timestamp> tags
# with the local reference timestamp # with the local reference timestamp
sedstr="'s/<timestamp>/$ref_timestamp/g'" sedstr="\
eval sed $sedstr $ref_file >$ref_file_tmp sed 's/<timestamp1>/$local_timestamp1/g' $ref_file | \
sed 's/<timestamp2>/$local_timestamp2/g' | \
sed 's/<timestamp3>/$local_timestamp3/g' "
eval $sedstr >$ref_file_tmp
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d" assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d"