This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new c55053a  Fixed an issue where master quota state is not updated.
c55053a is described below

commit c55053a5985c3974572ceb066e8b789fae55a1d8
Author: Meng Zhu <[email protected]>
AuthorDate: Tue Jul 16 14:20:43 2019 -0700

    Fixed an issue where master quota state is not updated.
    
    Also added a regression test.
    
    Review: https://reviews.apache.org/r/71086
---
 src/master/quota_handler.cpp     |  1 +
 src/tests/master_quota_tests.cpp | 70 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index 13789d8..2a3ca56 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -555,6 +555,7 @@ Future<http::Response> Master::QuotaHandler::_update(
       CHECK(result);
 
       foreach (const QuotaConfig& config, configs) {
+        master->quotas[config.role()] = Quota(config);
         master->allocator->updateQuota(config.role(), Quota{config});
       }
 
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index a1b3769..64a9b31 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -197,6 +197,76 @@ protected:
 };
 
 
+TEST_F(MasterQuotaTest, UpdateQuota)
+{
+  TestAllocator<> allocator;
+  EXPECT_CALL(allocator, initialize(_, _, _));
+
+  Try<Owned<cluster::Master>> master = StartMaster(&allocator);
+  ASSERT_SOME(master);
+
+  process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL);
+  headers["Content-Type"] = "application/json";
+
+  // Use force flag to update the quota.
+  Future<Response> response = process::http::post(
+      master.get()->pid,
+      "/api/v1",
+      headers,
+      createUpdateQuotaRequestBody(
+          createQuotaConfig(
+              ROLE1,
+              stringify("cpus:1;mem:1024"),
+              stringify("cpus:2;mem:2048")),
+          true));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+
+  response = process::http::get(
+      master.get()->pid,
+      "roles",
+      None(),
+      createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+
+  Try<JSON::Value> parse = JSON::parse(response->body);
+  ASSERT_SOME(parse);
+
+  Try<JSON::Value> expected = JSON::parse(
+      "{"
+      "  \"roles\": ["
+      "    {"
+      "      \"frameworks\": [],"
+      "      \"name\": \"role1\","
+      "      \"resources\": {},"
+      "      \"allocated\": {},"
+      "      \"offered\": {},"
+      "      \"reserved\": {},"
+      "      \"quota\": {"
+      "        \"consumed\": {},"
+      "        \"limit\": {"
+      "          \"cpus\": 2.0,"
+      "          \"mem\":  2048.0"
+      "        },"
+      "        \"guarantee\": {"
+      "          \"cpus\": 1.0,"
+      "          \"mem\":  1024.0"
+      "        },"
+      "        \"role\": \"role1\""
+      "      },"
+      "      \"weight\": 1.0"
+      "    }"
+      "  ]"
+      "}");
+
+  ASSERT_SOME(expected);
+
+  EXPECT_EQ(*expected, *parse) << "expected " << stringify(*expected)
+                               << " vs actual " << stringify(*parse);
+}
+
+
 // These are request validation tests. They verify JSON is well-formed,
 // convertible to corresponding protobufs, all necessary fields are present,
 // while irrelevant fields are not present.

Reply via email to