Commit 465cfbd9 authored by Francis Dupont's avatar Francis Dupont

[393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-i...

[393-global-search-through-leases-by-mac-or-hostname-w-o-specifying-a-subnet-id] Moves lease hostnames to lower case
parent 0d3dee36
......@@ -29,9 +29,9 @@ Lease::Lease(const isc::asiolink::IOAddress& addr,
uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
const bool fqdn_fwd, const bool fqdn_rev,
const std::string& hostname, const HWAddrPtr& hwaddr)
:addr_(addr), valid_lft_(valid_lft), cltt_(cltt),
subnet_id_(subnet_id), hostname_(hostname), fqdn_fwd_(fqdn_fwd),
fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT) {
:addr_(addr), valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id),
hostname_(boost::algorithm::to_lower_copy(hostname)), fqdn_fwd_(fqdn_fwd),
fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT) {
}
......@@ -237,6 +237,7 @@ Lease::fromElementCommon(const LeasePtr& lease, const data::ConstElementPtr& ele
}
lease->hostname_ = hostname->stringValue();
boost::algorithm::to_lower(lease->hostname_);
// state
ConstElementPtr state = element->get("state");
......
......@@ -117,7 +117,7 @@ struct Lease : public isc::data::UserContext, public isc::data::CfgToElement {
/// @brief Client hostname
///
/// This field may be empty
/// This field is in lower case and may be empty.
std::string hostname_;
/// @brief Forward zone updated?
......
......@@ -126,7 +126,7 @@ TEST_F(Lease4Test, constructor) {
// Create the lease
Lease4 lease(ADDRESS[i], hwaddr_, clientid_, VALID_LIFETIME,
current_time, SUBNET_ID, true, true,
"hostname.example.com.");
"Hostname.Example.Com.");
EXPECT_EQ(ADDRESS[i], lease.addr_.toUint32());
EXPECT_TRUE(util::equalValues(hwaddr_, lease.hwaddr_));
......@@ -370,7 +370,7 @@ TEST_F(Lease4Test, operatorEquals) {
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
EXPECT_FALSE(lease1 != lease2); // ... leases equal
lease1.hostname_ += std::string("Something random");
lease1.hostname_ += std::string("something random");
EXPECT_FALSE(lease1 == lease2);
EXPECT_TRUE(lease1 != lease2);
lease1.hostname_ = lease2.hostname_;
......@@ -493,7 +493,7 @@ TEST_F(Lease4Test, toElement) {
const time_t current_time = 12345678;
Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, clientid_, 3600,
current_time, 789, true, true, "urania.example.org");
current_time, 789, true, true, "URANIA.example.org");
lease.setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
std::string expected = "{"
......@@ -556,7 +556,7 @@ TEST_F(Lease4Test, fromElement) {
"\"cltt\": 12345678,"
"\"fqdn-fwd\": true,"
"\"fqdn-rev\": true,"
"\"hostname\": \"urania.example.org\","
"\"hostname\": \"urania.example.ORG\","
"\"hw-address\": \"08:00:2b:02:3f:4e\","
"\"ip-address\": \"192.0.2.3\","
"\"state\": 0,"
......@@ -634,7 +634,7 @@ TEST_F(Lease4Test, decline) {
const time_t current_time = 12345678;
Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, clientid_, 3600,
current_time, 789);
lease.hostname_="foo.example.org";
lease.hostname_ = "foo.example.org";
lease.fqdn_fwd_ = true;
lease.fqdn_rev_ = true;
......@@ -746,7 +746,7 @@ TEST(Lease6Test, Lease6ConstructorWithFQDN) {
IOAddress addr(ADDRESS[i]);
Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr,
duid, iaid, 100, 200, subnet_id,
true, true, "host.example.com."));
true, true, "Host.Example.Com."));
EXPECT_TRUE(lease->addr_ == addr);
EXPECT_TRUE(*lease->duid_ == *duid);
......@@ -862,7 +862,7 @@ TEST(Lease6Test, operatorEquals) {
EXPECT_TRUE(lease1 == lease2); // Check that the reversion has made the
EXPECT_FALSE(lease1 != lease2); // ... leases equal
lease1.hostname_ += std::string("Something random");
lease1.hostname_ += std::string("something random");
EXPECT_FALSE(lease1 == lease2);
EXPECT_TRUE(lease1 != lease2);
lease1.hostname_ = lease2.hostname_;
......@@ -1220,7 +1220,7 @@ TEST(Lease6Test, fromElementNA) {
"\"duid\": \"00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\","
"\"fqdn-fwd\": false,"
"\"fqdn-rev\": false,"
"\"hostname\": \"urania.example.org\","
"\"hostname\": \"urania.EXAMPLE.org\","
"\"hw-address\": \"08:00:2b:02:3f:4e\","
"\"iaid\": 123456,"
"\"ip-address\": \"2001:db8::1\","
......@@ -1266,7 +1266,7 @@ TEST(Lease6Test, fromElementPD) {
"\"duid\": \"00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\","
"\"fqdn-fwd\": false,"
"\"fqdn-rev\": false,"
"\"hostname\": \"urania.example.org\","
"\"hostname\": \"uraniA.exaMple.orG\","
"\"hw-address\": \"08:00:2b:02:3f:4e\","
"\"iaid\": 123456,"
"\"ip-address\": \"3000::\","
......
......@@ -374,6 +374,12 @@ 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);
-- Create a new hostname index on lease4.
CREATE INDEX IF NOT EXISTS lease4index6 ON lease4 (hostname);
-- Create a new hostname index on lease6.
CREATE INDEX IF NOT EXISTS lease6index7 ON lease6 (hostname);
DELETE FROM schema_version WHERE version=4;
INSERT INTO schema_version (version, minor) VALUES(5, 0);
......
......@@ -33,6 +33,7 @@ DROP INDEX IF EXISTS lease4index2;
DROP INDEX IF EXISTS lease4index3;
DROP INDEX IF EXISTS lease4index4;
DROP INDEX IF EXISTS lease4index5;
DROP INDEX IF EXISTS lease4index6;
DROP INDEX IF EXISTS lease6index1;
DROP INDEX IF EXISTS lease6index2;
......@@ -40,6 +41,7 @@ DROP INDEX IF EXISTS lease6index3;
DROP INDEX IF EXISTS lease6index4;
DROP INDEX IF EXISTS lease6index5;
DROP INDEX IF EXISTS lease6index6;
DROP INDEX IF EXISTS lease6index7;
DROP INDEX IF EXISTS hostsindex1;
DROP INDEX IF EXISTS hostsindex2;
......
......@@ -2785,6 +2785,12 @@ SET version = '8', minor = '2';
# Create hostname index for host reservations
CREATE INDEX hosts_by_hostname ON hosts (hostname);
# Create hostname index for lease4
CREATE INDEX lease4_by_hostname ON lease4 (hostname);
# Create hostname index for lease6
CREATE INDEX lease6_by_hostname ON lease6 (hostname);
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '0';
......
......@@ -21,6 +21,20 @@ mysql "$@" <<EOF
# Create hostname index for host reservations
CREATE INDEX hosts_by_hostname ON hosts (hostname);
# Move to lower case hostnames in lease4 table.
UPDATE lease4 SET hostname = LOWER(hostname)
WHERE BINARY LOWER(hostname) != hostname;
# Move to lower case hostnames in lease6 table.
UPDATE lease6 SET hostname = LOWER(hostname)
WHERE BINARY LOWER(hostname) != hostname;
# Create hostname index for lease4
CREATE INDEX lease4_by_hostname ON lease4 (hostname);
# Create hostname index for lease6
CREATE INDEX lease6_by_hostname ON lease6 (hostname);
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '0';
......
......@@ -891,10 +891,18 @@ UPDATE schema_version
START TRANSACTION;
-- Create a lower case hostname index.
-- Create a lower case hostname index for hosts.
CREATE INDEX hosts_by_hostname ON hosts (lower(hostname))
WHERE hostname IS NOT NULL;
-- Create a hostname index for lease4.
CREATE INDEX lease4_by_hostname ON lease4 (hostname)
WHERE hostname IS NOT NULL;
-- Create a hostname index for lease6.
CREATE INDEX lease6_by_hostname ON lease6 (hostname)
WHERE hostname IS NOT NULL;
-- Set 6.0 schema version.
UPDATE schema_version
SET version = '6', minor = '0';
......
......@@ -20,10 +20,26 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
-- Create a lower case hostname index.
-- Create a lower case hostname index for hosts.
CREATE INDEX hosts_by_hostname ON hosts (lower(hostname))
WHERE hostname IS NOT NULL;
-- Create a hostname index for lease4.
CREATE INDEX lease4_by_hostname ON lease4 (hostname)
WHERE hostname IS NOT NULL;
-- Create a hostname index for lease6.
CREATE INDEX lease6_by_hostname ON lease6 (hostname)
WHERE hostname IS NOT NULL;
-- Move to lower case hostnames in lease4 table.
UPDATE lease4 SET hostname = lower(hostname)
WHERE lower(hostname) != hostname;
-- Move to lower case hostnames in lease6 table.
UPDATE lease6 SET hostname = lower(hostname)
WHERE lower(hostname) != hostname;
-- Set 6.0 schema version.
UPDATE schema_version
SET version = '6', minor = '0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment