TemporaryDirectoryTest Merge: Remove non-Stout version of `TemporaryDirectoryTest`.
The special cleanup in the non-Stout `TemporaryDirectoryTest` was moved into `LinuxFilesystemIsolatorTest`. `LinuxFilesystemIsolatorTest` creates additional mounts as part of its tests. No other tests require the special cleanup logic to pass. Review: https://reviews.apache.org/r/40001 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5f8c7dc0 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5f8c7dc0 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5f8c7dc0 Branch: refs/heads/master Commit: 5f8c7dc0918204d234698a1f963244e3f6d05d39 Parents: 2d06679 Author: Joseph Wu <[email protected]> Authored: Fri Nov 6 16:15:10 2015 -0800 Committer: Jie Yu <[email protected]> Committed: Fri Nov 6 16:46:39 2015 -0800 ---------------------------------------------------------------------- .../containerizer/filesystem_isolator_tests.cpp | 23 +++++++- src/tests/utils.cpp | 60 -------------------- src/tests/utils.hpp | 20 ------- 3 files changed, 21 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5f8c7dc0/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 f1ab98a..7032095 100644 --- a/src/tests/containerizer/filesystem_isolator_tests.cpp +++ b/src/tests/containerizer/filesystem_isolator_tests.cpp @@ -85,9 +85,28 @@ namespace internal { namespace tests { #ifdef __linux__ -class LinuxFilesystemIsolatorTest: public MesosTest +class LinuxFilesystemIsolatorTest : public MesosTest { -public: +protected: + virtual void TearDown() + { + // Try to remove any mounts under sandbox. + if (::geteuid() == 0) { + Try<string> umount = os::shell( + "grep '%s' /proc/mounts | " + "cut -d' ' -f2 | " + "xargs --no-run-if-empty umount -l", + sandbox.get().c_str()); + + if (umount.isError()) { + LOG(ERROR) << "Failed to umount for sandbox '" << sandbox.get() + << "': " << umount.error(); + } + } + + MesosTest::TearDown(); + } + // This helper creates a MesosContainerizer instance that uses the // LinuxFilesystemIsolator. The filesystem isolator takes a // TestAppcProvisioner which provisions APPC images by copying files http://git-wip-us.apache.org/repos/asf/mesos/blob/5f8c7dc0/src/tests/utils.cpp ---------------------------------------------------------------------- diff --git a/src/tests/utils.cpp b/src/tests/utils.cpp index cc3e9e9..0578e63 100644 --- a/src/tests/utils.cpp +++ b/src/tests/utils.cpp @@ -16,10 +16,6 @@ * limitations under the License. */ -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> - #include <gtest/gtest.h> #include <process/future.hpp> @@ -29,70 +25,14 @@ #include <process/process.hpp> #include <stout/gtest.hpp> -#include <stout/os.hpp> -#include <stout/path.hpp> -#include <stout/strings.hpp> -#include "tests/environment.hpp" #include "tests/flags.hpp" #include "tests/utils.hpp" -using std::string; - namespace mesos { namespace internal { namespace tests { -void TemporaryDirectoryTest::SetUp() -{ - // Save the current working directory. - cwd = os::getcwd(); - - // Create a temporary directory for the test. - Try<string> directory = environment->mkdtemp(); - - ASSERT_SOME(directory) << "Failed to mkdtemp"; - - sandbox = directory.get(); - - if (flags.verbose) { - std::cout << "Using temporary directory '" - << sandbox.get() << "'" << std::endl; - } - - // Run the test out of the temporary directory we created. - ASSERT_SOME(os::chdir(sandbox.get())) - << "Failed to chdir into '" << sandbox.get() << "'"; -} - - -void TemporaryDirectoryTest::TearDown() -{ - // Return to previous working directory and cleanup the sandbox. - ASSERT_SOME(os::chdir(cwd)); - - if (sandbox.isSome()) { -#ifdef __linux__ - // Try to remove any mounts under sandbox. - if (::geteuid() == 0) { - Try<string> umount = os::shell( - "grep '%s' /proc/mounts | " - "cut -d' ' -f2 | " - "xargs --no-run-if-empty umount -l", - sandbox.get().c_str()); - - if (umount.isError()) { - LOG(ERROR) << "Failed to umount for sandbox '" << sandbox.get() - << "': " << umount.error(); - } - } -#endif - - ASSERT_SOME(os::rmdir(sandbox.get())); - } -} - - JSON::Object Metrics() { process::UPID upid("metrics", process::address()); http://git-wip-us.apache.org/repos/asf/mesos/blob/5f8c7dc0/src/tests/utils.hpp ---------------------------------------------------------------------- diff --git a/src/tests/utils.hpp b/src/tests/utils.hpp index d4fc6ac..1497013 100644 --- a/src/tests/utils.hpp +++ b/src/tests/utils.hpp @@ -19,32 +19,12 @@ #ifndef __TESTS_UTILS_HPP__ #define __TESTS_UTILS_HPP__ -#include <gtest/gtest.h> - -#include <string> - #include <stout/json.hpp> -#include <stout/option.hpp> namespace mesos { namespace internal { namespace tests { -// Test fixture for creating a temporary directory for each test. -// TODO(vinod): Fold this into stout/tests/utils.hpp. -class TemporaryDirectoryTest : public ::testing::Test -{ -protected: - virtual void SetUp(); - virtual void TearDown(); - - Option<std::string> sandbox; - -private: - std::string cwd; -}; - - // Get the metrics snapshot. // TODO(vinod): Move this into a libprocess utility header. JSON::Object Metrics();
