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

bmahler 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 e5ba255f4 [cgroups2] 'cpu.max' parsing fix and introduce a test.
e5ba255f4 is described below

commit e5ba255f44b32e8fade87901634567428ffcab86
Author: Devin Leamy <[email protected]>
AuthorDate: Mon Apr 1 17:13:27 2024 -0400

    [cgroups2] 'cpu.max' parsing fix and introduce a test.
    
    The 'cpu.max' file is terminated by a newline which causes an error
    while parsing. Hence, we trim whitespace before we parse its contents.
    
    A test is also introduced.
    
    This closes #543
---
 src/linux/cgroups2.cpp                     |  2 +-
 src/tests/containerizer/cgroups2_tests.cpp | 32 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index 5241d65c2..27ef3a141 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -499,7 +499,7 @@ Try<BandwidthLimit> parse_bandwidth(const string& content)
   //             is no limit.
   //
   // $PERIOD     Length of one period, in microseconds.
-  vector<string> split = strings::split(content, " ");
+  vector<string> split = strings::split(strings::trim(content), " ");
   if (split.size() != 2) {
     return Error("Expected format '$MAX $PERIOD'"
                  " but received '" + content + "'");
diff --git a/src/tests/containerizer/cgroups2_tests.cpp 
b/src/tests/containerizer/cgroups2_tests.cpp
index 38f062ffb..b3d9dff26 100644
--- a/src/tests/containerizer/cgroups2_tests.cpp
+++ b/src/tests/containerizer/cgroups2_tests.cpp
@@ -41,6 +41,7 @@ using std::string;
 using std::tuple;
 using std::vector;
 
+namespace cpu = cgroups2::cpu;
 namespace devices = cgroups2::devices;
 
 namespace mesos {
@@ -220,6 +221,37 @@ TEST_F(Cgroups2Test, ROOT_CGROUPS2_EnableAndDisable)
   EXPECT_EQ(0u, enabled->count("cpu"));
 }
 
+
+TEST_F(Cgroups2Test, ROOT_CGROUPS2_CpuBandwidthLimit)
+{
+  ASSERT_SOME(enable_controllers({"cpu"}));
+
+  ASSERT_SOME(cgroups2::create(TEST_CGROUP));
+  ASSERT_SOME(cgroups2::controllers::enable(TEST_CGROUP, {"cpu"}));
+
+  Try<cpu::BandwidthLimit> limit = cgroups2::cpu::max(TEST_CGROUP);
+  ASSERT_SOME(limit);
+  EXPECT_NONE(limit->limit); // The default limit is limitless.
+
+  cpu::BandwidthLimit new_limit =
+    cpu::BandwidthLimit(Microseconds(10000), Microseconds(20000));
+  EXPECT_SOME(cgroups2::cpu::set_max(TEST_CGROUP, new_limit));
+
+  limit = cgroups2::cpu::max(TEST_CGROUP);
+  ASSERT_SOME(limit);
+  EXPECT_EQ(new_limit.limit, limit->limit);
+  EXPECT_EQ(new_limit.period, limit->period);
+
+  new_limit = cpu::BandwidthLimit();
+  EXPECT_SOME(cgroups2::cpu::set_max(TEST_CGROUP, new_limit));
+
+  limit = cgroups2::cpu::max(TEST_CGROUP);
+  ASSERT_SOME(limit);
+  EXPECT_EQ(new_limit.limit, limit->limit);
+  EXPECT_EQ(new_limit.period, limit->period);
+}
+
+
 // Arguments for os::open(). Combination of a path and an access type.
 typedef pair<string, int> OpenArgs;
 

Reply via email to