Commit b912c5a0 authored by Razvan Becheriu's avatar Razvan Becheriu
Browse files

implemented getPage4 and getPage6 for Cassandra, sorting and filtering hosts...

implemented getPage4 and getPage6 for Cassandra, sorting and filtering hosts in unittests, implemented migration script for schema 4.0
parent 20bd7a1c
......@@ -1690,6 +1690,7 @@ AC_CONFIG_FILES([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/cql/upgrade_3.0_to_4.0.sh
src/share/database/scripts/cql/wipe_data.sh
src/share/database/scripts/mysql/Makefile
src/share/database/scripts/mysql/upgrade_1.0_to_2.0.sh
......
......@@ -85,7 +85,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 "3.0" $version "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "4.0" $version "Expected kea-admin to return %s, returned value was %s"
# Wipe the database.
cql_wipe
......@@ -150,17 +150,15 @@ cql_lease4_dump_test() {
# 1433464245 corresponds to 2015-05-05 02:30:45
# 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, user_context)\
VALUES(-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,\
'one.example.com', 0, '');\
INSERT INTO lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
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, user_context)\
VALUES(-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,\
'three.example.com', 2, '');"
INSERT INTO lease4 (address, hwaddr, client_id, valid_lifetime, expire, subnet_id, \
fqdn_fwd, fqdn_rev, hostname, state, user_context) \
VALUES (-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,'one.example.com', 0, '');\
INSERT INTO lease4 (address, hwaddr, client_id, valid_lifetime, expire, subnet_id, \
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, user_context) \
VALUES (-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,'three.example.com', 2, '');"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease4 failed, expected exit code %d, actual %d"
......@@ -217,21 +215,21 @@ cql_lease6_dump_test() {
# 1433464245 corresponds to 2015-05-05 02:30:45
# 1436173267 corresponds to 2015-06-06 11:01:07
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, 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,'');\
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, user_context)\
VALUES('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true,\
'',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, 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,'');"
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, 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,'');\
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, user_context) \
VALUES ('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true, \
'',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, 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,'');"
cql_execute "$insert_cql"
assert_eq 0 $? "insert into lease6 failed, expected exit code %d, actual %d"
......@@ -260,7 +258,7 @@ cql_upgrade_schema_to_version() {
# Check if the scripts directory exists at all.
if [ ! -d ${db_scripts_dir}/cql ]; then
log_error "Invalid scripts directory: ${db_scripts_dir}/mysql"
log_error "Invalid scripts directory: ${db_scripts_dir}/cql"
exit 1
fi
......@@ -306,17 +304,17 @@ cql_unused_subnet_id_test() {
cql_upgrade_schema_to_version 2.0
# Now we need insert some hosts to "migrate" for both v4 and v6
qry=\
"insert into host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
values (1, 0, textAsBlob('0123456'), 0, 0, 0);\
insert into host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
values (2, 0, textAsBlob('1123456'), 4, 0, 4);\
insert into host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
values (3, 0, textAsBlob('2123456'), 0, 6, 6);\
insert into host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
values (4, 0, textAsBlob('3123456'), 4, 6, 0);\
insert into host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
values (5, 0, textAsBlob('3123456'), -1, 6, 6);"
qry="\
INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id) \
VALUES (1, 0, textAsBlob('0123456'), 0, 0, 0);\
INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id) \
VALUES (2, 0, textAsBlob('1123456'), 4, 0, 4);\
INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id) \
VALUES (3, 0, textAsBlob('2123456'), 0, 6, 6);\
INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id) \
VALUES (4, 0, textAsBlob('3123456'), 4, 6, 0);\
INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id) \
VALUES (5, 0, textAsBlob('3123456'), -1, 6, 6);"
cql_execute "$qry"
assert_eq 0 $? "insert hosts failed, expected exit code: %d, actual: %d"
......@@ -337,14 +335,14 @@ cql_unused_subnet_id_test() {
# Fetch host_reservation data for comparison
echo "Exporting host_reservation data to $export_file ..."
qry=\
"select id, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id from\
host_reservations where id in(1,2,3,4,5);"
qry="\
SELECT id, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id\
FROM hosts WHERE id IN (1,2,3,4,5) ALLOW FILTERING;"
cql_execute "$qry" >$export_file
cql_execute "$qry" > $export_file
assert_eq 0 $? "insert hosts failed, expected exit code: %d, actual: %d"
# Compare the dump output to reference file, they should be identical.
cmp -s $export_file $ref_file
cmp -s $export_file $ref_file
assert_eq 0 $? "export file does not match reference file, expected exit code %d, actual %d"
# remove the output file.
......@@ -357,6 +355,98 @@ cql_unused_subnet_id_test() {
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that all hosts and options from old host_reseravation table (version 3.0) are
# converted to new schema (version 4.0) with new key partition key and are
# moved to new hosts table
cql_upgrade_hosts_test() {
test_start "cql.update_hosts_test"
# Let's wipe the whole database
cql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which convert subnet id values
#
# Initialize database to schema 1.0.
cql_execute_script @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.cql
# Now upgrade to schema 3.0, the version just before global HRs
cql_upgrade_schema_to_version 3.0
# Now we need insert some hosts to "migrate" for both v4 and v6
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
data_file="$test_dir/data/cql.hosts_data_test.csv"
ref_file="$test_dir/data/cql.hosts_data_test.reference.csv"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
export_file="$output_dir/data/cql.hosts_test.csv"
sorted_file="$output_dir/data/cql.hosts_test.sorted.csv"
# Fetch host_reservation data for comparison
echo "Exporting host_reservation data to $export_file ..."
qry="\
COPY host_reservations \
(id, host_identifier, host_identifier_type, host_ipv4_subnet_id, \
host_ipv6_subnet_id, host_ipv4_address, host_ipv4_next_server, \
host_ipv4_server_hostname, host_ipv4_boot_file_name, hostname, \
auth_key, user_context, host_ipv4_client_classes, \
host_ipv6_client_classes, reserved_ipv6_prefix_address, \
reserved_ipv6_prefix_length, reserved_ipv6_prefix_address_type, \
iaid, option_universe, option_code, option_value, \
option_formatted_value, option_space, option_is_persistent, \
option_client_class, option_subnet_id, option_user_context, \
option_scope_id) \
FROM '$data_file'"
cql_execute "$qry"
assert_eq 0 $? "insert hosts failed, expected exit code: %d, actual: %d"
# Ok, we have a 3.0 database with hosts and options. Let's upgrade it.
${keaadmin} lease-upgrade cql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
# Upgrade should succeed
assert_eq 0 $ERRCODE "upgrade failed"
qry="\
COPY hosts \
(id, key, host_identifier, host_identifier_type, host_ipv4_subnet_id, \
host_ipv6_subnet_id, host_ipv4_address, host_ipv4_next_server, \
host_ipv4_server_hostname, host_ipv4_boot_file_name, hostname, \
auth_key, user_context, host_ipv4_client_classes, \
host_ipv6_client_classes, reserved_ipv6_prefix_address, \
reserved_ipv6_prefix_length, reserved_ipv6_prefix_address_type, \
iaid, option_universe, option_code, option_value, \
option_formatted_value, option_space, option_is_persistent, \
option_client_class, option_subnet_id, option_user_context, \
option_scope_id) \
TO '$export_file'"
cql_execute "$qry"
assert_eq 0 $? "insert hosts failed, expected exit code: %d, actual: %d"
# sort data so we can compare
cat $export_file | sort -V > $sorted_file
# Compare the dump output to reference file, they should be identical.
cmp -s $sorted_file $ref_file
assert_eq 0 $? "export file does not match reference file, expected exit code %d, actual %d"
# remove the output file.
rm $export_file
# remove the sorted file.
rm $sorted_file
# Wipe the database.
cql_wipe
# Report test success.
test_finish 0
}
# Run tests.
cql_lease_init_test
......@@ -365,3 +455,4 @@ cql_upgrade_test
cql_lease4_dump_test
cql_lease6_dump_test
cql_unused_subnet_id_test
cql_upgrade_hosts_test
1105657659805715115,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3
2129388898029710264,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3
2370585748436022247,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3
2459636980433777721,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,{ \"comment\": \"a host reservation\" },3
5403514763123047131,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,254,0x,192.0.2.3,dhcp4,False,,0,,3
5501234819855171334,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3
5747907930644082856,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3
5955003068494074400,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,,3
6399013866147252670,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3
6783601303445960591,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3
7821756928114620236,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,23,0x,64,dhcp4,False,,0,,3
8973539074684426388,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,,isc,True,,0,,3
9211831388923168274,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,2,0x,"10.0.0.5,10.0.0.3,10.0.3.4",isc,False,,0,,3
-650687214220680074,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,1024,0x,2001:db8:1::1,dhcp6,False,,0,,3
-1123502337428230752,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,254,0x,192.0.2.3,dhcp4,False,,0,,3
-1210691761766369036,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,67,0x,my-boot-file,dhcp4,True,,0,{ \"comment\": \"a host reservation\" },3
-3907456719587717375,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,2,0x,"10.0.0.5,10.0.0.3,10.0.3.4",isc,False,,0,,3
-5169419091664697091,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,2,0x,"3000::1,3000::2,3000::3",isc2,False,,0,,3
-6372549629773775261,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3
-6378104957663278797,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,,isc,True,,0,,3
-7724068518921719729,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,1024,0x,2001:db8:1::1,dhcp6,False,,0,,3
-7804940982500935489,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,23,0x,64,dhcp4,False,,0,,3
-8100784457292204371,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3
-8306770918748488616,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,2,0x,"3000::1,3000::2,3000::3",isc2,False,,0,,3
1105657659805715115,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3
2129388898029710264,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3
2370585748436022247,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3
2459636980433777721,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,{ \"comment\": \"a host reservation\" },3
5403514763123047131,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,254,0x,192.0.2.3,dhcp4,False,,0,,3
5501234819855171334,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3
5747907930644082856,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3
5955003068494074400,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,,3
6399013866147252670,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3
6783601303445960591,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3
7821756928114620236,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,23,0x,64,dhcp4,False,,0,,3
8973539074684426388,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,,isc,True,,0,,3
9211831388923168274,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,2,0x,"10.0.0.5,10.0.0.3,10.0.3.4",isc,False,,0,,3
-650687214220680074,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,1024,0x,2001:db8:1::1,dhcp6,False,,0,,3
-1123502337428230752,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,254,0x,192.0.2.3,dhcp4,False,,0,,3
-1210691761766369036,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,67,0x,my-boot-file,dhcp4,True,,0,{ \"comment\": \"a host reservation\" },3
-3907456719587717375,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,2,0x,"10.0.0.5,10.0.0.3,10.0.3.4",isc,False,,0,,3
-5169419091664697091,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,2,0x,"3000::1,3000::2,3000::3",isc2,False,,0,,3
-6372549629773775261,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3
-6378104957663278797,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,,isc,True,,0,,3
-7724068518921719729,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,1024,0x,2001:db8:1::1,dhcp6,False,,0,,3
-7804940982500935489,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,23,0x,64,dhcp4,False,,0,,3
-8100784457292204371,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3
-8306770918748488616,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,2,0x,"3000::1,3000::2,3000::3",isc2,False,,0,,3
id | host_ipv4_subnet_id | host_ipv6_subnet_id | option_subnet_id
----+---------------------+---------------------+------------------
1 | -1 | -1 | -1
2 | 4 | -1 | 4
3 | -1 | 6 | 6
4 | 4 | 6 | -1
3 | -1 | 6 | 6
5 | -1 | 6 | 6
1 | -1 | -1 | -1
(5 rows)
......@@ -49,9 +49,9 @@ constexpr uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR;
constexpr uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR;
/// @}
/// Define CQL schema version: 3.0
/// Define CQL schema version: 4.0
/// @{
constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR = 3u;
constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR = 4u;
constexpr uint32_t CQL_SCHEMA_VERSION_MINOR = 0u;
/// @}
......
This diff is collapsed.
......@@ -2679,7 +2679,6 @@ TEST_F(AllocEngine4Test, globalReservationReservedAddressRequest) {
EXPECT_FALSE(ctx.old_lease_);
}
// This test checks the behavior of the allocation engine in the following
// scenario:
// - Client has no lease in the database.
......
......@@ -44,7 +44,7 @@ namespace test {
bool testStatistics(const std::string& stat_name, const int64_t exp_value,
const SubnetID subnet_id) {
try {
std::string name = (subnet_id == SUBNET_ID_UNUSED ? stat_name :
std::string name = (subnet_id == SUBNET_ID_UNUSED ? stat_name :
StatsMgr::generateName("subnet", subnet_id, stat_name));
ObservationPtr observation = StatsMgr::instance().getObservation(name);
if (observation) {
......
......@@ -178,7 +178,7 @@ public:
EXPECT_EQ(lease->subnet_id_, subnet_->getID());
if (expected_in_subnet) {
EXPECT_TRUE(subnet_->inRange(lease->addr_))
EXPECT_TRUE(subnet_->inRange(lease->addr_))
<< " address: " << lease->addr_.toText();
} else {
EXPECT_FALSE(subnet_->inRange(lease->addr_))
......
......@@ -483,7 +483,7 @@ TEST_F(CfgIfaceTest, unparse) {
EXPECT_NO_THROW(cfg4.use(AF_INET, "eth1/192.0.2.3"));
std::string comment = "{ \"comment\": \"foo\", \"bar\": 1 }";
EXPECT_NO_THROW(cfg4.setContext(Element::fromJSON(comment)));
// Check unparse
std::string expected =
"{ \"comment\": \"foo\", "
......
......@@ -18,17 +18,17 @@
#include <config.h>
#include <asiolink/io_address.h>
#include <dhcpsrv/tests/test_utils.h>
#include <exceptions/exceptions.h>
#include <cql/cql_connection.h>
#include <cql/testutils/cql_schema.h>
#include <dhcpsrv/host.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/cql_lease_mgr.h>
#include <dhcpsrv/cql_host_data_source.h>
#include <dhcpsrv/testutils/generic_host_data_source_unittest.h>
#include <dhcpsrv/testutils/host_data_source_utils.h>
#include <dhcpsrv/tests/test_utils.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <cql/cql_connection.h>
#include <cql/cql_exchange.h>
#include <cql/testutils/cql_schema.h>
#include <gtest/gtest.h>
......@@ -209,7 +209,7 @@ TEST(CqlHostDataSource, OpenDatabase) {
// CQL specifies the timeout values in ms, not seconds. Therefore
// we need to add extra 000 to the "connect-timeout=10" string.
string connection_string = validCqlConnectionString() + string(" ") +
string(VALID_TIMEOUT) + string("000");
string(VALID_TIMEOUT) + string("000");
HostMgr::create();
EXPECT_NO_THROW(HostMgr::addBackend(connection_string));
HostMgr::delBackend("cql");
......@@ -292,6 +292,36 @@ TEST_F(CqlHostDataSourceTest, DISABLED_testReadOnlyDatabase) {
testReadOnlyDatabase(CQL_VALID_TYPE);
}
// Test verifies if a host reservation can be added and later retrieved by IPv4
// address. Host uses hw address as identifier.
TEST_F(CqlHostDataSourceTest, basic4HWAddr) {
testBasic4(Host::IDENT_HWADDR);
}
// Verifies that IPv4 host reservation with options can have a the global
// subnet id value
TEST_F(CqlHostDataSourceTest, globalSubnetId4) {
testGlobalSubnetId4();
}
// Verifies that IPv6 host reservation with options can have a the global
// subnet id value
TEST_F(CqlHostDataSourceTest, globalSubnetId6) {
testGlobalSubnetId6();
}
// Verifies that IPv4 host reservation with options can have a max value
// for dhcp4_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId4) {
testMaxSubnetId4();
}
// Verifies that IPv6 host reservation with options can have a max value
// for dhcp6_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId6) {
testMaxSubnetId6();
}
// Verifies that IPv4 host reservations in the same subnet can be retrieved
TEST_F(CqlHostDataSourceTest, getAll4BySubnet) {
testGetAll4();
......@@ -304,21 +334,38 @@ TEST_F(CqlHostDataSourceTest, getAll6BySubnet) {
// Verifies that IPv4 host reservations in the same subnet can be retrieved
// by pages.
// Does not work because TOKEN(id) order is not the same than id...
TEST_F(CqlHostDataSourceTest, DISABLED_getPage4) {
TEST_F(CqlHostDataSourceTest, getPage4) {
testGetPage4();
}
// Verifies that IPv6 host reservations in the same subnet can be retrieved
// by pages.
TEST_F(CqlHostDataSourceTest, DISABLED_getPage6) {
TEST_F(CqlHostDataSourceTest, getPage6) {
testGetPage6();
}
// Test verifies if a host reservation can be added and later retrieved by IPv4
// address. Host uses hw address as identifier.
TEST_F(CqlHostDataSourceTest, basic4HWAddr) {
testBasic4(Host::IDENT_HWADDR);
// Verifies that IPv4 host reservations in the same subnet can be retrieved
// by pages without truncation from the limit.
TEST_F(CqlHostDataSourceTest, getPageLimit4) {
testGetPageLimit4(Host::IDENT_DUID);
}
// Verifies that IPv6 host reservations in the same subnet can be retrieved
// by pages without truncation from the limit.
TEST_F(CqlHostDataSourceTest, getPageLimit6) {
testGetPageLimit6(Host::IDENT_HWADDR);
}
// Verifies that IPv4 host reservations in the same subnet can be retrieved
// by pages even with multiple subnets.
TEST_F(CqlHostDataSourceTest, getPage4Subnets) {
testGetPage4Subnets();
}
// Verifies that IPv6 host reservations in the same subnet can be retrieved
// by pages even with multiple subnets.
TEST_F(CqlHostDataSourceTest, getPage6Subnets) {
testGetPage6Subnets();
}
// Test verifies if a host reservation can be added and later retrieved by IPv4
......@@ -602,15 +649,15 @@ TEST_F(CqlHostDataSourceTest, testAddRollback) {
params["name"] = "keatest";
params["user"] = "keatest";
params["password"] = "keatest";
CqlConnection connection(params);
ASSERT_NO_THROW(connection.openDatabase());
CqlConnection conn(params);
ASSERT_NO_THROW(conn.openDatabase());
// Drop every table so we make sure host_reservations doesn't exist anymore.
// Drop every table so we make sure hosts doesn't exist anymore.
destroyCqlSchema(false, true);
// Create a host with a reservation.
HostPtr host = HostDataSourceUtils::initializeHost6("2001:db8:1::1",
Host::IDENT_HWADDR, false, "key##1");
Host::IDENT_HWADDR, false, "randomKey");
// Let's assign some DHCPv4 subnet to the host, because we will use the
// DHCPv4 subnet to try to retrieve the host after failed insertion.
host->setIPv4SubnetID(SubnetID(4));
......@@ -687,30 +734,4 @@ TEST_F(CqlHostDataSourceTest, testMultipleHosts6) {
testMultipleHosts6();
}
// Verifies that IPv4 host reservation with options can have a the global
// subnet id value
TEST_F(CqlHostDataSourceTest, globalSubnetId4) {
testGlobalSubnetId4();
}
// Verifies that IPv6 host reservation with options can have a the global
// subnet id value
TEST_F(CqlHostDataSourceTest, globalSubnetId6) {
testGlobalSubnetId6();
}
// Verifies that IPv4 host reservation with options can have a max value
// for dhcp4_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId4) {
testMaxSubnetId4();
}
// Verifies that IPv6 host reservation with options can have a max value
// for dhcp6_subnet id
TEST_F(CqlHostDataSourceTest, maxSubnetId6) {
testMaxSubnetId6();
}
} // namespace
......@@ -223,7 +223,7 @@ public:
}
// This is the CQL implementation for
// GenericLeaseMgrTest::testGetExpiredLeases4().
// GenericLeaseMgrTest::testGetExpiredLeases6().
// The GenericLeaseMgrTest implementation checks for the order of expired
// leases to be from the most expired to the least expired. Cassandra
// doesn't support ORDER BY without imposing a EQ / IN restriction on the
......@@ -285,8 +285,7 @@ public:
}
// Retrieve expired leases again. The limit of 0 means return all
// expired
// leases.
// expired leases.
ASSERT_NO_THROW(lmptr_->getExpiredLeases6(expired_leases, 0));
// The same leases should be returned.
......@@ -685,7 +684,7 @@ TEST_F(CqlLeaseMgrTest, lease6LeaseTypeCheck) {
/// Adds 3 lease and verifies fetch by DUID.
/// Verifies retrival of non existant DUID fails
TEST_F(CqlLeaseMgrTest, getLeases6Duid) {
testGetLeases6Duid();
testGetLeases6Duid();
}
/// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
......@@ -736,12 +735,12 @@ TEST_F(CqlLeaseMgrTest, nullDuid) {
testNullDuid();
}
/// @brief Tests whether memfile can store and retrieve hardware addresses
/// @brief Tests whether CQL can store and retrieve hardware addresses
TEST_F(CqlLeaseMgrTest, testLease6Mac) {
testLease6MAC();
}
/// @brief Tests whether memfile can store and retrieve hardware addresses
/// @brief Tests whether CQL can store and retrieve hardware addresses
TEST_F(CqlLeaseMgrTest, testLease6HWTypeAndSource) {
testLease6HWTypeAndSource();
}
......@@ -772,14 +771,14 @@ TEST_F(CqlLeaseMgrTest, recountLeaseStats6) {
testRecountLeaseStats6();
}
// @brief Tests that leases from specific subnet can be removed.
/// @brief Tests that leases from specific subnet can be removed.
/// @todo: uncomment this once lease wipe is implemented
/// for Cassandra (see #5485)
TEST_F(CqlLeaseMgrTest, DISABLED_wipeLeases4) {
testWipeLeases4();
}
// @brief Tests that leases from specific subnet can be removed.
/// @brief Tests that leases from specific subnet can be removed.
/// @todo: uncomment this once lease wipe is implemented
/// for Cassandra (see #5485)
TEST_F(CqlLeaseMgrTest, DISABLED_wipeLeases6) {
......
......@@ -67,7 +67,8 @@ public:
///
/// @param address Address to use for the initialization
///
/// @return Lease6Ptr. This will not point to anything if the initialization
/// @return Lease6Ptr. This will not point to anything if the
/// initialization
/// failed (e.g. unknown address).
Lease6Ptr initializeLease6(std::string address);
......@@ -446,13 +447,13 @@ public:
const std::vector<std::string>& expected_addresses);
/// @brief String forms of IPv4 addresses
std::vector<std::string> straddress4_;
std::vector<std::string> straddress4_;
/// @brief IOAddress forms of IPv4 addresses
std::vector<isc::asiolink::IOAddress> ioaddress4_;
/// @brief String forms of IPv6 addresses
std::vector<std::string> straddress6_;
std::vector<std::string> straddress6_;
/// @brief Types of IPv6 Leases
std::vector<Lease::Type> leasetype6_;
......@@ -502,7 +503,7 @@ public: