]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[392-search-of-reservations-by-hostname] Checkpoint: updated shcemas, todo tests
authorFrancis Dupont <fdupont@isc.org>
Sun, 29 Sep 2019 21:01:44 +0000 (23:01 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 15 Oct 2019 09:45:32 +0000 (11:45 +0200)
21 files changed:
configure.ac
src/bin/admin/tests/cql_tests.sh.in
src/bin/admin/tests/data/cql.hosts_data_test.csv
src/bin/admin/tests/data/cql.hosts_data_test.reference.csv
src/bin/admin/tests/data/cql.subnet_id_test.reference.csv
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/cql/cql_connection.h
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/mysql/mysql_constants.h
src/lib/pgsql/pgsql_connection.h
src/share/database/scripts/cql/Makefile.am
src/share/database/scripts/cql/dhcpdb_create.cql
src/share/database/scripts/cql/dhcpdb_drop.cql
src/share/database/scripts/cql/upgrade_4.0_to_5.0.sh.in [new file with mode: 0644]
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_8.2_to_9.0.sh.in [new file with mode: 0644]
src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_5.1_to_6.0.sh.in [new file with mode: 0644]

index 9cd89290f06441cd40e0a744020dea3fd9671eab..420fecd1f5101899586487355c3f1e630589600a 100755 (executable)
@@ -1796,6 +1796,7 @@ AC_CONFIG_FILES([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/upgrade_4.0_to_5.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
@@ -1810,6 +1811,7 @@ AC_CONFIG_FILES([Makefile
                  src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh
                  src/share/database/scripts/mysql/upgrade_8.0_to_8.1.sh
                  src/share/database/scripts/mysql/upgrade_8.1_to_8.2.sh
+                 src/share/database/scripts/mysql/upgrade_8.2_to_9.0.sh
                  src/share/database/scripts/mysql/wipe_data.sh
                  src/share/database/scripts/pgsql/Makefile
                  src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
@@ -1820,6 +1822,7 @@ AC_CONFIG_FILES([Makefile
                  src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh
                  src/share/database/scripts/pgsql/upgrade_4.0_to_5.0.sh
                  src/share/database/scripts/pgsql/upgrade_5.0_to_5.1.sh
+                 src/share/database/scripts/pgsql/upgrade_5.1_to_6.0.sh
                  src/share/database/scripts/pgsql/wipe_data.sh
                  src/share/yang/Makefile
                  src/share/yang/modules/Makefile
index 88ba7b6902a573f1c2775d1bd34f316cac8cacca..a79d3bf4b4ead2a60428e7ef57fd36e18b40dc45 100644 (file)
@@ -85,7 +85,7 @@ cql_db_version_test() {
 
     # Verify that kea-admin db-version returns the correct version.
     version=$($keaadmin db-version cql -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"
 
     # Wipe the database.
     cql_wipe
@@ -315,16 +315,16 @@ cql_unused_subnet_id_test() {
 
     # 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);"
+  INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \
+    VALUES (1, 0, textAsBlob('0123456'), 0, 0, 'host0', 0);\
+  INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \
+    VALUES (2, 0, textAsBlob('1123456'), 4, 0, 'Host1', 4);\
+  INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \
+    VALUES (3, 0, textAsBlob('2123456'), 0, 6, 'host2', 6);\
+  INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \
+    VALUES (4, 0, textAsBlob('3123456'), 4, 6, 'Host3', 0);\
+  INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \
+    VALUES (5, 0, textAsBlob('3123456'), -1, 6, 'host3', 6);"
 
     cql_execute "$qry"
     assert_eq 0 $? "insert hosts failed, expected exit code: %d, actual: %d"
@@ -347,7 +347,7 @@ cql_unused_subnet_id_test() {
     echo "Exporting host_reservation data to $export_file ..."
 
     qry="\
-  SELECT id, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id\
+  SELECT id, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, lower_case_hostname, option_subnet_id\
     FROM hosts WHERE id IN (1,2,3,4,5) ALLOW FILTERING;"
 
     cql_execute "$qry" > $export_file
@@ -433,7 +433,8 @@ cql_upgrade_hosts_test() {
         (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, \
+         lower_case_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, \
index 1712f8c4b13b794d8d47e0e37ec14d5409db50d0..ed73ffa3a3c64907b3ec656815e1e0d83d18bc5d 100644 (file)
@@ -1,6 +1,6 @@
-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\r
-2370585748436022247,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3\r
+1105657659805715115,0x4142434445464748494b,1,1,101,0,0,,,host60,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3
+2129388898029710264,0x414243444548,0,2,102,0,0,,,Host61,,,,,2001:db8::1,128,0,0,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3\r
+2370585748436022247,0x414243444548,0,2,102,0,0,,,host62,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3\r
 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\r
index 046a3317d1c6d50014df7b868a22176fa997cc32..86ba92645fd591d2246b132c972e0572c47a9c77 100644 (file)
@@ -1,24 +1,24 @@
-1105657659805715115,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3\r
-2129388898029710264,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3\r
-2370585748436022247,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3\r
-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\r
-5403514763123047131,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,254,0x,192.0.2.3,dhcp4,False,,0,,3\r
-5501234819855171334,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3\r
-5747907930644082856,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3\r
-5955003068494074400,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,,3\r
-6399013866147252670,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3\r
-6783601303445960591,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3\r
-7821756928114620236,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,23,0x,64,dhcp4,False,,0,,3\r
-8973539074684426388,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,1,0x,,isc,True,,0,,3\r
-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\r
--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\r
--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\r
--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\r
--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\r
--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\r
--6372549629773775261,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3\r
--6378104957663278797,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,::,0,-1,-1,0,1,0x,,isc,True,,0,,3\r
--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\r
--7804940982500935489,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,0,23,0x,64,dhcp4,False,,0,,3\r
--8100784457292204371,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3\r
--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\r
+1105657659805715115,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,host60,host60,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3\r
+2129388898029710264,-4885955325122621964,0x414243444548,0,2,102,0,0,,,Host61,host61,,,,,2001:db8::1,128,0,0,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3\r
+2370585748436022247,-4885955325122621964,0x414243444548,0,2,102,0,0,,,host62,host62,,,,,2001:db8::1,128,0,0,0,67,0x,my-boot-file,dhcp4,True,,0,,3\r
+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\r
+5403514763123047131,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,,::,0,-1,-1,0,254,0x,192.0.2.3,dhcp4,False,,0,,3\r
+5501234819855171334,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,1,17,0x,2495,dhcp6,False,,0,,3\r
+5747907930644082856,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3\r
+5955003068494074400,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,1,59,0x,my-boot-file,dhcp6,True,,0,,3\r
+6399013866147252670,5367868710821401223,0x4142434445464748494b,1,1,101,0,0,,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3\r
+6783601303445960591,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,1,32,0x,3600,dhcp6,False,,0,,3\r
+7821756928114620236,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,,::,0,-1,-1,0,23,0x,64,dhcp4,False,,0,,3\r
+8973539074684426388,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,0,1,0x,,isc,True,,0,,3\r
+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\r
+-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\r
+-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\r
+-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\r
+-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\r
+-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\r
+-6372549629773775261,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,,::,0,-1,-1,0,1,0x,312131,vendor-encapsulated-options,False,,0,,3\r
+-6378104957663278797,4012104063077014549,0x414243444547,0,1,101,-1073741307,0,,,,,,,,,::,0,-1,-1,0,1,0x,,isc,True,,0,,3\r
+-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\r
+-7804940982500935489,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,0,23,0x,64,dhcp4,False,,0,,3\r
+-8100784457292204371,-4885955325122621964,0x414243444548,0,2,102,0,0,,,,,,,,,2001:db8::1,128,0,0,1,1,0x,,isc2,True,,0,,3\r
+-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\r
index 724264ad211793a7e55016b8f68e00ab4fce37ea..381c1811f4a995bbe9cd1cd487cb6724fd4f7ff3 100644 (file)
@@ -1,6 +1,6 @@
-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
-5,-1,6,6
+id,host_ipv4_subnet_id,host_ipv6_subnet_id,hostname,lower_case_hostname,option_subnet_id
+1,-1,-1,host0,host0,-1
+2,4,-1,Host1,host1,4
+3,-1,6,host2,host2,6
+4,4,6,Host3,host3,-1
+5,-1,6,host3,host3,6
index 0823b754c41d0fa147f95e5b963ca73d4ab2e819..2247d9e422de3d0c06f3165f422239ef7410464d 100644 (file)
@@ -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 8.2
+    # Ok, we have a 1.0 database. Let's upgrade it to 9.0
     ${keaadmin} db-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
     ERRCODE=$?
 
@@ -721,10 +721,6 @@ EOF
     qry="select client_class, require_client_classes, user_context from dhcp6_pool"
     run_statement "dhcp6_pool" "$qry"
 
-    # Verify upgraded schema reports version 8.2
-    version=$(${keaadmin} db-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "8.2" ${version} "Expected kea-admin to return %s, returned value was %s"
-
     # Verify that dhcp4_option_def column name is is_array
     qry="select is_array from dhcp4_option_def"
     run_statement "dhcp4_option_def verify is_array column" "$qry"
@@ -733,6 +729,10 @@ EOF
     qry="select is_array from dhcp6_option_def"
     run_statement "dhcp6_option_def verify is_array column" "$qry"
 
+    # Verify upgraded schema reports version 9.0
+    version=$(${keaadmin} db-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
+    assert_str_eq "9.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+
     # Let's wipe the whole database
     mysql_wipe
 
index d2c2d75f4eacc1debf1222cd80c71acaa7db1513..43802cbaed217e7ff9944f2a446e80aac27db858 100644 (file)
@@ -120,7 +120,7 @@ pgsql_db_version_test() {
 
     # Verify that kea-admin db-version returns the correct version
     version=$(${keaadmin} db-version pgsql -u $db_user -p $db_password -n $db_name)
-    assert_str_eq "5.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "6.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -230,10 +230,10 @@ 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_5_1() {
-    # Verify upgraded schema reports version 5.1.
+pgsql_upgrade_3_0_to_6_0() {
+    # Verify upgraded schema reports version 6.0.
     version=$(${keaadmin} db-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "5.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "6.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;"`
@@ -270,8 +270,8 @@ pgsql_upgrade_test() {
     # Check 2.0 to 3.0 upgrade
     pgsql_upgrade_2_0_to_3_0
 
-    # Check 3.0 to 5.1 upgrade
-    pgsql_upgrade_3_0_to_5_1
+    # Check 3.0 to 6.0 upgrade
+    pgsql_upgrade_3_0_to_6_0
 
     # Let's wipe the whole database
     pgsql_wipe
index dde9ee9ae30eb1508d14d3cc7c6a615bdd3bae64..f14400badfa0aec13609eb23c184ec8d57b09b12 100644 (file)
@@ -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: 4.0
+/// Define CQL schema version: 5.0
 /// @{
-constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR = 4u;
+constexpr uint32_t CQL_SCHEMA_VERSION_MAJOR = 5u;
 constexpr uint32_t CQL_SCHEMA_VERSION_MINOR = 0u;
 /// @}
 
index 085c9da46cbb0b3383bbad7add1a8fb3b0ed5fba..49521aebe48773779882bafbd9b117a7e1decdd8 100644 (file)
@@ -419,6 +419,9 @@ private:
     /// @brief Name reserved for the host
     std::string hostname_;
 
+    /// @brief Lower case name reserved for the host
+    std::string lower_case_hostname_;
+
     /// @brief User context
     std::string user_context_;
 
@@ -513,6 +516,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "host_ipv4_boot_file_name, "
       "auth_key, "
       "hostname, "
+      "lower_case_hostname, "
       "user_context, "
       "host_ipv4_client_classes, "
       "host_ipv6_client_classes, "
@@ -536,7 +540,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       // id
       "?, "
       // host
-      "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
+      "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
       // denormalized reservation, option
       "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "
       ") "
@@ -952,7 +956,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "option_user_context, "
       "option_scope_id "
       "FROM hosts "
-      "WHERE hostname = ? "
+      "WHERE lower_case_hostname = ? "
       "ALLOW FILTERING "
      }},
 
@@ -989,7 +993,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "option_user_context, "
       "option_scope_id "
       "FROM hosts "
-      "WHERE hostname = ? "
+      "WHERE lower_case_hostname = ? "
       "AND host_ipv4_subnet_id = ? "
       "ALLOW FILTERING "
      }},
@@ -1027,7 +1031,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
       "option_user_context, "
       "option_scope_id "
       "FROM hosts "
-      "WHERE hostname = ? "
+      "WHERE lower_case_hostname = ? "
       "AND host_ipv6_subnet_id = ? "
       "ALLOW FILTERING "
      }},
@@ -1496,6 +1500,15 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
                       << " is greater than allowed of " << HOSTNAME_MAX_LEN);
         }
 
+        // lower_case_hostname: text
+        lower_case_hostname_ = host->getLowerHostname();
+        if (lower_case_hostname_.size() > HOSTNAME_MAX_LEN) {
+            isc_throw(BadValue, "CqlHostExchange::prepareExchange(): lower "
+                      "case hostname " << lower_case_hostname_ << " of length "
+                      << lower_case_hostname_.size()
+                      << " is greater than allowed of " << HOSTNAME_MAX_LEN);
+        }
+
         // user_context: text
         ConstElementPtr ctx = host->getContext();
         if (ctx) {
@@ -1656,6 +1669,7 @@ CqlHostExchange::createBindForMutation(const HostPtr& host,
             data.add(&host_ipv4_boot_file_name_);
             data.add(&auth_key_);
             data.add(&hostname_);
+            data.add(&lower_case_hostname_);
             data.add(&user_context_);
             data.add(&host_ipv4_client_classes_);
             data.add(&host_ipv6_client_classes_);
index d83a8116c9ee0eab63dc3a48fde4f9031e43456e..f7ddbba6b45e213371a00c2fa654e0f3a830d3ae 100644 (file)
@@ -51,8 +51,8 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
 
 /// @name Current database schema version values.
 //@{
-const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 8;
-const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 2;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 9;
+const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
 
 //@}
 
index 63afe01fd062425e19af2f0975669332d0ff3003..339ec7eefccc6d15f25497322db486184878fa1a 100644 (file)
@@ -17,9 +17,9 @@
 namespace isc {
 namespace db {
 
-/// @brief Define PostgreSQL backend version: 5.1
-const uint32_t PG_SCHEMA_VERSION_MAJOR = 5;
-const uint32_t PG_SCHEMA_VERSION_MINOR = 1;
+/// @brief Define PostgreSQL backend version: 6.0
+const uint32_t PG_SCHEMA_VERSION_MAJOR = 6;
+const uint32_t PG_SCHEMA_VERSION_MINOR = 0;
 
 // Maximum number of parameters that can be used a statement
 // @todo This allows us to use an initializer list (since we can't
index 5cd3f86f5984a73a43682791ac3e66f67e53d416..88208c33e060db4de5940c21ca84452bb9ad157c 100644 (file)
@@ -6,6 +6,7 @@ sqlscripts_DATA += dhcpdb_drop.cql
 sqlscripts_DATA += upgrade_1.0_to_2.0.sh
 sqlscripts_DATA += upgrade_2.0_to_3.0.sh
 sqlscripts_DATA += upgrade_3.0_to_4.0.sh
+sqlscripts_DATA += upgrade_4.0_to_5.0.sh
 sqlscripts_DATA += wipe_data.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index 03008308bd941a20ce3dc4881fd0e0445b814b4a..34d5cc7e122512c468fd9244dce83c8544093e0e 100644 (file)
@@ -365,3 +365,16 @@ DELETE FROM schema_version WHERE version=3;
 INSERT INTO schema_version (version, minor) VALUES(4, 0);
 
 -- This line concludes database upgrade to version 4.0
+
+-- This line starts database upgrade to version 5.0
+
+-- Add the lower case hostname column to reservations.
+ALTER TABLE hosts ADD lower_case_hostname VARCHAR;
+
+-- Make the lower case hostname an index.
+CREATE INDEX IF NOT EXISTS hostsindex8 ON hosts (lower_case_hostname);
+
+DELETE FROM schema_version WHERE version=4;
+INSERT INTO schema_version (version, minor) VALUES(5, 0);
+
+-- This line concludes database upgrade to version 5.0
index 797ef59906b0a18d5ad49a3af14f83d5d81538c0..96c6ecc3d3c49ae20a5f7f59bba8eaba5bbd72d9 100644 (file)
@@ -48,5 +48,6 @@ DROP INDEX IF EXISTS hostsindex4;
 DROP INDEX IF EXISTS hostsindex5;
 DROP INDEX IF EXISTS hostsindex6;
 DROP INDEX IF EXISTS hostsindex7;
+DROP INDEX IF EXISTS hostsindex8;
 
 DROP INDEX IF EXISTS logsindex;
diff --git a/src/share/database/scripts/cql/upgrade_4.0_to_5.0.sh.in b/src/share/database/scripts/cql/upgrade_4.0_to_5.0.sh.in
new file mode 100644 (file)
index 0000000..3d50451
--- /dev/null
@@ -0,0 +1,197 @@
+#!/bin/sh
+
+prefix=@prefix@
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+# Need a path for temporary files created during data update
+# Use the state directory in the install path directory if it exists, otherwise
+# use the build tree
+if [ -e "@localstatedir@/lib/@PACKAGE_NAME@" ]; then
+    temp_file_dir="@localstatedir@/lib/@PACKAGE_NAME@"
+else
+    temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
+fi
+
+cqlargs=$@
+
+# Ensures the current schema version is 4.0. If not it exits.
+check_version() {
+    version=$(cql_version $cqlargs)
+
+    if [ "${version}" != "4.0" ]; then
+        printf "This script upgrades 4.0 to 5.0. Reported version is %s. Skipping upgrade.\n" "${version}"
+        exit 0
+    fi
+}
+
+# Peforms the schema changes from 4.0 to 5.0
+update_schema() {
+    cqlsh $cqlargs <<EOF
+-- This line starts database upgrade to version 5.0
+
+-- Add the lower case hostname column to reservations.
+ALTER TABLE hosts ADD lower_case_hostname VARCHAR;
+
+-- Make the lower case hostname an index.
+CREATE INDEX IF NOT EXISTS hostsindex8 ON hosts (lower_case_hostname);
+
+DELETE FROM schema_version WHERE version=4;
+INSERT INTO schema_version (version, minor) VALUES(5, 0);
+
+-- This line concludes database upgrade to version 5.0
+EOF
+
+    if [ "$?" -ne 0 ]
+    then
+        echo Schema udpate FAILED!
+        exit 1
+    fi
+}
+
+# Function to delete temporary update files
+clean_up() {
+    # clean up the files
+    if [ -e "$export_file" ]
+    then
+        rm $export_file
+    fi
+
+    if [ -e "$update_file" ]
+    then
+        rm $update_file
+    fi
+}
+
+# Function to clean up and exit the script gracefully
+#
+# Called by update_host_data()
+#
+# Parameters:
+# status - integer value to pass to sh:exit
+# explanation - "quoted" text message to emit to stdout
+exit_now() {
+    status=$1;shift
+    explanation=$1
+
+    clean_up
+    if [ "$status" -eq 0 ]
+    then
+        echo "Data Update SUCCESS! $explanation"
+    else
+        echo "Data Update FAILURE! $explanation"
+    fi
+
+    exit $status
+}
+
+# This function adds host 'lower_case_hostname' column.
+#
+# After exhausting the export file, the update file is submitted to
+# cqlsh for execution.
+#
+# No parameters.
+update_host_data() {
+    export_file="$temp_file_dir/cql_export.csv"
+    update_file="$temp_file_dir/cql_update.cql"
+
+    clean_up
+
+    # Fetch hosts data so we have primary key components and hostname.
+    echo "Exporting hostnames to $export_file ..."
+    query="COPY hosts (key, id, hostname) TO '$export_file'"
+
+    cqlsh $cqlargs -e "$query"
+    if [ "$?" -ne 0 ]
+    then
+        exit_now 1 "Cassandra get hostname failed! Could not update data!"
+    fi
+
+    # Strip the carriage returns that CQL insists on adding.
+    if [ -e "$export_file" ]
+    then
+        cat $export_file | tr -d '\015' > $export_file.2
+        mv $export_file.2 $export_file
+    else
+        # Shouldn't happen but then again we're talking about CQL here
+        exit_now 1 "Cassandra export file $export_file is missing?"
+    fi
+
+    # Iterate through the exported data, accumulating update statements,
+    # one for each reservation that needs updating.  We should have one
+    # host per line.
+    line_cnt=0;
+    update_cnt=0;
+
+    while read -r line
+    do
+        line_cnt=$((line_cnt + 1));
+        xIFS="$IFS"
+        IFS=$','
+
+        i=1
+        hostname=
+        # Parse the column values
+        for val in $line
+        do
+            case $i in
+            1)
+                key="$val"
+                ;;
+            2)
+                host_id="$val"
+                ;;
+            3)
+                hostname="$val"
+                ;;
+            *)
+                # We're going to assume that since any error is fatal
+                exit_now 1 "Line# $line_cnt, too many values, wrong or corrupt file"
+                ;;
+            esac
+            i=$((i + 1))
+        done
+
+        if [ "$i" -lt 3 ]
+        then
+            # We're going to assume that since any error is fatal
+            exit_now 1 "Line# $line_cnt, too few values, wrong or corrupt file"
+        fi
+
+        # If the hostname was not null set the lower case value
+        if [ "$hostname" != "" ]
+        then
+            lower=$(echo $hostname | tr '[:upper:]' '[:lower:]')
+            echo "update hosts set lower_case_hostname = '$lower' where key = $key and id = $host_id;" >> $update_file
+            update_cnt=$((update_cnt + 1))
+        fi
+
+        IFS="$xIFS"
+    done <  $export_file
+
+    # If we didn't record any updates, then hey, we're good to go!
+    if [ "$update_cnt" -eq 0 ]
+    then
+        exit_now 0 "Completed successfully: No updates were needed"
+    fi
+
+    # We have at least one update in the update file, so submit it # to cqlsh.
+    echo "$update_cnt update statements written to $update_file"
+    echo "Running the updates..."
+    cqlsh $cqlargs -f "$update_file"
+    if [ "$?" -ne 0 ]
+    then
+        exit_now 1 "Cassandra updates failed"
+    fi
+
+    exit_now 0 "Updated $update_cnt of $line_cnt records"
+}
+
+check_version
+update_schema
+update_host_data
index 6370f95af90a50540be134368fc002b4880c2a11..786552afafd9f53cb10d927b92b21d1e2358add1 100644 (file)
@@ -15,6 +15,7 @@ sqlscripts_DATA += upgrade_6.0_to_7.0.sh
 sqlscripts_DATA += upgrade_7.0_to_8.0.sh
 sqlscripts_DATA += upgrade_8.0_to_8.1.sh
 sqlscripts_DATA += upgrade_8.1_to_8.2.sh
+sqlscripts_DATA += upgrade_8.2_to_9.0.sh
 sqlscripts_DATA += wipe_data.sh
 
 DISTCLEANFILES = upgrade_1.0_to_2.0.sh
@@ -28,6 +29,7 @@ DISTCLEANFILES += upgrade_5.2_to_6.0.sh
 DISTCLEANFILES += upgrade_6.0_to_7.0.sh
 DISTCLEANFILES += upgrade_7.0_to_8.0.sh
 DISTCLEANFILES += upgrade_8.1_to_8.2.sh
+DISTCLEANFILES += upgrade_8.2_to_9.0.sh
 DISTCLEANFILES += wipe_data.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index 2acfafa601f2eec9ea58673a18656aa543def4ae..f451757223f05b01ae7a3bfdefa27ae22c7a5fec 100644 (file)
@@ -2782,6 +2782,15 @@ SET version = '8', minor = '2';
 
 # This line concludes database upgrade to version 8.2.
 
+# Create hostname index for host reservations
+CREATE INDEX hosts_by_hostname ON hosts (hostname);
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '9', minor = '0';
+
+# This line concludes database upgrade to version 9.0.
+
 
 # Notes:
 #
diff --git a/src/share/database/scripts/mysql/upgrade_8.2_to_9.0.sh.in b/src/share/database/scripts/mysql/upgrade_8.2_to_9.0.sh.in
new file mode 100644 (file)
index 0000000..1bdf048
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+prefix=@prefix@
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`mysql_version "$@"`
+
+if [ "$VERSION" != "8.2" ]; then
+    printf "This script upgrades 8.2 to 9.0. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+mysql "$@" <<EOF
+
+# Create hostname index for host reservations
+CREATE INDEX hosts_by_hostname ON hosts (hostname);
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '9', minor = '0';
+
+# This line concludes database upgrade to version 9.0.
+
+EOF
+
+RESULT=$?
+
+exit $?
index 4c5b36a7220f6996659c2c7b38abe87f52c8bad1..60c03bfa2afc2935dd5644e55dc46227edf46512 100644 (file)
@@ -11,6 +11,7 @@ sqlscripts_DATA += upgrade_3.2_to_3.3.sh
 sqlscripts_DATA += upgrade_3.3_to_4.0.sh
 sqlscripts_DATA += upgrade_4.0_to_5.0.sh
 sqlscripts_DATA += upgrade_5.0_to_5.1.sh
+sqlscripts_DATA += upgrade_5.1_to_6.0.sh
 sqlscripts_DATA += wipe_data.sh
 
 DISTCLEANFILES = upgrade_1.0_to_2.0.sh
@@ -21,6 +22,7 @@ DISTCLEANFILES += upgrade_3.2_to_3.3.sh
 DISTCLEANFILES += upgrade_3.3_to_4.0.sh
 DISTCLEANFILES += upgrade_4.0_to_5.0.sh
 DISTCLEANFILES += upgrade_5.0_to_5.1.sh
+DISTCLEANFILES += upgrade_5.1_to_6.0.sh
 DISTCLEANFILES += wipe_data.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index 60151d79820374e18d2ce75c195179aa4183dfe7..b207cabc671f2f7016ffa8680092c8c23b93d96f 100644 (file)
@@ -887,7 +887,21 @@ UPDATE schema_version
 
 -- Schema 5.1 specification ends here.
 
--- Commit the script transaction.
+-- Upgrade to schema 6.0 begins here:
+
+START TRANSACTION;
+
+-- Create a lower case hostname index.
+CREATE INDEX hosts_by_hostname ON hosts (lower(hostname))
+WHERE hostname IS NOT NULL;
+
+-- Set 6.0 schema version.
+UPDATE schema_version
+    SET version = '6', minor = '0';
+
+-- Schema 5.1a specification ends here.
+
+-- Commit the script transaction
 COMMIT;
 
 -- Notes:
diff --git a/src/share/database/scripts/pgsql/upgrade_5.1_to_6.0.sh.in b/src/share/database/scripts/pgsql/upgrade_5.1_to_6.0.sh.in
new file mode 100644 (file)
index 0000000..59dcf66
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+prefix=@prefix@
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`pgsql_version "$@"`
+
+if [ "$VERSION" != "5.1" ]; then
+    printf "This script upgrades 5.1 to 6.0. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+START TRANSACTION;
+
+-- Create a lower case hostname index.
+CREATE INDEX hosts_by_hostname ON hosts (lower(hostname))
+WHERE hostname IS NOT NULL;
+
+-- Set 6.0 schema version.
+UPDATE schema_version
+    SET version = '6', minor = '0';
+
+-- Schema 5.1a specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+EOF
+
+exit $RESULT
+