ソースを参照

HDFS-6298. XML based End-to-End test for getfattr and setfattr commands. Contributed by Yi Liu

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2006@1592694 13f79535-47bb-0310-9956-ffa450edef68
Uma Maheswara Rao G 11 年 前
コミット
51fb234b5a

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-2006.txt

@@ -23,6 +23,8 @@ HDFS-2006 (Unreleased)
     HDFS-6301. NameNode: persist XAttrs in fsimage and record XAttrs modifications to edit log.
     (Yi Liu via umamahesh)
 
+    HDFS-6298. XML based End-to-End test for getfattr and setfattr commands. (Yi Liu via umamahesh)
+
   OPTIMIZATIONS
 
   BUG FIXES

+ 99 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestXAttrCLI.java

@@ -0,0 +1,99 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.cli;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.hadoop.cli.util.CLICommand;
+import org.apache.hadoop.cli.util.CommandExecutor.Result;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
+import org.apache.hadoop.hdfs.HDFSPolicyProvider;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.security.authorize.PolicyProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestXAttrCLI  extends CLITestHelperDFS {
+  protected MiniDFSCluster dfsCluster = null;
+  protected FileSystem fs = null;
+  protected String namenode = null;
+  
+  @Before
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
+    conf.setClass(PolicyProvider.POLICY_PROVIDER_CONFIG,
+        HDFSPolicyProvider.class, PolicyProvider.class);
+    conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1);
+    
+    dfsCluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
+    dfsCluster.waitClusterUp();
+    namenode = conf.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///");
+    
+    username = System.getProperty("user.name");
+
+    fs = dfsCluster.getFileSystem();
+    assertTrue("Not a HDFS: "+fs.getUri(), 
+        fs instanceof DistributedFileSystem);
+  }
+
+  @Override
+  protected String getTestFile() {
+    return "testXAttrConf.xml";
+  }
+  
+  @After
+  @Override
+  public void tearDown() throws Exception {
+    if (fs != null) {
+      fs.close();
+    }
+    if (dfsCluster != null) {
+      dfsCluster.shutdown();
+    }
+    Thread.sleep(2000);
+    super.tearDown();
+  }
+
+  @Override
+  protected String expandCommand(final String cmd) {
+    String expCmd = cmd;
+    expCmd = expCmd.replaceAll("NAMENODE", namenode);
+    expCmd = expCmd.replaceAll("#LF#",
+        System.getProperty("line.separator"));
+    expCmd = super.expandCommand(expCmd);
+    return expCmd;
+  }
+  
+  @Override
+  protected Result execute(CLICommand cmd) throws Exception {
+    return cmd.getExecutor(namenode).executeCommand(cmd.getCmd());
+  }
+  
+  @Test
+  @Override
+  public void testAll () {
+    super.testAll();
+  }
+
+}

+ 409 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testXAttrConf.xml

@@ -0,0 +1,409 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="testConf.xsl"?>
+
+<!--
+   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.
+-->
+
+<configuration>
+  <!-- Normal mode is test. To run just the commands and dump the output
+       to the log, set it to nocompare -->
+  <mode>test</mode>
+  
+  <!--  Comparator types:
+           ExactComparator
+           SubstringComparator
+           RegexpComparator
+           TokenComparator
+           -->
+  <tests>
+    <test>
+      <description>setfattr : Add an xattr</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr which has wrong prefix</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n uuu.a1 -v 123456 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>name must be prefixed with user/trusted/security/system, followed by a '.'</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr of trusted namespace</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n trusted.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>trusted.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr of system namespace</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n system.a1 -v 123456 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>setfattr: User doesn't have permission for xattr: system.a1</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr of security namespace</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n security.a1 -v 123456 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>setfattr: User doesn't have permission for xattr: security.a1</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr, and encode is text</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v "123456" /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr, and encode is hex</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 0x313233343536 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add an xattr, and encode is base64</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 0sMTIzNDU2 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Add multiple xattrs</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a2="abc"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Remove an xattr</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -setfattr -x user.a1 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+      	<comparator>
+          <type>ExactComparator</type>
+          <expected-output># file: /file1#LF#user.a2="abc"#LF#</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>setfattr : Remove an xattr which doesn't exist</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -x user.a2 /file1</command>
+        <command>-fs NAMENODE -getfattr -d /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+      	<comparator>
+          <type>ExactComparator</type>
+          <expected-output># file: /file1#LF#user.a1="123456"#LF#</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr which doesn't exist</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+      	<comparator>
+          <type>ExactComparator</type>
+          <expected-output># file: /file1#LF#</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr, and encode is text</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 -e text /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1="123456"</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr, and encode is hex</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 -e hex /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1=0x313233343536</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr, and encode is base64</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 -e base64 /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output># file: /file1</expected-output>
+        </comparator>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>user.a1=0sMTIzNDU2</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr : Get an xattr, and encode is invalid</description>
+      <test-commands>
+        <command>-fs NAMENODE -touchz /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /file1</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /file1</command>
+        <command>-fs NAMENODE -getfattr -n user.a1 -e invalid /file1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm /file1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>Invalid/unsupported encoding option specified: invalid</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+    <test>
+      <description>getfattr -R : recursive</description>
+      <test-commands>
+        <command>-fs NAMENODE -mkdir /dir1</command>
+        <command>-fs NAMENODE -setfattr -n user.a1 -v 123456 /dir1</command>
+        <command>-fs NAMENODE -mkdir /dir1/dir2</command>
+        <command>-fs NAMENODE -setfattr -n user.a2 -v abc /dir1/dir2</command>
+        <command>-fs NAMENODE -getfattr -R -d /dir1</command>
+      </test-commands>
+      <cleanup-commands>
+        <command>-fs NAMENODE -rm -R /dir1</command>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>ExactComparator</type>
+          <expected-output># file: /dir1#LF#user.a1="123456"#LF## file: /dir1/dir2#LF#user.a2="abc"#LF#</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+    
+  </tests>
+</configuration>