mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject [4/4] mesos git commit: Added unit-test for dynamic addition/deletion of CNI config.
Date Thu, 22 Dec 2016 01:51:08 GMT
Added unit-test for dynamic addition/deletion of CNI config.

Review: https://reviews.apache.org/r/54880/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e6005743
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e6005743
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e6005743

Branch: refs/heads/master
Commit: e6005743ea247f381c055dce2e875730b07a3864
Parents: f74d9a1
Author: Avinash sridharan <avinash@mesosphere.io>
Authored: Wed Dec 21 15:02:55 2016 -0800
Committer: Jie Yu <yujie.jay@gmail.com>
Committed: Wed Dec 21 17:50:57 2016 -0800

----------------------------------------------------------------------
 src/tests/containerizer/cni_isolator_tests.cpp | 168 ++++++++++++++++++++
 1 file changed, 168 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e6005743/src/tests/containerizer/cni_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cni_isolator_tests.cpp b/src/tests/containerizer/cni_isolator_tests.cpp
index eb19407..82697ae 100644
--- a/src/tests/containerizer/cni_isolator_tests.cpp
+++ b/src/tests/containerizer/cni_isolator_tests.cpp
@@ -16,6 +16,8 @@
 
 #include <gmock/gmock.h>
 
+#include <process/clock.hpp>
+
 #include <stout/ip.hpp>
 
 #include "slave/containerizer/fetcher.hpp"
@@ -35,6 +37,7 @@ using mesos::internal::slave::MesosContainerizer;
 
 using mesos::master::detector::MasterDetector;
 
+using process::Clock;
 using process::Future;
 using process::Owned;
 
@@ -682,6 +685,171 @@ TEST_F(CniIsolatorTest, ROOT_INTERNET_CURL_LaunchContainerInHostNetwork)
   driver.join();
 }
 
+
+// This tests the dynamic addition and deletion of CNI configuration
+// without the need to restart the agent.
+TEST_F(CniIsolatorTest, ROOT_DynamicAddDelofCniConfig)
+{
+  master::Flags masterFlags = CreateMasterFlags();
+
+  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
+  ASSERT_SOME(master);
+
+  slave::Flags slaveFlags = CreateSlaveFlags();
+
+  slaveFlags.network_cni_plugins_dir = cniPluginDir;
+  slaveFlags.network_cni_config_dir = cniConfigDir;
+
+  Try<string> mockCniConfig = os::read(path::join(cniConfigDir, "mockConfig"));
+  ASSERT_SOME(mockCniConfig);
+
+  // Remove the CNI config.
+  Try<Nothing> rm = os::rm(path::join(cniConfigDir, "mockConfig"));
+  ASSERT_SOME(rm);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+
+  // We use the filter explicitly here so that the resources will not
+  // be filtered for 5 seconds (the default).
+  Filters filters;
+  filters.set_refuse_seconds(0);
+
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+
+  MesosSchedulerDriver driver(
+      &sched,
+      frameworkInfo,
+      master.get()->pid,
+      DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(_, _, _));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(DeclineOffers()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  ASSERT_EQ(1u, offers->size());
+
+  const Offer& offer1 = offers.get()[0];
+
+  CommandInfo command = createCommandInfo("sleep 1000");
+
+  TaskInfo task = createTask(
+      offer1.slave_id(),
+      Resources::parse("cpus:0.1;mem:128").get(),
+      command);
+
+  ContainerInfo* container = task.mutable_container();
+  container->set_type(ContainerInfo::MESOS);
+
+  // Make sure the container is not able to join mock CNI network.
+  container->add_network_infos()->set_name("__MESOS_TEST__");
+
+  Future<TaskStatus> statusFailed;
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusFailed));
+
+  driver.launchTasks(offer1.id(), {task}, filters);
+
+  AWAIT_READY_FOR(statusFailed, Seconds(60));
+  EXPECT_EQ(task.task_id(), statusFailed->task_id());
+  EXPECT_EQ(TASK_FAILED, statusFailed->state());
+
+  // Now add the CNI config back. This would dynamically add the CNI
+  // network to the `network/cni` isolator, and try launching a task
+  // on this CNI network.
+  Try<Nothing> write = os::write(
+      path::join(cniConfigDir, "mockConfig"),
+      mockCniConfig.get());
+
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(DeclineOffers()); // Ignore subsequent offers.
+
+  Clock::pause();
+  Clock::advance(masterFlags.allocation_interval);
+  Clock::settle();
+  Clock::resume();
+
+  AWAIT_READY(offers);
+  ASSERT_EQ(1u, offers->size());
+
+  const Offer& offer2 = offers.get()[0];
+
+  task = createTask(
+      offer2.slave_id(),
+      Resources::parse("cpus:0.1;mem:128").get(),
+      command);
+
+  container = task.mutable_container();
+  container->set_type(ContainerInfo::MESOS);
+
+  // Make sure the container is able to join mock CNI network.
+  container->add_network_infos()->set_name("__MESOS_TEST__");
+
+  Future<TaskStatus> statusRunning;
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusRunning));
+
+  driver.launchTasks(offer2.id(), {task}, filters);
+
+  AWAIT_READY_FOR(statusRunning, Seconds(60));
+  EXPECT_EQ(task.task_id(), statusRunning->task_id());
+  EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+  // Testing dynamic deletion of CNI networks.
+  rm = os::rm(path::join(cniConfigDir, "mockConfig"));
+  ASSERT_SOME(rm);
+
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(DeclineOffers()); // Ignore subsequent offers.
+
+  Clock::pause();
+  Clock::advance(Seconds(10));
+  Clock::settle();
+  Clock::resume();
+
+  // Try launching the task on the `__MESOS_TEST__` network, it should
+  // fail because the network config has been deleted.
+  AWAIT_READY(offers);
+  ASSERT_EQ(1u, offers->size());
+
+  const Offer& offer3 = offers.get()[0];
+
+  task = createTask(
+      offer3.slave_id(),
+      Resources::parse("cpus:0.1;mem:128").get(),
+      command);
+
+  container = task.mutable_container();
+  container->set_type(ContainerInfo::MESOS);
+
+  // Make sure the container is not able to join mock CNI network.
+  container->add_network_infos()->set_name("__MESOS_TEST__");
+
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusFailed));
+
+  driver.launchTasks(offer3.id(), {task}, filters);
+
+  AWAIT_READY_FOR(statusFailed, Seconds(60));
+  EXPECT_EQ(task.task_id(), statusFailed->task_id());
+  EXPECT_EQ(TASK_FAILED, statusFailed->state());
+
+  driver.stop();
+  driver.join();
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


Mime
View raw message