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

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

commit 848c622bef15c0f2aa9d3ea9cb30bae401ea7ca7
Author: Qian Zhang <[email protected]>
AuthorDate: Thu Mar 7 16:41:56 2019 -0800

    Verified volume gid manager's metrics in the related tests.
    
    Review: https://reviews.apache.org/r/70113/
---
 .../linux_filesystem_isolator_tests.cpp            | 24 ++++++++++++
 .../containerizer/volume_gid_manager_tests.cpp     | 44 ++++++++++++++++++++++
 .../volume_sandbox_path_isolator_tests.cpp         | 33 ++++++++++++++++
 src/tests/default_executor_tests.cpp               | 26 +++++++++++++
 src/tests/persistent_volume_tests.cpp              | 24 ++++++++++++
 5 files changed, 151 insertions(+)

diff --git a/src/tests/containerizer/linux_filesystem_isolator_tests.cpp 
b/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
index d32bf74..13e51d4 100644
--- a/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
@@ -65,6 +65,16 @@ using mesos::master::detector::MasterDetector;
 using mesos::slave::ContainerTermination;
 using mesos::slave::Isolator;
 
+namespace process {
+
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -1313,6 +1323,11 @@ TEST_F(LinuxFilesystemIsolatorMesosTest,
 TEST_F(LinuxFilesystemIsolatorMesosTest,
        ROOT_UNPRIVILEGED_USER_SharedPersistentVolume)
 {
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
@@ -1404,6 +1419,15 @@ TEST_F(LinuxFilesystemIsolatorMesosTest,
   EXPECT_EQ(task.task_id(), statusFinished->task_id());
   EXPECT_EQ(TASK_FINISHED, statusFinished->state());
 
+  // One gid should have been allocated to the volume. Please note that shared
+  // persistent volume's gid will be deallocated only when it is destroyed.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   driver.stop();
   driver.join();
 }
diff --git a/src/tests/containerizer/volume_gid_manager_tests.cpp 
b/src/tests/containerizer/volume_gid_manager_tests.cpp
index 129e701..6fc3205 100644
--- a/src/tests/containerizer/volume_gid_manager_tests.cpp
+++ b/src/tests/containerizer/volume_gid_manager_tests.cpp
@@ -46,6 +46,16 @@ using std::vector;
 using testing::AtMost;
 using testing::DoAll;
 
+namespace process {
+
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -91,6 +101,11 @@ TEST_F(VolumeGidManagerTest, ROOT_Flag)
 // volume will only be allocated with gid once rather than twice.
 TEST_F(VolumeGidManagerTest, ROOT_UNPRIVILEGED_USER_GidReused)
 {
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
@@ -192,6 +207,14 @@ TEST_F(VolumeGidManagerTest, 
ROOT_UNPRIVILEGED_USER_GidReused)
   EXPECT_EQ(task.task_id(), statusRunning->task_id());
   EXPECT_EQ(TASK_RUNNING, statusRunning->state());
 
+  // One gid should have been allocated to the volume.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   string volumePath =
     slave::paths::getPersistentVolumePath(flags.work_dir, volume);
 
@@ -225,6 +248,14 @@ TEST_F(VolumeGidManagerTest, 
ROOT_UNPRIVILEGED_USER_GidReused)
   EXPECT_EQ(task.task_id(), statusRunning->task_id());
   EXPECT_EQ(TASK_RUNNING, statusRunning->state());
 
+  // Still one gid is allocated.
+  metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   // The owner group of the volume should still be the
   // one allocated when the first task was launched.
   EXPECT_EQ(0, ::stat(volumePath.c_str(), &s));
@@ -244,6 +275,11 @@ TEST_F(VolumeGidManagerTest, 
ROOT_UNPRIVILEGED_USER_GidReused)
 // volume will be changed back to the original one.
 TEST_F(VolumeGidManagerTest, ROOT_UNPRIVILEGED_USER_SlaveRecovery)
 {
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
@@ -376,6 +412,14 @@ TEST_F(VolumeGidManagerTest, 
ROOT_UNPRIVILEGED_USER_SlaveRecovery)
 
   AWAIT_READY(ackRunning);
 
+  // One gid should have been allocated to the volume.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   string executorSandbox = slave::paths::getExecutorLatestRunPath(
       flags.work_dir,
       devolve(agentId),
diff --git a/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp 
b/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp
index 9238d58..dc50a26 100644
--- a/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp
+++ b/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp
@@ -49,6 +49,18 @@ using mesos::internal::slave::state::SlaveState;
 
 using mesos::slave::ContainerTermination;
 
+#ifdef __linux__
+namespace process {
+
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+#endif // __linux__
+
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -441,6 +453,11 @@ TEST_F(VolumeSandboxPathIsolatorTest,
 TEST_F(VolumeSandboxPathIsolatorTest,
        ROOT_UNPRIVILEGED_USER_ParentTypeDifferentUser)
 {
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   slave::Flags flags = CreateSlaveFlags();
   flags.isolation = "filesystem/linux,volume/sandbox_path";
   flags.volume_gid_range = "[10000-20000]";
@@ -534,6 +551,14 @@ TEST_F(VolumeSandboxPathIsolatorTest,
   ASSERT_TRUE(wait.get()->has_status());
   EXPECT_WEXITSTATUS_EQ(0, wait.get()->status());
 
+  // One gid should have been allocated to the volume.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   string volumePath = path::join(directory.get(), "shared");
 
   // The owner group of the volume should be changed to the gid allocated
@@ -550,6 +575,14 @@ TEST_F(VolumeSandboxPathIsolatorTest,
   ASSERT_TRUE(termination.get()->has_status());
   EXPECT_WTERMSIG_EQ(SIGKILL, termination.get()->status());
 
+  // The gid allocated to the volume should have been deallocated.
+  metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>(),
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   // The owner group of the volume should be changed back to
   // the original one, i.e., root.
   EXPECT_EQ(0, ::stat(volumePath.c_str(), &s));
diff --git a/src/tests/default_executor_tests.cpp 
b/src/tests/default_executor_tests.cpp
index 045e211..7d7b113 100644
--- a/src/tests/default_executor_tests.cpp
+++ b/src/tests/default_executor_tests.cpp
@@ -84,6 +84,18 @@ using mesos::internal::slave::Slave;
 
 using mesos::slave::ContainerTermination;
 
+#ifndef __WINDOWS__
+namespace process {
+
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+#endif // __WINDOWS__
+
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -3312,6 +3324,11 @@ TEST_P(
     return;
   }
 
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
@@ -3435,6 +3452,15 @@ TEST_P(
   AWAIT_READY(updateFinished);
   ASSERT_EQ(v1::TASK_FINISHED, updateFinished->status().state());
   ASSERT_EQ(taskInfo.task_id(), updateFinished->status().task_id());
+
+  // One gid should have been allocated to the volume. Please note that shared
+  // persistent volume's gid will be deallocated only when it is destroyed.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
 }
 #endif // __WINDOWS__
 
diff --git a/src/tests/persistent_volume_tests.cpp 
b/src/tests/persistent_volume_tests.cpp
index 8a5672e..b62e455 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -81,6 +81,16 @@ using testing::DoAll;
 using testing::Return;
 using testing::WithParamInterface;
 
+namespace process {
+
+void reinitialize(
+    const Option<string>& delegate,
+    const Option<string>& readonlyAuthenticationRealm,
+    const Option<string>& readwriteAuthenticationRealm);
+
+} // namespace process {
+
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -2506,6 +2516,11 @@ TEST_P(PersistentVolumeTest, 
SharedPersistentVolumeMultipleFrameworks)
 // `filesystem/posix` isolator.
 TEST_P(PersistentVolumeTest, UNPRIVILEGED_USER_SharedPersistentVolume)
 {
+  // Reinitialize libprocess to ensure volume gid manager's metrics
+  // can be added in each iteration of this test (i.e., run this test
+  // repeatedly with the `--gtest_repeat` option).
+  process::reinitialize(None(), None(), None());
+
   Clock::pause();
 
   master::Flags masterFlags = CreateMasterFlags();
@@ -2606,6 +2621,15 @@ TEST_P(PersistentVolumeTest, 
UNPRIVILEGED_USER_SharedPersistentVolume)
   AWAIT_READY(status2);
   EXPECT_EQ(TASK_FINISHED, status2->state());
 
+  // One gid should have been allocated to the volume. Please note that shared
+  // persistent volume's gid will be deallocated only when it is destroyed.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_total")
+        ->as<int>() - 1,
+      metrics.at<JSON::Number>("volume_gid_manager/volume_gids_free")
+        ->as<int>());
+
   // Resume the clock so the terminating task and executor can be reaped.
   Clock::resume();
 

Reply via email to