Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
d2cd5d53
Commit
d2cd5d53
authored
May 15, 2015
by
Tomek Mrugalski
🛰
Browse files
[master] Merge branch 'trac3567' (host reservations MySQL schema)
parents
704dcc76
17f63946
Changes
5
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
d2cd5d53
...
...
@@ -1455,6 +1455,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
src/bin/admin/tests/mysql_tests.sh
src/bin/admin/scripts/mysql/Makefile
src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh
src/bin/admin/scripts/pgsql/Makefile
src/hooks/Makefile
src/hooks/dhcp/Makefile
...
...
src/bin/admin/scripts/mysql/Makefile.am
View file @
d2cd5d53
SUBDIRS
=
.
sqlscriptsdir
=
${datarootdir}
/
${PACKAGE_NAME}
/scripts/mysql
sqlscripts_DATA
=
dhcpdb_create.mysql upgrade_1.0_to_2.0.sh
sqlscripts_DATA
=
dhcpdb_create.mysql upgrade_1.0_to_2.0.sh
upgrade_2.0_to_3.0.sh
EXTRA_DIST
=
dhcpdb_create.mysql upgrade_1.0_to_2.0.sh
EXTRA_DIST
=
dhcpdb_create.mysql upgrade_1.0_to_2.0.sh
upgrade_2.0_to_3.0.sh
src/bin/admin/scripts/mysql/dhcpdb_create.mysql
View file @
d2cd5d53
...
...
@@ -163,6 +163,93 @@ UPDATE schema_version SET version="2", minor="0";
# This line concludes database upgrade to version 2.0.
# This line starts database upgrade to version 3.0.
# Upgrade extending MySQL schema with the ability to store hosts.
CREATE TABLE IF NOT EXISTS hosts (
host_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
dhcp_identifier VARBINARY(128) NOT NULL,
dhcp_identifier_type TINYINT NOT NULL,
dhcp4_subnet_id INT UNSIGNED NULL,
dhcp6_subnet_id INT UNSIGNED NULL,
ipv4_address INT UNSIGNED NULL,
hostname VARCHAR(255) NULL,
dhcp4_client_classes VARCHAR(255) NULL,
dhcp6_client_classes VARCHAR(255) NULL,
PRIMARY KEY (host_id),
INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC),
INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC)
) ENGINE=INNODB;
-- -----------------------------------------------------
-- Table `ipv6_reservations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS ipv6_reservations (
reservation_id INT NOT NULL AUTO_INCREMENT,
address VARCHAR(39) NOT NULL,
prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128,
type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0,
dhcp6_iaid INT UNSIGNED NULL,
host_id INT UNSIGNED NOT NULL,
PRIMARY KEY (reservation_id),
INDEX fk_ipv6_reservations_host_idx (host_id ASC),
CONSTRAINT fk_ipv6_reservations_Host FOREIGN KEY (host_id)
REFERENCES hosts (host_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=INNODB;
-- -----------------------------------------------------
-- Table `dhcp4_options`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS dhcp4_options (
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
code TINYINT UNSIGNED NOT NULL,
value BLOB NULL,
formatted_value TEXT NULL,
space VARCHAR(128) NULL,
persistent TINYINT(1) NOT NULL DEFAULT 0,
dhcp_client_class VARCHAR(128) NULL,
dhcp4_subnet_id INT NULL,
host_id INT UNSIGNED NULL,
PRIMARY KEY (option_id),
UNIQUE INDEX option_id_UNIQUE (option_id ASC),
INDEX fk_options_host1_idx (host_id ASC),
CONSTRAINT fk_options_host1 FOREIGN KEY (host_id)
REFERENCES hosts (host_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=INNODB;
-- -----------------------------------------------------
-- Table `dhcp6_options`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS dhcp6_options (
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
code INT UNSIGNED NOT NULL,
value BLOB NULL,
formatted_value TEXT NULL,
space VARCHAR(128) NULL,
persistent TINYINT(1) NOT NULL DEFAULT 0,
dhcp_client_class VARCHAR(128) NULL,
dhcp6_subnet_id INT NULL,
host_id INT UNSIGNED NULL,
PRIMARY KEY (option_id),
UNIQUE INDEX option_id_UNIQUE (option_id ASC),
INDEX fk_options_host1_idx (host_id ASC),
CONSTRAINT fk_options_host10 FOREIGN KEY (host_id)
REFERENCES hosts (host_id)
ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=INNODB;
DELIMITER $$
CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id;
END
$$
DELIMITER ;
UPDATE schema_version
SET version = '3', minor = '0';
# This line concludes database upgrade to version 3.0.
# Notes:
#
# Indexes
...
...
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in
0 → 100755
View file @
d2cd5d53
#!/bin/sh
# 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
mysql_version
"
$@
"
VERSION
=
$_RESULT
if
[
"
$VERSION
"
!=
"2.0"
]
;
then
printf
"This script upgrades 2.0 to 3.0. Reported version is
$VERSION
. Skipping upgrade.
\n
"
exit
0
fi
mysql
"
$@
"
<<
EOF
CREATE TABLE IF NOT EXISTS hosts (
host_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
dhcp_identifier VARBINARY(128) NOT NULL ,
dhcp_identifier_type TINYINT NOT NULL ,
dhcp4_subnet_id INT UNSIGNED NULL ,
dhcp6_subnet_id INT UNSIGNED NULL ,
ipv4_address INT UNSIGNED NULL ,
hostname VARCHAR(255) NULL ,
dhcp4_client_classes VARCHAR(255) NULL ,
dhcp6_client_classes VARCHAR(255) NULL ,
PRIMARY KEY (host_id) ,
INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) );
CREATE TABLE IF NOT EXISTS ipv6_reservations (
reservation_id INT NOT NULL AUTO_INCREMENT ,
address VARCHAR(39) NOT NULL ,
prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128 ,
type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 ,
dhcp6_iaid INT UNSIGNED NULL ,
host_id INT UNSIGNED NOT NULL ,
PRIMARY KEY (reservation_id) ,
INDEX fk_ipv6_reservations_host_idx (host_id ASC) ,
CONSTRAINT fk_ipv6_reservations_Host
FOREIGN KEY (host_id )
REFERENCES hosts (host_id )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS dhcp4_options (
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
code TINYINT UNSIGNED NOT NULL ,
value BLOB NULL ,
formatted_value TEXT NULL ,
space VARCHAR(128) NULL ,
persistent TINYINT(1) NOT NULL DEFAULT 0 ,
dhcp_client_class VARCHAR(128) NULL ,
dhcp4_subnet_id INT NULL ,
host_id INT UNSIGNED NULL ,
PRIMARY KEY (option_id) ,
UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
INDEX fk_options_host1_idx (host_id ASC) ,
CONSTRAINT fk_options_host1
FOREIGN KEY (host_id )
REFERENCES hosts (host_id )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS dhcp6_options (
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
code INT UNSIGNED NOT NULL ,
value BLOB NULL ,
formatted_value TEXT NULL ,
space VARCHAR(128) NULL ,
persistent TINYINT(1) NOT NULL DEFAULT 0 ,
dhcp_client_class VARCHAR(128) NULL ,
dhcp6_subnet_id INT NULL ,
host_id INT UNSIGNED NULL ,
PRIMARY KEY (option_id) ,
UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
INDEX fk_options_host1_idx (host_id ASC) ,
CONSTRAINT fk_options_host10
FOREIGN KEY (host_id )
REFERENCES hosts (host_id )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
DELIMITER
$$
CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id;
END
$$
DELIMITER ;
UPDATE schema_version SET version="3", minor="0";
EOF
RESULT
=
$?
exit
$?
src/bin/admin/tests/mysql_tests.sh.in
View file @
d2cd5d53
...
...
@@ -129,11 +129,63 @@ EOF
test_finish 0
}
mysql_lease_upgrade_test
()
{
mysql_host_reservation_init_test
()
{
test_start
"mysql.host_reservation-init"
# @todo: need to test whether non-empty database is updated correctly and the data survives the upgrade
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initalize the database
${
keaadmin
}
lease-init mysql
-u
$db_user
-p
$db_pass
-n
$db_name
-d
@abs_top_srcdir@/src/bin/admin/scripts
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"kea-admin lease-init mysql returned non-zero status code %d, expected %d"
# Ok, now let's check if the tables are indeed there.
# First table: schema_version. Should have 2 columns: version and minor.
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT version, minor FROM schema_version;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"schema_version table is missing or broken. (returned status code %d, expected %d)"
# Second table: hosts
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"hosts table is missing or broken. (returned status code %d, expected %d)"
# Third table: ipv6_reservations
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"ipv6_reservations table is missing or broken. (returned status code %d, expected %d)"
# Fourth table: dhcp4_options
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"dhcp4_options table is missing or broken. (returned status code %d, expected %d)"
# Fifth table: dhcp6_options
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"dhcp6_options table is missing or broken. (returned status code %d, expected %d)"
# Let's wipe the whole database
mysql_wipe
test_start
"mysql.lease-upgrade"
test_finish 0
}
mysql_upgrade_test
()
{
test_start
"mysql.host_reservation-upgrade"
# Let's wipe the whole database
mysql_wipe
...
...
@@ -146,7 +198,7 @@ mysql_lease_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
2
.0
# Ok, we have a 1.0 database. Let's upgrade it to
3
.0
${
keaadmin
}
lease-upgrade mysql
-u
$db_user
-p
$db_pass
-n
$db_name
-d
@abs_top_srcdir@/src/bin/admin/scripts
ERRCODE
=
$?
...
...
@@ -154,24 +206,53 @@ mysql_lease_upgrade_test() {
# Let's check that the new tables are indeed there.
#
Third
table: lease6
#table: lease6
(upgrade 1.0 -> 2.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT hwaddr, hwtype, hwaddr_source FROM lease6;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"lease6 table not upgraded to 2.0 (returned status code %d, expected %d)"
#
Fifth
table: lease_hwaddr_source
#table: lease_hwaddr_source
(upgrade 1.0 -> 2.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT hwaddr_source, name FROM lease_hwaddr_source;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"lease_hwaddr_source table is missing or broken. (returned status code %d, expected %d)"
# Verify that it reports version 2.0.
#table: hosts (upgrade 2.0 -> 3.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"hosts table is missing or broken. (returned status code %d, expected %d)"
#table: ipv6_reservations (upgrade 2.0 -> 3.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"ipv6_reservations table is missing or broken. (returned status code %d, expected %d)"
#table: dhcp4_options (upgrade 2.0 -> 3.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"dhcp4_options table is missing or broken. (returned status code %d, expected %d)"
#table: dhcp6_options (upgrade 2.0 -> 3.0)
mysql
-u
$db_user
-p
$db_pass
$db_name
>
/dev/null 2>&1
<<
EOF
SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options;
EOF
ERRCODE
=
$?
assert_eq 0
$ERRCODE
"dhcp6_options table is missing or broken. (returned status code %d, expected %d)"
# Verify that it reports version 3.0.
version
=
$(
${
keaadmin
}
lease-version mysql
-u
$db_user
-p
$db_pass
-n
$db_name
)
assert_str_eq
"
2
.0"
${
version
}
"Expected kea-admin to return %s, returned value was %s"
assert_str_eq
"
3
.0"
${
version
}
"Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
mysql_wipe
...
...
@@ -180,5 +261,6 @@ EOF
}
mysql_lease_init_test
mysql_host_reservation_init_test
mysql_lease_version_test
mysql_
lease_
upgrade_test
mysql_upgrade_test
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment