Add filesystem isolator with command executor test. Review: https://reviews.apache.org/r/39258/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0f93a8d6 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0f93a8d6 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0f93a8d6 Branch: refs/heads/master Commit: 0f93a8d6bf8bbe17d6ddb9535f32cb3a8718e7c1 Parents: 6b8d833 Author: Timothy Chen <[email protected]> Authored: Fri Oct 9 12:26:11 2015 -0700 Committer: Timothy Chen <[email protected]> Committed: Thu Nov 5 18:18:59 2015 -0800 ---------------------------------------------------------------------- src/Makefile.am | 1 - .../containerizer/filesystem_isolator_tests.cpp | 187 ++++++++++++------- src/tests/containerizer/provisioner.hpp | 119 ------------ src/tests/containerizer/rootfs.hpp | 3 +- 4 files changed, 126 insertions(+), 184 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0f93a8d6/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index cee8fbf..b92ba15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -902,7 +902,6 @@ libmesos_no_3rdparty_la_SOURCES += \ tests/containerizer/isolator.hpp \ tests/containerizer/launcher.hpp \ tests/containerizer/memory_test_helper.hpp \ - tests/containerizer/provisioner.hpp \ tests/containerizer/rootfs.hpp \ tests/containerizer/setns_test_helper.hpp \ usage/usage.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/0f93a8d6/src/tests/containerizer/filesystem_isolator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp index 39008f6..6e77812 100644 --- a/src/tests/containerizer/filesystem_isolator_tests.cpp +++ b/src/tests/containerizer/filesystem_isolator_tests.cpp @@ -47,19 +47,25 @@ #include "slave/containerizer/mesos/containerizer.hpp" +#include "slave/containerizer/mesos/provisioner/backend.hpp" #include "slave/containerizer/mesos/provisioner/paths.hpp" +#include "slave/containerizer/mesos/provisioner/backends/copy.hpp" + #include "tests/flags.hpp" #include "tests/mesos.hpp" -#include "tests/containerizer/provisioner.hpp" #include "tests/containerizer/rootfs.hpp" +#include "tests/containerizer/store.hpp" using namespace process; using std::string; using std::vector; +using mesos::internal::master::Master; + +using mesos::internal::slave::Backend; using mesos::internal::slave::Fetcher; using mesos::internal::slave::Launcher; #ifdef __linux__ @@ -68,7 +74,9 @@ using mesos::internal::slave::LinuxLauncher; #endif using mesos::internal::slave::MesosContainerizer; using mesos::internal::slave::Provisioner; +using mesos::internal::slave::ProvisionerProcess; using mesos::internal::slave::Slave; +using mesos::internal::slave::Store; using mesos::slave::Isolator; @@ -103,7 +111,28 @@ public: rootfses.put(imageName, rootfs.get().share()); } - Owned<Provisioner> provisioner(new TestProvisioner(rootfses)); + Owned<Store> store(new TestStore(rootfses)); + hashmap<Image::Type, Owned<Store>> stores; + stores[Image::APPC] = store; + + hashmap<string, Owned<Backend>> backends = Backend::create(flags); + + const string rootDir = slave::paths::getProvisionerDir(flags.work_dir); + + if (!os::exists(rootDir)) { + Try<Nothing> mkdir = os::mkdir(rootDir); + if (mkdir.isError()) { + return Error("Failed to create root dir: " + mkdir.isError()); + } + } + + Owned<ProvisionerProcess> provisionerProcess(new ProvisionerProcess( + flags, + rootDir, + stores, + backends)); + + Owned<Provisioner> provisioner(new Provisioner(provisionerProcess)); Try<Isolator*> _isolator = LinuxFilesystemIsolatorProcess::create(flags, provisioner); @@ -195,13 +224,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_ChangeRootFilesystem) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -238,20 +263,96 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_ChangeRootFilesystem) } -TEST_F(LinuxFilesystemIsolatorTest, ROOT_Metrics) +// This test verifies that the root filesystem of the container is +// properly changed to the one that's provisioned by the provisioner. +// Also runs the command executor with the new root filesystem. +TEST_F(LinuxFilesystemIsolatorTest, ROOT_ChangeRootFilesystemCommandExecutor) { + Try<PID<Master>> master = StartMaster(); + ASSERT_SOME(master); + slave::Flags flags = CreateSlaveFlags(); + flags.image_provisioner_backend = "copy"; ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); + Try<Owned<MesosContainerizer>> containerizer = createContainerizer( + flags, + {{"test_image", path::join(os::getcwd(), "test_image")}}); + + ASSERT_SOME(containerizer); + + Try<PID<Slave>> slave = StartSlave(containerizer.get().get(), flags); + ASSERT_SOME(slave); + + MockScheduler sched; + MesosSchedulerDriver driver( + &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); + + Future<FrameworkID> frameworkId; + EXPECT_CALL(sched, registered(&driver, _, _)) + .WillOnce(FutureArg<1>(&frameworkId)); + + Future<vector<Offer>> offers; + EXPECT_CALL(sched, resourceOffers(&driver, _)) + .WillOnce(FutureArg<1>(&offers)) + .WillRepeatedly(Return()); // Ignore subsequent offers. + + driver.start(); + + AWAIT_READY(frameworkId); + + AWAIT_READY(offers); + ASSERT_NE(0u, offers.get().size()); + + const Offer& offer = offers.get()[0]; + + SlaveID slaveId = offer.slave_id(); + + TaskInfo task = createTask( + offer.slave_id(), + offer.resources(), + "test -d " + flags.sandbox_directory); + + ContainerInfo containerInfo; + Image* image = containerInfo.mutable_mesos()->mutable_image(); + image->set_type(Image::APPC); + image->mutable_appc()->set_name("test_image"); + containerInfo.set_type(ContainerInfo::MESOS); + task.mutable_container()->CopyFrom(containerInfo); + + driver.launchTasks(offers.get()[0].id(), {task}); + + Future<TaskStatus> statusRunning; + Future<TaskStatus> statusFinished; + + EXPECT_CALL(sched, statusUpdate(&driver, _)) + .WillOnce(FutureArg<1>(&statusRunning)) + .WillOnce(FutureArg<1>(&statusFinished)); + + AWAIT_READY(statusRunning); + EXPECT_EQ(TASK_RUNNING, statusRunning.get().state()); + AWAIT_READY(statusFinished); + EXPECT_EQ(TASK_FINISHED, statusFinished.get().state()); + + driver.stop(); + driver.join(); + + Shutdown(); +} + + +TEST_F(LinuxFilesystemIsolatorTest, ROOT_Metrics) +{ + slave::Flags flags = CreateSlaveFlags(); + + ContainerID containerId; + containerId.set_value(UUID::random().toString()); Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -308,13 +409,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromSandbox) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -365,13 +462,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHost) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -420,13 +513,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHostSandboxMountPoint) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -478,13 +567,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_PersistentVolumeWithRootFilesystem) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -548,13 +633,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_PersistentVolumeWithoutRootFilesystem) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -623,13 +704,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_ImageInVolumeWithoutRootFilesystem) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); @@ -678,15 +755,11 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_ImageInVolumeWithRootFilesystem) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image_rootfs", path::join(rootfsesDir, "test_image_rootfs")}, - {"test_image_volume", path::join(rootfsesDir, "test_image_volume")}}); + {{"test_image_rootfs", path::join(os::getcwd(), "test_image_rootfs")}, + {"test_image_volume", path::join(os::getcwd(), "test_image_volume")}}); ASSERT_SOME(containerizer); @@ -741,19 +814,11 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_MultipleContainers) ContainerID containerId2; containerId2.set_value(UUID::random().toString()); - string rootfsesDir1 = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId1); - - string rootfsesDir2 = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId2); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image1", path::join(rootfsesDir1, "test_image1")}, - {"test_image2", path::join(rootfsesDir2, "test_image2")}}); + {{"test_image1", path::join(os::getcwd(), "test_image1")}, + {"test_image2", path::join(os::getcwd(), "test_image2")}}); ASSERT_SOME(containerizer); @@ -859,13 +924,9 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_SandboxEnvironmentVariable) ContainerID containerId; containerId.set_value(UUID::random().toString()); - string rootfsesDir = slave::provisioner::paths::getContainerDir( - slave::paths::getProvisionerDir(flags.work_dir), - containerId); - Try<Owned<MesosContainerizer>> containerizer = createContainerizer( flags, - {{"test_image", path::join(rootfsesDir, "test_image")}}); + {{"test_image", path::join(os::getcwd(), "test_image")}}); ASSERT_SOME(containerizer); http://git-wip-us.apache.org/repos/asf/mesos/blob/0f93a8d6/src/tests/containerizer/provisioner.hpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/provisioner.hpp b/src/tests/containerizer/provisioner.hpp deleted file mode 100644 index 507e141..0000000 --- a/src/tests/containerizer/provisioner.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/** - * 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. - */ - -#ifndef __TEST_PROVISIONER_HPP__ -#define __TEST_PROVISIONER_HPP__ - -#include <gmock/gmock.h> - -#include <process/shared.hpp> - -#include <stout/hashmap.hpp> -#include <stout/stringify.hpp> - -#include "slave/containerizer/mesos/provisioner/provisioner.hpp" - -#include "tests/containerizer/rootfs.hpp" - -namespace mesos { -namespace internal { -namespace tests { - -class TestProvisioner : public slave::Provisioner -{ -public: - TestProvisioner( - const hashmap<std::string, process::Shared<Rootfs>>& _rootfses) - : rootfses(_rootfses) - { - using testing::_; - using testing::DoDefault; - using testing::Invoke; - - ON_CALL(*this, recover(_, _)) - .WillByDefault(Invoke(this, &TestProvisioner::unmocked_recover)); - EXPECT_CALL(*this, recover(_, _)) - .WillRepeatedly(DoDefault()); - - ON_CALL(*this, provision(_, _)) - .WillByDefault(Invoke(this, &TestProvisioner::unmocked_provision)); - EXPECT_CALL(*this, provision(_, _)) - .WillRepeatedly(DoDefault()); - - ON_CALL(*this, destroy(_)) - .WillByDefault(Invoke(this, &TestProvisioner::unmocked_destroy)); - EXPECT_CALL(*this, destroy(_)) - .WillRepeatedly(DoDefault()); - } - - MOCK_METHOD2( - recover, - process::Future<Nothing>( - const std::list<mesos::slave::ContainerState>& states, - const hashset<ContainerID>& orphans)); - - MOCK_METHOD2( - provision, - process::Future<std::string>( - const ContainerID& containerId, - const Image& image)); - - MOCK_METHOD1( - destroy, - process::Future<bool>( - const ContainerID& containerId)); - - process::Future<Nothing> unmocked_recover( - const std::list<mesos::slave::ContainerState>& states, - const hashset<ContainerID>& orphans) - { - return Nothing(); - } - - process::Future<std::string> unmocked_provision( - const ContainerID& containerId, - const Image& image) - { - if (image.type() != Image::APPC) { - return process::Failure( - "Unsupported image type '" + stringify(image.type()) + "'"); - } - - if (!rootfses.contains(image.appc().name())) { - return process::Failure( - "Image '" + image.appc().name() + "' is not found"); - } - - return rootfses[image.appc().name()]->root; - } - - process::Future<bool> unmocked_destroy( - const ContainerID& containerId) - { - return true; - } - -private: - hashmap<std::string, process::Shared<Rootfs>> rootfses; -}; - -} // namespace tests { -} // namespace internal { -} // namespace mesos { - -#endif // __TEST_PROVISIONER_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/0f93a8d6/src/tests/containerizer/rootfs.hpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/rootfs.hpp b/src/tests/containerizer/rootfs.hpp index 56a205f..2d3dbc4 100644 --- a/src/tests/containerizer/rootfs.hpp +++ b/src/tests/containerizer/rootfs.hpp @@ -105,7 +105,8 @@ public: std::vector<std::string> directories = { "/bin", "/lib", - "/lib64" + "/lib64", + "/etc" }; foreach (const std::string& directory, directories) {
