]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5651] Renamed count to limit for leaseX-get-page command.
authorMarcin Siodelski <marcin@isc.org>
Thu, 28 Jun 2018 12:19:08 +0000 (14:19 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 28 Jun 2018 12:19:08 +0000 (14:19 +0200)
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.cc

index e1a1e9056a403cbf342e59bf3d589fb8e23683c2..4d24546df9b2bf2f2ffe4bc1ce521a0e402f7962 100644 (file)
@@ -624,34 +624,27 @@ LeaseCmdsImpl::leaseGetPageHandler(CalloutHandle& handle) {
                       << " is not an IPv6 address");
         }
 
-        // The 'count' is a desired page size. It must always be present.
-        ConstElementPtr page_count = cmd_args_->get("count");
-        if (!page_count) {
-            isc_throw(BadValue, "'count' parameter not specified");
+        // The 'limit' is a desired page size. It must always be present.
+        ConstElementPtr page_limit = cmd_args_->get("limit");
+        if (!page_limit) {
+            isc_throw(BadValue, "'limit' parameter not specified");
         }
 
-        // The 'count' must be a number.
-        if (page_count->getType() != Element::integer) {
-            isc_throw(BadValue, "'count' parameter must be a number");
+        // The 'limit' must be a number.
+        if (page_limit->getType() != Element::integer) {
+            isc_throw(BadValue, "'limit' parameter must be a number");
         }
 
         // Retrieve the desired page size.
-        size_t page_count_value = static_cast<size_t>(page_count->intValue());
+        size_t page_limit_value = static_cast<size_t>(page_limit->intValue());
 
         ElementPtr leases_json = Element::createList();
 
-        // Use lease stats function to retrieve the total number of leases.
-        // Total number of leases is returned apart from the leases list
-        // so as the controlling client can track the progress of leases
-        // viewed vs all leases count.
-        LeaseStatsQueryPtr query;
         if (v4) {
             // Get page of IPv4 leases.
             Lease4Collection leases =
                 LeaseMgrFactory::instance().getLeases4(*from_address,
-                                                       LeasePageSize(page_count_value));
-            // Get the total lease count.
-            query = LeaseMgrFactory::instance().startLeaseStatsQuery4();
+                                                       LeasePageSize(page_limit_value));
 
             // Convert leases into JSON list.
             for (auto lease : leases) {
@@ -663,10 +656,7 @@ LeaseCmdsImpl::leaseGetPageHandler(CalloutHandle& handle) {
             // Get page of IPv6 leases.
             Lease6Collection leases =
                 LeaseMgrFactory::instance().getLeases6(*from_address,
-                                                       LeasePageSize(page_count_value));
-            // Get the total lease count.
-            query = LeaseMgrFactory::instance().startLeaseStatsQuery6();
-
+                                                       LeasePageSize(page_limit_value));
             // Convert leases into JSON list.
             for (auto lease : leases) {
                 ElementPtr lease_json = lease->toElement();
@@ -674,13 +664,6 @@ LeaseCmdsImpl::leaseGetPageHandler(CalloutHandle& handle) {
             }
         }
 
-        // Sum up lease counters for various lease states.
-        LeaseStatsRow row;
-        int64_t total_leases = 0;
-        while (query->getNextRow(row)) {
-            total_leases += row.state_count_;
-        }
-
         // Prepare textual status.
         std::ostringstream s;
         s << leases_json->size()
index bf9eb6c1039125aa5d105b18d57bf1062a5357c0..630a6d3ae9a92cf13deddcc1c243772fe070aa5a 100644 (file)
@@ -1613,7 +1613,7 @@ TEST_F(LeaseCmdsTest, Lease4GetPaged) {
             "    \"command\": \"lease4-get-page\",\n"
             "    \"arguments\": {"
             "        \"from\": \"" + last_address + "\","
-            "        \"count\": 2"
+            "        \"limit\": 2"
             "    }"
             "}";
 
@@ -1697,7 +1697,7 @@ TEST_F(LeaseCmdsTest, Lease4GetPagedZeroAddress) {
         "    \"command\": \"lease4-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"0.0.0.0\","
-        "        \"count\": 2"
+        "        \"limit\": 2"
         "    }"
         "}";
 
@@ -1717,7 +1717,7 @@ TEST_F(LeaseCmdsTest, Lease4GetPagedIPv4Address) {
         "    \"command\": \"lease4-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"2001:db8::1\","
-        "        \"count\": 2"
+        "        \"limit\": 2"
         "    }"
         "}";
 
@@ -1948,7 +1948,7 @@ TEST_F(LeaseCmdsTest, Lease6GetPaged) {
             "    \"command\": \"lease6-get-page\",\n"
             "    \"arguments\": {"
             "        \"from\": \"" + last_address + "\","
-            "        \"count\": 2"
+            "        \"limit\": 2"
             "    }"
             "}";
 
@@ -2033,7 +2033,7 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedZeroAddress) {
         "    \"command\": \"lease6-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"::\","
-        "        \"count\": 2"
+        "        \"limit\": 2"
         "    }"
         "}";
 
@@ -2053,7 +2053,7 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedIPv4Address) {
         "    \"command\": \"lease6-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"192.0.2.3\","
-        "        \"count\": 2"
+        "        \"limit\": 2"
         "    }"
         "}";
 
@@ -2074,7 +2074,7 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedInvalidFrom) {
         "    \"command\": \"lease6-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"foo\","
-        "        \"count\": 2"
+        "        \"limit\": 2"
         "    }"
         "}";
 
@@ -2083,8 +2083,8 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedInvalidFrom) {
     testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
 }
 
-// Verifies that count is mandatory.
-TEST_F(LeaseCmdsTest, Lease6GetPagedNoCount) {
+// Verifies that limit is mandatory.
+TEST_F(LeaseCmdsTest, Lease6GetPagedNoLimit) {
 
     // Initialize lease manager (true = v6, true = add a lease)
     initLeaseMgr(true, true);
@@ -2098,12 +2098,12 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedNoCount) {
         "    }"
         "}";
 
-    string exp_rsp = "'count' parameter not specified";
+    string exp_rsp = "'limit' parameter not specified";
     testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
 }
 
-// Verifies that the count must be a number.
-TEST_F(LeaseCmdsTest, Lease6GetPagedCountNotNumber) {
+// Verifies that the limit must be a number.
+TEST_F(LeaseCmdsTest, Lease6GetPagedLimitNotNumber) {
 
     // Initialize lease manager (true = v6, true = add a lease)
     initLeaseMgr(true, true);
@@ -2114,16 +2114,16 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedCountNotNumber) {
         "    \"command\": \"lease6-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"start\","
-        "        \"count\": false"
+        "        \"limit\": false"
         "    }"
         "}";
 
-    string exp_rsp = "'count' parameter must be a number";
+    string exp_rsp = "'limit' parameter must be a number";
     testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
 }
 
-// Verifies that the count of 0 is rejected.
-TEST_F(LeaseCmdsTest, Lease6GetPagedCountIsZero) {
+// Verifies that the limit of 0 is rejected.
+TEST_F(LeaseCmdsTest, Lease6GetPagedLimitIsZero) {
 
     // Initialize lease manager (true = v6, true = add a lease)
     initLeaseMgr(true, true);
@@ -2134,7 +2134,7 @@ TEST_F(LeaseCmdsTest, Lease6GetPagedCountIsZero) {
         "    \"command\": \"lease6-get-page\",\n"
         "    \"arguments\": {"
         "        \"from\": \"start\","
-        "        \"count\": 0"
+        "        \"limit\": 0"
         "    }"
         "}";