Repository: mesos Updated Branches: refs/heads/master 288134fb7 -> d1ee9c989
Added tests for 'volume/sandbox_path' isolator. Review: https://reviews.apache.org/r/52318 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d1ee9c98 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d1ee9c98 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d1ee9c98 Branch: refs/heads/master Commit: d1ee9c9895b96ac7fbc39d318609f6dc8ff825de Parents: dc47b38 Author: Jie Yu <yujie....@gmail.com> Authored: Tue Sep 27 14:20:43 2016 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Tue Sep 27 15:38:29 2016 -0700 ---------------------------------------------------------------------- src/Makefile.am | 3 +- .../volume_sandbox_path_isolator_tests.cpp | 159 +++++++++++++++++++ 2 files changed, 161 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/d1ee9c98/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 0fa85b6..fba488f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2166,7 +2166,8 @@ mesos_tests_SOURCES = \ tests/containerizer/provisioner_appc_tests.cpp \ tests/containerizer/provisioner_backend_tests.cpp \ tests/containerizer/provisioner_docker_tests.cpp \ - tests/containerizer/provisioner_paths_tests.cpp + tests/containerizer/provisioner_paths_tests.cpp \ + tests/containerizer/volume_sandbox_path_isolator_tests.cpp if ENABLE_XFS_DISK_ISOLATOR mesos_tests_SOURCES += \ http://git-wip-us.apache.org/repos/asf/mesos/blob/d1ee9c98/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp b/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp new file mode 100644 index 0000000..5105ff2 --- /dev/null +++ b/src/tests/containerizer/volume_sandbox_path_isolator_tests.cpp @@ -0,0 +1,159 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <stout/gtest.hpp> + +#include <process/future.hpp> +#include <process/gtest.hpp> + +#include "tests/environment.hpp" +#include "tests/mesos.hpp" + +using process::Future; +using process::Owned; + +using mesos::internal::slave::Fetcher; +using mesos::internal::slave::MesosContainerizer; + +using mesos::internal::slave::state::SlaveState; + +using mesos::slave::ContainerTermination; + +using std::string; + +namespace mesos { +namespace internal { +namespace tests { + +class VolumeSandboxPathIsolatorTest : public MesosTest {}; + + +// This test verifies that sandbox path volume allows two containers +// nested under the same parent container to share data. +// TODO(jieyu): Parameterize this test to test both linux and posix +// launcher and filesystem isolator. +TEST_F(VolumeSandboxPathIsolatorTest, SharedVolume) +{ + slave::Flags flags = CreateSlaveFlags(); + flags.isolation = "volume/sandbox_path"; + + Fetcher fetcher; + + Try<MesosContainerizer*> create = MesosContainerizer::create( + flags, + true, + &fetcher); + + ASSERT_SOME(create); + + Owned<MesosContainerizer> containerizer(create.get()); + + SlaveState state; + state.id = SlaveID(); + + AWAIT_READY(containerizer->recover(state)); + + ContainerID containerId; + containerId.set_value(UUID::random().toString()); + + ExecutorInfo executor = CREATE_EXECUTOR_INFO("executor", "sleep 1000"); + executor.mutable_resources()->CopyFrom(Resources::parse("cpus:1").get()); + + Try<string> directory = environment->mkdtemp(); + ASSERT_SOME(directory); + + Future<bool> launch = containerizer->launch( + containerId, + None(), + executor, + directory.get(), + None(), + state.id, + map<string, string>(), + true); // TODO(benh): Ever want to check not-checkpointing? + + AWAIT_ASSERT_TRUE(launch); + + ContainerID nestedContainerId1; + nestedContainerId1.mutable_parent()->CopyFrom(containerId); + nestedContainerId1.set_value(UUID::random().toString()); + + ContainerInfo containerInfo; + containerInfo.set_type(ContainerInfo::MESOS); + + Volume* volume = containerInfo.add_volumes(); + volume->set_mode(Volume::RW); + volume->set_container_path("parent"); + + Volume::Source* source = volume->mutable_source(); + source->set_type(Volume::Source::SANDBOX_PATH); + + Volume::Source::SandboxPath* sandboxPath = source->mutable_sandbox_path(); + sandboxPath->set_type(Volume::Source::SandboxPath::PARENT); + sandboxPath->set_path("shared"); + + directory = environment->mkdtemp(); + ASSERT_SOME(directory); + + launch = containerizer->launch( + nestedContainerId1, + CREATE_COMMAND_INFO("touch parent/file; sleep 1000"), + containerInfo, + directory.get(), + None(), + state.id); + + AWAIT_ASSERT_TRUE(launch); + + ContainerID nestedContainerId2; + nestedContainerId2.mutable_parent()->CopyFrom(containerId); + nestedContainerId2.set_value(UUID::random().toString()); + + directory = environment->mkdtemp(); + ASSERT_SOME(directory); + + launch = containerizer->launch( + nestedContainerId2, + CREATE_COMMAND_INFO( + "while true; do if [ -f parent/file ]; then exit 0; fi; done"), + containerInfo, + directory.get(), + None(), + state.id); + + AWAIT_ASSERT_TRUE(launch); + + Future<Option<ContainerTermination>> wait = + containerizer->wait(nestedContainerId2); + + AWAIT_READY(wait); + ASSERT_SOME(wait.get()); + ASSERT_TRUE(wait.get()->has_status()); + EXPECT_WEXITSTATUS_EQ(0, wait.get()->status()); + + wait = containerizer->wait(containerId); + + containerizer->destroy(containerId); + + AWAIT_READY(wait); + ASSERT_SOME(wait.get()); + ASSERT_TRUE(wait.get()->has_status()); + EXPECT_WTERMSIG_EQ(SIGKILL, wait.get()->status()); +} + +} // namespace tests { +} // namespace internal { +} // namespace mesos {