Skip to content

Commit ae27304

Browse files
committed
[#89,!22] Implemented MySQL schema upgrade tests for CB.
1 parent fd59729 commit ae27304

File tree

3 files changed

+183
-12
lines changed

3 files changed

+183
-12
lines changed

src/bin/admin/tests/mysql_tests.sh.in

+173-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ mysql_upgrade_schema_to_version() {
245245

246246
mysql_upgrade_test() {
247247

248-
test_start "mysql.host_reservation-upgrade"
248+
test_start "mysql.upgrade"
249249

250250
# Let's wipe the whole database
251251
mysql_wipe
@@ -469,11 +469,182 @@ EOF
469469
ERRCODE=$?
470470
assert_eq 0 $ERRCODE "logs table is missing or broken. (expected status code %d, returned %d)"
471471

472+
# table: modification (upgrade 6.0 -> 7.0)
473+
qry="select id, modification_type from modification";
474+
count=`mysql_execute "${qry}"`
475+
ERRCODE=$?
476+
assert_eq 0 $ERRCODE "modification table is missing or broken. (expected status code %d, returned %d)"
477+
478+
# table: modification table should have 3 entries (upgrade 6.0 -> 7.0)
479+
qry="select count(*) from modification";
480+
count=`mysql_execute "${qry}"`
481+
ERRCODE=$?
482+
assert_eq 3 "$count" "modification table does not contain correct number of entries. (expected count %d, returned %d)"
483+
484+
# table: dhcp4_server
485+
qry="select id, tag, description, modification_ts from dhcp4_server";
486+
count=`mysql_execute "${qry}"`
487+
ERRCODE=$?
488+
assert_eq 0 $ERRCODE "dhcp4_server table missing or broken (expected status code %d, returned %d)";
489+
490+
# table: dhcp4_audit
491+
qry="select id, object_type, object_id, modification_type, modification_ts from dhcp4_audit";
492+
count=`mysql_execute "${qry}"`
493+
ERRCODE=$?
494+
assert_eq 0 $ERRCODE "dhcp4_audit table missing or broken (expected status code %d, returned %d)";
495+
496+
# table: dhcp4_global_parameter
497+
qry="select id, name, value, modification_ts from dhcp4_global_parameter";
498+
count=`mysql_execute "${qry}"`
499+
ERRCODE=$?
500+
assert_eq 0 $ERRCODE "dhcp4_global_parameter table missing or broken (expected status code %d, returned %d)";
501+
502+
# table: dhcp4_global_parameter_server
503+
qry="select parameter_id, server_id, modification_ts from dhcp4_global_parameter_server";
504+
count=`mysql_execute "${qry}"`
505+
ERRCODE=$?
506+
assert_eq 0 $ERRCODE "dhcp4_global_parameter_server table missing or broken (expected status code %d, returned %d)";
507+
508+
# table: dhcp4_option_def
509+
qry="select id, code, space, modification_ts, array, encapsulate, record_types, user_context from dhcp4_option_def";
510+
count=`mysql_execute "${qry}"`
511+
ERRCODE=$?
512+
assert_eq 0 $ERRCODE "dhcp4_option_def table missing or broken (expected status code %d, returned %d)";
513+
514+
# table: dhcp4_option_def_server
515+
qry="select option_def_id, server_id, modification_ts from dhcp4_option_def_server";
516+
count=`mysql_execute "${qry}"`
517+
ERRCODE=$?
518+
assert_eq 0 $ERRCODE "dhcp4_option_def_server table missing or broken (expected status code %d, returned %d)";
519+
520+
# table: dhcp4_shared_network
521+
qry="select name, client_class, interface, match_client_id, modification_ts, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, server_hostname, user_context, valid_lifetime from dhcp4_shared_network";
522+
count=`mysql_execute "${qry}"`
523+
ERRCODE=$?
524+
assert_eq 0 $ERRCODE "dhcp4_shared_network table missing or broken (expected status code %d, returned %d)";
525+
526+
# table: dhcp4_shared_network_server
527+
qry="select shared_network_name, server_id, modification_ts from dhcp4_shared_network_server";
528+
count=`mysql_execute "${qry}"`
529+
ERRCODE=$?
530+
assert_eq 0 $ERRCODE "dhcp4_shared_network_server table missing or broken (expected status code %d, returned %d)";
531+
532+
# table: dhcp4_subnet
533+
qry="select subnet_prefix, 4o6_interface, 4o6_interface_id, 4o6_subnet, boot_file_name, client_class, interface, match_client_id, modification_ts, next_server, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, server_hostname, shared_network_name, subnet_id, user_context, valid_lifetime from dhcp4_subnet";
534+
count=`mysql_execute "${qry}"`
535+
ERRCODE=$?
536+
assert_eq 0 $ERRCODE "dhcp4_subnet table missing or broken (expected status code %d, returned %d)";
537+
538+
# table: dhcp4_pool
539+
qry="select id, start_address, end_address, subnet_id, modification_ts from dhcp4_pool";
540+
count=`mysql_execute "${qry}"`
541+
ERRCODE=$?
542+
assert_eq 0 $ERRCODE "dhcp4_pool table missing or broken (expected status code %d, returned %d)";
543+
544+
# table: dhcp4_subnet_server
545+
qry="select subnet_id, server_id, modification_ts from dhcp4_subnet_server";
546+
count=`mysql_execute "${qry}"`
547+
ERRCODE=$?
548+
assert_eq 0 $ERRCODE "dhcp4_subnet_server table missing or broken (expected status code %d, returned %d)";
549+
550+
# table: dhcp4_options (should include three new columns)
551+
qry="select shared_network_name, pool_id, modification_ts from dhcp4_options";
552+
count=`mysql_execute "${qry}"`
553+
ERRCODE=$?
554+
assert_eq 0 $ERRCODE "dhcp4_options table missing or broken (expected status code %d, returned %d)";
555+
556+
# table: dhcp4_options_server
557+
qry="select option_id, server_id, modification_ts from dhcp4_options_server";
558+
count=`mysql_execute "${qry}"`
559+
ERRCODE=$?
560+
assert_eq 0 $ERRCODE "dhcp4_options_server table missing or broken (expected status code %d, returned %d)";
561+
# table: dhcp6_server
562+
qry="select id, tag, description, modification_ts from dhcp6_server";
563+
count=`mysql_execute "${qry}"`
564+
ERRCODE=$?
565+
assert_eq 0 $ERRCODE "dhcp6_server table missing or broken (expected status code %d, returned %d)";
566+
567+
# table: dhcp6_audit
568+
qry="select id, object_type, object_id, modification_type, modification_ts from dhcp6_audit";
569+
count=`mysql_execute "${qry}"`
570+
ERRCODE=$?
571+
assert_eq 0 $ERRCODE "dhcp6_audit table missing or broken (expected status code %d, returned %d)";
572+
573+
# table: dhcp6_global_parameter
574+
qry="select id, name, value, modification_ts from dhcp6_global_parameter";
575+
count=`mysql_execute "${qry}"`
576+
ERRCODE=$?
577+
assert_eq 0 $ERRCODE "dhcp6_global_parameter table missing or broken (expected status code %d, returned %d)";
578+
579+
# table: dhcp6_global_parameter_server
580+
qry="select parameter_id, server_id, modification_ts from dhcp6_global_parameter_server";
581+
count=`mysql_execute "${qry}"`
582+
ERRCODE=$?
583+
assert_eq 0 $ERRCODE "dhcp6_global_parameter_server table missing or broken (expected status code %d, returned %d)";
584+
585+
# table: dhcp6_option_def
586+
qry="select id, code, space, modification_ts, array, encapsulate, record_types, user_context from dhcp6_option_def";
587+
count=`mysql_execute "${qry}"`
588+
ERRCODE=$?
589+
assert_eq 0 $ERRCODE "dhcp6_option_def table missing or broken (expected status code %d, returned %d)";
590+
591+
# table: dhcp6_option_def_server
592+
qry="select option_def_id, server_id, modification_ts from dhcp6_option_def_server";
593+
count=`mysql_execute "${qry}"`
594+
ERRCODE=$?
595+
assert_eq 0 $ERRCODE "dhcp6_option_def_server table missing or broken (expected status code %d, returned %d)";
596+
597+
# table: dhcp6_shared_network
598+
qry="select name, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, server_hostname, user_context, valid_lifetime from dhcp6_shared_network";
599+
count=`mysql_execute "${qry}"`
600+
ERRCODE=$?
601+
assert_eq 0 $ERRCODE "dhcp6_shared_network table missing or broken (expected status code %d, returned %d)";
602+
# table: dhcp6_shared_network_server
603+
qry="select shared_network_name, server_id, modification_ts from dhcp6_shared_network_server";
604+
count=`mysql_execute "${qry}"`
605+
ERRCODE=$?
606+
assert_eq 0 $ERRCODE "dhcp6_shared_network_server table missing or broken (expected status code %d, returned %d)";
607+
608+
# table: dhcp6_subnet
609+
qry="select subnet_prefix, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, shared_network_name, subnet_id, user_context, valid_lifetime from dhcp6_subnet";
610+
count=`mysql_execute "${qry}"`
611+
ERRCODE=$?
612+
assert_eq 0 $ERRCODE "dhcp6_subnet table missing or broken (expected status code %d, returned %d)";
613+
614+
# table: dhcp6_subnet_server
615+
qry="select subnet_id, server_id, modification_ts from dhcp6_subnet_server";
616+
count=`mysql_execute "${qry}"`
617+
ERRCODE=$?
618+
assert_eq 0 $ERRCODE "dhcp6_subnet_server table missing or broken (expected status code %d, returned %d)";
619+
620+
# table: dhcp6_pd_pool
621+
qry="select id, prefix_length, delegated_prefix_length, dhcp6_subnet_id, modification_ts from dhcp6_pd_pool";
622+
count=`mysql_execute "${qry}"`
623+
ERRCODE=$?
624+
assert_eq 0 $ERRCODE "dhcp6_pd_pool table missing or broken (expected status code %d, returned %d)";
625+
626+
# table: dhcp6_pool
627+
qry="select id, start_address, end_address, dhcp6_subnet_id, modification_ts from dhcp6_pool";
628+
count=`mysql_execute "${qry}"`
629+
ERRCODE=$?
630+
assert_eq 0 $ERRCODE "dhcp6_pool table missing or broken (expected status code %d, returned %d)";
631+
632+
# table: dhcp6_options (should include four new columns)
633+
qry="select shared_network_name, pool_id, pd_pool_id, modification_ts from dhcp6_options";
634+
count=`mysql_execute "${qry}"`
635+
ERRCODE=$?
636+
assert_eq 0 $ERRCODE "dhcp6_options table missing or broken (expected status code %d, returned %d)";
637+
638+
# table: dhcp6_options_server
639+
qry="select option_id, server_id, modification_ts from dhcp6_options_server";
640+
count=`mysql_execute "${qry}"`
641+
ERRCODE=$?
642+
assert_eq 0 $ERRCODE "dhcp6_options_server table missing or broken (expected status code %d, returned %d)";
643+
472644
# Verify upgraded schema reports version 7.0
473645
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
474646
assert_str_eq "7.0" ${version} "Expected kea-admin to return %s, returned value was %s"
475647

476-
477648
# Let's wipe the whole database
478649
mysql_wipe
479650

src/share/database/scripts/mysql/dhcpdb_create.mysql

+5-5
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,8 @@ ALTER TABLE dhcp4_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL;
10001000

10011001
# Add conifguration backend specific columns.
10021002
ALTER TABLE dhcp4_options
1003-
ADD COLUMN dhcp4_shared_network_name VARCHAR(128) DEFAULT NULL,
1004-
ADD COLUMN dhcp4_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
1003+
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
1004+
ADD COLUMN pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
10051005
ADD COLUMN modification_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
10061006

10071007
-- -----------------------------------------------------
@@ -1247,9 +1247,9 @@ ALTER TABLE dhcp6_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL;
12471247

12481248
# Add conifguration backend specific columns.
12491249
ALTER TABLE dhcp6_options
1250-
ADD COLUMN dhcp6_shared_network_name VARCHAR(128) DEFAULT NULL,
1251-
ADD COLUMN dhcp6_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
1252-
ADD COLUMN dhcp6_pd_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
1250+
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
1251+
ADD COLUMN pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
1252+
ADD COLUMN pd_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
12531253
ADD COLUMN modification_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
12541254

12551255
-- -----------------------------------------------------

src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ ALTER TABLE dhcp4_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL;
320320
321321
# Add conifguration backend specific columns.
322322
ALTER TABLE dhcp4_options
323-
ADD COLUMN dhcp4_shared_network_name VARCHAR(128) DEFAULT NULL,
324-
ADD COLUMN dhcp4_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
323+
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
324+
ADD COLUMN pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
325325
ADD COLUMN modification_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
326326
327327
# Create table dhcp4_options_server
@@ -541,9 +541,9 @@ ALTER TABLE dhcp6_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL;
541541
542542
# Add conifguration backend specific columns.
543543
ALTER TABLE dhcp6_options
544-
ADD COLUMN dhcp6_shared_network_name VARCHAR(128) DEFAULT NULL,
545-
ADD COLUMN dhcp6_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
546-
ADD COLUMN dhcp6_pd_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
544+
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
545+
ADD COLUMN pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
546+
ADD COLUMN pd_pool_id BIGINT(20) UNSIGNED DEFAULT NULL,
547547
ADD COLUMN modification_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
548548
549549
# Create table dhcp6_options_server

0 commit comments

Comments
 (0)