소스 검색

svn merge -c 1357994 from branch-1 for HDFS-6527. Backport HADOOP-7389: Use of TestingGroups by tests causes subsequent tests to fail.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.1@1357995 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 13 년 전
부모
커밋
9421380397

+ 3 - 0
CHANGES.txt

@@ -265,6 +265,9 @@ Release 1.1.0 - unreleased
     HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection.
     (szetszwo)
 
+    HDFS-6527. Backport HADOOP-7389: Use of TestingGroups by tests causes
+    subsequent tests to fail.  (Ivan Mitic via szetszwo)
+
 Release 1.0.3 - 2012.05.07
 
   NEW FEATURES

+ 9 - 5
src/core/org/apache/hadoop/security/UserGroupInformation.java

@@ -895,17 +895,21 @@ public class UserGroupInformation {
   private static class TestingGroups extends Groups {
     private final Map<String, List<String>> userToGroupsMapping = 
       new HashMap<String,List<String>>();
+    private Groups underlyingImplementation;
     
-    private TestingGroups() {
+    private TestingGroups(Groups underlyingImplementation) {
       super(new org.apache.hadoop.conf.Configuration());
+      this.underlyingImplementation = underlyingImplementation;
     }
     
     @Override
-    public List<String> getGroups(String user) {
+    public List<String> getGroups(String user) throws IOException {
       List<String> result = userToGroupsMapping.get(user);
+
       if (result == null) {
-        result = new ArrayList<String>();
+        result = underlyingImplementation.getGroups(user);
       }
+
       return result;
     }
 
@@ -926,7 +930,7 @@ public class UserGroupInformation {
     UserGroupInformation ugi = createRemoteUser(user);
     // make sure that the testing object is setup
     if (!(groups instanceof TestingGroups)) {
-      groups = new TestingGroups();
+      groups = new TestingGroups(groups);
     }
     // add the user groups
     ((TestingGroups) groups).setUserGroups(ugi.getShortUserName(), userGroups);
@@ -951,7 +955,7 @@ public class UserGroupInformation {
     UserGroupInformation ugi = createProxyUser(user, realUser);
     // make sure that the testing object is setup
     if (!(groups instanceof TestingGroups)) {
-      groups = new TestingGroups();
+      groups = new TestingGroups(groups);
     }
     // add the user groups
     ((TestingGroups) groups).setUserGroups(ugi.getShortUserName(), userGroups);

+ 5 - 18
src/test/org/apache/hadoop/mapred/TestQueueManager.java

@@ -48,19 +48,8 @@ public class TestQueueManager extends TestCase {
 
   MiniDFSCluster miniDFSCluster;
   MiniMRCluster miniMRCluster = null;
-  
-  /**
-   * For some tests it is necessary to sandbox them in a doAs with a fake user
-   * due to bug HADOOP-6527, which wipes out real group mappings. It's also
-   * necessary to then add the real user running the test to the fake users
-   * so that child processes can write to the DFS.
-   */
+
   UserGroupInformation createNecessaryUsers() throws IOException {
-    // Add real user to fake groups mapping so that child processes (tasks)
-    // will have permissions on the dfs
-    String j = UserGroupInformation.getCurrentUser().getShortUserName();
-    UserGroupInformation.createUserForTesting(j, new String [] { "myGroup"});
-    
     // Create a fake user for all processes to execute within
     UserGroupInformation ugi = UserGroupInformation.createUserForTesting("Zork",
                                                  new String [] {"ZorkGroup"});
@@ -130,12 +119,10 @@ public class TestQueueManager extends TestCase {
       verifyJobSubmissionToDefaultQueue(conf, true, userName + "," + groupName);
       verifyJobSubmissionToDefaultQueue(conf, true, user2 + "," + group2);
     
-      // Check if MROwner(user who started the mapreduce cluster) can submit job
-      UserGroupInformation mrOwner = UserGroupInformation.getCurrentUser();
-      userName = mrOwner.getShortUserName();
-      String[] groups = mrOwner.getGroupNames();
-      groupName = groups[groups.length - 1];
-      verifyJobSubmissionToDefaultQueue(conf, true, userName + "," + groupName);
+      // Check if MROwner (user who started the mapreduce cluster) can submit
+      // job. By passing null as userInfo we fallback to using the
+      // UserGroupInformation.getCurrentUser() what is the intent of the test.
+      verifyJobSubmissionToDefaultQueue(conf, true, null);
     } finally {
       tearDownCluster();
     }

+ 23 - 23
src/test/org/apache/hadoop/security/TestUserGroupInformation.java

@@ -76,6 +76,29 @@ public class TestUserGroupInformation {
     UserGroupInformation.setConfiguration(conf);
   }
   
+  /** Test login method */
+  @Test
+  public void testLogin() throws Exception {
+    // login from unix
+    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
+    assertEquals(UserGroupInformation.getCurrentUser(),
+                 UserGroupInformation.getLoginUser());
+    assertTrue(ugi.getGroupNames().length >= 1);
+
+    // ensure that doAs works correctly
+    UserGroupInformation userGroupInfo = 
+      UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
+    UserGroupInformation curUGI = 
+      userGroupInfo.doAs(new PrivilegedExceptionAction<UserGroupInformation>(){
+        public UserGroupInformation run() throws IOException {
+          return UserGroupInformation.getCurrentUser();
+        }});
+    // make sure in the scope of the doAs, the right user is current
+    assertEquals(curUGI, userGroupInfo);
+    // make sure it is not the same as the login user
+    assertFalse(curUGI.equals(UserGroupInformation.getLoginUser()));
+  }
+  
   /**
    * given user name - get all the groups.
    * Needs to happen before creating the test users
@@ -120,29 +143,6 @@ public class TestUserGroupInformation {
       }});
   }
 
-  /** Test login method */
-  @Test
-  public void testLogin() throws Exception {
-    // login from unix
-    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
-    assertEquals(UserGroupInformation.getCurrentUser(),
-                 UserGroupInformation.getLoginUser());
-    assertTrue(ugi.getGroupNames().length >= 1);
-
-    // ensure that doAs works correctly
-    UserGroupInformation userGroupInfo = 
-      UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES);
-    UserGroupInformation curUGI = 
-      userGroupInfo.doAs(new PrivilegedExceptionAction<UserGroupInformation>(){
-        public UserGroupInformation run() throws IOException {
-          return UserGroupInformation.getCurrentUser();
-        }});
-    // make sure in the scope of the doAs, the right user is current
-    assertEquals(curUGI, userGroupInfo);
-    // make sure it is not the same as the login user
-    assertFalse(curUGI.equals(UserGroupInformation.getLoginUser()));
-  }
-
   /** test constructor */
   @Test
   public void testConstructor() throws Exception {