| 126 | |
| 127 | |
| 128 | TEST_F(NamespacesIsolatorTest, ROOT_PidNamespace) |
| 129 | { |
| 130 | Try<Owned<MesosContainerizer>> containerizer = |
| 131 | createContainerizer("filesystem/linux,namespaces/pid"); |
| 132 | |
| 133 | ASSERT_SOME(containerizer); |
| 134 | |
| 135 | // Write the command's pid namespace inode and init name to files. |
| 136 | const string command = |
| 137 | "stat -Lc %i /proc/1/ns/pid > ns && (cat /proc/1/cmdline > init)"; |
| 138 | |
| 139 | process::Future<Containerizer::LaunchResult> launch = |
| 140 | containerizer.get()->launch( |
| 141 | containerId, |
| 142 | createContainerConfig( |
| 143 | None(), |
| 144 | createExecutorInfo("executor", command), |
| 145 | directory), |
| 146 | std::map<string, string>(), |
| 147 | None()); |
| 148 | |
| 149 | AWAIT_ASSERT_EQ(Containerizer::LaunchResult::SUCCESS, launch); |
| 150 | |
| 151 | // Wait on the container. |
| 152 | Future<Option<ContainerTermination>> wait = |
| 153 | containerizer.get()->wait(containerId); |
| 154 | |
| 155 | AWAIT_READY(wait); |
| 156 | ASSERT_SOME(wait.get()); |
| 157 | |
| 158 | // Check the executor exited correctly. |
| 159 | EXPECT_TRUE(wait->get().has_status()); |
| 160 | EXPECT_EQ(0, wait->get().status()); |
| 161 | |
| 162 | // Check that the command was run in a different pid namespace. |
| 163 | Result<ino_t> testPidNamespace = ns::getns(::getpid(), "pid"); |
| 164 | ASSERT_SOME(testPidNamespace); |
| 165 | |
| 166 | Try<string> containerPidNamespace = os::read(path::join(directory, "ns")); |
| 167 | ASSERT_SOME(containerPidNamespace); |
| 168 | |
| 169 | EXPECT_NE(stringify(testPidNamespace.get()), |
| 170 | strings::trim(containerPidNamespace.get())); |
| 171 | |
| 172 | // Check that the word 'mesos' is the part of the name for the |
| 173 | // container's 'init' process. This verifies that /proc has been |
| 174 | // correctly mounted for the container. |
| 175 | Try<string> init = os::read(path::join(directory, "init")); |
| 176 | ASSERT_SOME(init); |
| 177 | |
| 178 | EXPECT_TRUE(strings::contains(init.get(), "mesos")); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | // This test verifies a top-level container can share pid namespace |
nothing calls this directly
no test coverage detected