From b3553db19d05490d84d994d4f2a03bf23a872ec3 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Fri, 27 Dec 2024 11:16:24 +0100 Subject: [PATCH] [#3683] Added registered lease state --- src/bin/admin/tests/mysql_tests.sh.in | 7 +++++++ src/bin/admin/tests/pgsql_tests.sh.in | 9 ++++++++- src/lib/dhcpsrv/lease.cc | 7 +++++-- src/lib/dhcpsrv/lease.h | 3 +++ src/lib/dhcpsrv/tests/lease_unittest.cc | 14 ++++++++------ .../database/scripts/mysql/dhcpdb_create.mysql | 3 +++ .../scripts/mysql/upgrade_027_to_028.sh.in | 3 +++ .../database/scripts/pgsql/dhcpdb_create.pgsql | 3 +++ .../scripts/pgsql/upgrade_027_to_028.sh.in | 3 +++ 9 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 44bc9d8047..234d1dc1bb 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -1020,6 +1020,13 @@ mysql_upgrade_27_to_28_test() { check_table_column ddns_ttl dhcp6_subnet check_table_column ddns_ttl_min dhcp6_subnet check_table_column ddns_ttl_max dhcp6_subnet + + # check registered were added tp lease_state + qry="SELECT name FROM lease_state WHERE state = 4" + run_command \ + mysql_execute "${qry}" + assert_eq 0 "${EXIT_CODE}" "${qry}: expected %d, returned %d" + assert_str_eq 'registered' "${OUTPUT}" "${qry}: expected output %s, returned %s" } mysql_upgrade_test() { diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 4fd7a33786..2463f993e1 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -1110,7 +1110,14 @@ pgsql_upgrade_27_to_28_test() { check_table_column ddns_ttl_percent dhcp6_subnet check_table_column ddns_ttl dhcp6_subnet check_table_column ddns_ttl_min dhcp6_subnet - check_table_column ddns_ttl_max dhcp6_subnet + check_table_column ddns_ttl_max dhcp6_subnet + + # check registered were added tp lease_state + query="SELECT name FROM lease_state WHERE state = 4" + run_command \ + pgsql_execute "${query}" + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq 'registered' "${OUTPUT}" "${query}: expected output %s, returned %s" } pgsql_upgrade_test() { diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index d28580c3de..905ee59c64 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -28,6 +28,7 @@ const uint32_t Lease::STATE_DEFAULT = 0; const uint32_t Lease::STATE_DECLINED = 1; const uint32_t Lease::STATE_EXPIRED_RECLAIMED = 2; const uint32_t Lease::STATE_RELEASED = 3; +const uint32_t Lease::STATE_REGISTERED = 4; std::string Lease::lifetimeToText(uint32_t lifetime) { @@ -100,6 +101,8 @@ Lease::basicStatesToText(const uint32_t state) { return ("expired-reclaimed"); case STATE_RELEASED: return ("released"); + case STATE_REGISTERED: + return ("registered"); default: // The default case will be handled further on ; @@ -284,10 +287,10 @@ Lease::fromElementCommon(const LeasePtr& lease, const data::ConstElementPtr& ele " or it is not an integer"); } - if ((state->intValue() < 0) || (state->intValue() > Lease::STATE_RELEASED)) { + if ((state->intValue() < 0) || (state->intValue() > Lease::STATE_REGISTERED)) { isc_throw(BadValue, "state " << state->intValue() << " must be in range [0.." - << Lease::STATE_RELEASED << "]"); + << Lease::STATE_REGISTERED << "]"); } lease->state_ = state->intValue(); diff --git a/src/lib/dhcpsrv/lease.h b/src/lib/dhcpsrv/lease.h index 85b82c70eb..f22ff0eeab 100644 --- a/src/lib/dhcpsrv/lease.h +++ b/src/lib/dhcpsrv/lease.h @@ -77,6 +77,9 @@ struct Lease : public isc::data::UserContext, public isc::data::CfgToElement { /// @brief Released lease held in the database for lease affinity. static const uint32_t STATE_RELEASED; + /// @brief Registered self-generated lease. + static const uint32_t STATE_REGISTERED; + /// @brief Returns name(s) of the basic lease state(s). /// /// @param state A numeric value holding a state information. diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc index 98222e760c..638d12d7ec 100644 --- a/src/lib/dhcpsrv/tests/lease_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_unittest.cc @@ -619,7 +619,8 @@ TEST_F(Lease4Test, stateToText) { EXPECT_EQ("declined", Lease4::statesToText(Lease::STATE_DECLINED)); EXPECT_EQ("expired-reclaimed", Lease4::statesToText(Lease::STATE_EXPIRED_RECLAIMED)); EXPECT_EQ("released", Lease4::statesToText(Lease::STATE_RELEASED)); - EXPECT_EQ("unknown (4)", Lease4::statesToText(4)); + EXPECT_EQ("registered", Lease4::statesToText(Lease::STATE_REGISTERED)); + EXPECT_EQ("unknown (5)", Lease4::statesToText(5)); } /// @brief Creates an instance of the lease with certain FQDN data. @@ -1329,8 +1330,8 @@ TEST(Lease6Test, fromElementPD) { EXPECT_EQ(400, lease->preferred_lft_); } - // Verify that a released Lease6 can be created from JSON. -TEST(Lease6Test, fromElementReleased) { + // Verify that a registered Lease6 can be created from JSON. +TEST(Lease6Test, fromElementRegistered) { // Same as fromElementNA test at the exception of the state. std::string json = "{" "\"cltt\": 12345678," @@ -1342,7 +1343,7 @@ TEST(Lease6Test, fromElementReleased) { "\"iaid\": 123456," "\"ip-address\": \"2001:db8::1\"," "\"preferred-lft\": 400," - "\"state\": 3," + "\"state\": 4," "\"subnet-id\": 5678," "\"pool-id\": 5," "\"type\": \"IA_NA\"," @@ -1355,7 +1356,7 @@ TEST(Lease6Test, fromElementReleased) { ASSERT_TRUE(lease); - EXPECT_EQ(Lease::STATE_RELEASED, lease->state_); + EXPECT_EQ(Lease::STATE_REGISTERED, lease->state_); } // Test that specifying invalid values for a lease or not specifying @@ -1424,7 +1425,8 @@ TEST(Lease6Test, stateToText) { EXPECT_EQ("declined", Lease6::statesToText(Lease::STATE_DECLINED)); EXPECT_EQ("expired-reclaimed", Lease6::statesToText(Lease::STATE_EXPIRED_RECLAIMED)); EXPECT_EQ("released", Lease6::statesToText(Lease::STATE_RELEASED)); - EXPECT_EQ("unknown (4)", Lease6::statesToText(4)); + EXPECT_EQ("registered", Lease6::statesToText(Lease::STATE_REGISTERED)); + EXPECT_EQ("unknown (5)", Lease6::statesToText(5)); } } // end of anonymous namespace diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index 87f1d2da38..6dc07036ab 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -6157,6 +6157,9 @@ ALTER TABLE dhcp6_subnet ADD COLUMN ddns_ttl_min INT(10) DEFAULT NULL, ADD COLUMN ddns_ttl_max INT(10) DEFAULT NULL; +-- New lease state for address registration +INSERT INTO lease_state VALUES (4, 'registered'); + -- Update the schema version number. UPDATE schema_version SET version = '28', minor = '0'; diff --git a/src/share/database/scripts/mysql/upgrade_027_to_028.sh.in b/src/share/database/scripts/mysql/upgrade_027_to_028.sh.in index 0d11734900..3a7c784358 100755 --- a/src/share/database/scripts/mysql/upgrade_027_to_028.sh.in +++ b/src/share/database/scripts/mysql/upgrade_027_to_028.sh.in @@ -80,6 +80,9 @@ ALTER TABLE dhcp6_subnet ADD COLUMN ddns_ttl_min INT(10) DEFAULT NULL, ADD COLUMN ddns_ttl_max INT(10) DEFAULT NULL; +-- New lease state for address registration +INSERT INTO lease_state VALUES (4, 'registered'); + -- Update the schema version number. UPDATE schema_version SET version = '28', minor = '0'; diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql index 83ec6969da..1d3edcc5c3 100644 --- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql @@ -6616,6 +6616,9 @@ ALTER TABLE dhcp6_subnet ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL, ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL; +-- New lease state for address registration +INSERT INTO lease_state VALUES (4, 'registered'); + -- Update the schema version number. UPDATE schema_version SET version = '28', minor = '0'; diff --git a/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in b/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in index f7ce30550f..dca5dc2a4d 100644 --- a/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in +++ b/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in @@ -63,6 +63,9 @@ ALTER TABLE dhcp6_subnet ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL, ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL; +-- New lease state for address registration +INSERT INTO lease_state VALUES (4, 'registered'); + -- Update the schema version number. UPDATE schema_version SET version = '28', minor = '0';