YARN-8922. Fixed test-container-executor test setup and clean up.
Contributed by Robert Kanter
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/66e7a2c7
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/66e7a2c7
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/66e7a2c7
Branch: refs/heads/HDFS-12943
Commit: 66e7a2c78767ec00be5076c614ac7611289ccaae
Parents: f6498af
Author: Eric Yang <[email protected]>
Authored: Mon Oct 22 15:28:58 2018 -0400
Committer: Eric Yang <[email protected]>
Committed: Mon Oct 22 15:28:58 2018 -0400
----------------------------------------------------------------------
.../test/test-container-executor.c | 54 ++++++++++++++------
1 file changed, 39 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/66e7a2c7/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
----------------------------------------------------------------------
diff --git
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
index a4515ce..327e441 100644
---
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
+++
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c
@@ -1440,32 +1440,26 @@ int main(int argc, char **argv) {
exit(1);
}
- if (mkdirs(TEST_ROOT, 0777) != 0) {
+ printf("\nMaking test dir\n");
+ if (mkdirs(TEST_ROOT, 0755) != 0) {
exit(1);
}
- if (chmod(TEST_ROOT, 0777) != 0) { // in case of umask
- exit(1);
- }
-
- if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) {
+ if (chmod(TEST_ROOT, 0755) != 0) { // in case of umask
exit(1);
}
+ // We need a valid config before the test really starts for the check_user
+ // and set_user calls
+ printf("\nCreating test.cfg\n");
if (write_config_file(TEST_ROOT "/test.cfg", 1) != 0) {
exit(1);
}
-
- printf("\nOur executable is %s\n",get_executable(argv[0]));
-
+ printf("\nLoading test.cfg\n");
read_executor_config(TEST_ROOT "/test.cfg");
- local_dirs = split(strdup(NM_LOCAL_DIRS));
- log_dirs = split(strdup(NM_LOG_DIRS));
-
- create_nm_roots(local_dirs);
-
// See the description above of various ways this test
// can be executed in order to understand the following logic
+ printf("\nDetermining user details\n");
char* current_username = strdup(getpwuid(getuid())->pw_name);
if (getuid() == 0 && (argc == 2 || argc == 3)) {
username = argv[1];
@@ -1474,12 +1468,37 @@ int main(int argc, char **argv) {
username = current_username;
yarn_username = (argc == 2) ? argv[1] : current_username;
}
- set_nm_uid(geteuid(), getegid());
+ struct passwd *username_info = check_user(username);
+ printf("\nSetting NM UID\n");
+ set_nm_uid(username_info->pw_uid, username_info->pw_gid);
+
+ // Make sure that username owns all the files now
+ printf("\nEnsuring ownership of test dir\n");
+ if (chown(TEST_ROOT, username_info->pw_uid, username_info->pw_gid) != 0) {
+ exit(1);
+ }
+ if (chown(TEST_ROOT "/test.cfg",
+ username_info->pw_uid, username_info->pw_gid) != 0) {
+ exit(1);
+ }
+ printf("\nSetting effective user\n");
if (set_user(username)) {
exit(1);
}
+ printf("\nCreating userlogs dir\n");
+ if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) {
+ exit(1);
+ }
+
+ printf("\nOur executable is %s\n",get_executable(argv[0]));
+
+ local_dirs = split(strdup(NM_LOCAL_DIRS));
+ log_dirs = split(strdup(NM_LOG_DIRS));
+
+ create_nm_roots(local_dirs);
+
printf("\nStarting tests\n");
printf("\ntest_is_empty()\n");
@@ -1609,6 +1628,11 @@ int main(int argc, char **argv) {
test_trim_function();
printf("\nFinished tests\n");
+ printf("\nAttempting to clean up from the run\n");
+ if (system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT)) {
+ exit(1);
+ }
+
free(current_username);
free_executor_configurations();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]