HDFS-6807. Fix TestReservedRawPaths. (clamb)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1615188 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Charles Lamb 2014-08-01 18:36:32 +00:00
parent beebb36595
commit 3d9e39e51f
4 changed files with 33 additions and 22 deletions

View File

@ -81,3 +81,5 @@ fs-encryption (Unreleased)
HDFS-6785. Should not be able to create encryption zone using path
to a non-directory file. (clamb)
HDFS-6807. Fix TestReservedRawPaths. (clamb)

View File

@ -27,6 +27,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.crypto.key.KeyProvider;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileSystem.Statistics;
@ -75,6 +76,7 @@ import org.junit.Assume;
import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedExceptionAction;
import java.util.*;
import java.util.concurrent.TimeoutException;
@ -1348,4 +1350,22 @@ public class DFSTestUtil {
in2.close();
}
}
/**
* Helper function to create a key in the Key Provider.
*
* @param keyName The name of the key to create
* @param cluster The cluster to create it in
* @param conf Configuration to use
*/
public static void createKey(String keyName, MiniDFSCluster cluster,
Configuration conf)
throws NoSuchAlgorithmException, IOException {
KeyProvider provider = cluster.getNameNode().getNamesystem().getProvider();
final KeyProvider.Options options = KeyProvider.options(conf);
options.setDescription(keyName);
options.setBitLength(128);
provider.createKey(keyName, options);
provider.flush();
}
}

View File

@ -102,7 +102,7 @@ public class TestEncryptionZones {
fs.getClient().provider = cluster.getNameNode().getNamesystem()
.getProvider();
// Create a test key
createKey(TEST_KEY);
DFSTestUtil.createKey(TEST_KEY, cluster, conf);
}
@After
@ -147,19 +147,6 @@ public class TestEncryptionZones {
);
}
/**
* Helper function to create a key in the Key Provider.
*/
private void createKey(String keyName)
throws NoSuchAlgorithmException, IOException {
KeyProvider provider = cluster.getNameNode().getNamesystem().getProvider();
final KeyProvider.Options options = KeyProvider.options(conf);
options.setDescription(keyName);
options.setBitLength(128);
provider.createKey(keyName, options);
provider.flush();
}
@Test(timeout = 60000)
public void testBasicOperations() throws Exception {
@ -263,7 +250,7 @@ public class TestEncryptionZones {
assertNumZones(1);
/* Test success of creating an EZ when they key exists. */
createKey(myKeyName);
DFSTestUtil.createKey(myKeyName, cluster, conf);
dfsAdmin.createEncryptionZone(zone2, myKeyName);
assertNumZones(++numZones);
assertZonePresent(myKeyName, zone2.toString());
@ -601,7 +588,7 @@ public class TestEncryptionZones {
// Test when the parent directory becomes a different EZ
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
final String otherKey = "otherKey";
createKey(otherKey);
DFSTestUtil.createKey(otherKey, cluster, conf);
dfsAdmin.createEncryptionZone(zone1, TEST_KEY);
executor.submit(new InjectFaultTask() {
@ -621,7 +608,7 @@ public class TestEncryptionZones {
// Test that the retry limit leads to an error
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
final String anotherKey = "anotherKey";
createKey(anotherKey);
DFSTestUtil.createKey(anotherKey, cluster, conf);
dfsAdmin.createEncryptionZone(zone1, anotherKey);
String keyToUse = otherKey;

View File

@ -57,12 +57,13 @@ public class TestReservedRawPaths {
private MiniDFSCluster cluster;
private HdfsAdmin dfsAdmin;
private DistributedFileSystem fs;
private final String TEST_KEY = "testKey";
protected FileSystemTestWrapper fsWrapper;
protected FileContextTestWrapper fcWrapper;
@Before
public void setup() throws IOException {
public void setup() throws Exception {
conf = new HdfsConfiguration();
fsHelper = new FileSystemTestHelper();
// Set up java key store
@ -82,6 +83,7 @@ public class TestReservedRawPaths {
// else the updates do not get flushed properly
fs.getClient().provider = cluster.getNameNode().getNamesystem()
.getProvider();
DFSTestUtil.createKey(TEST_KEY, cluster, conf);
}
@After
@ -110,7 +112,7 @@ public class TestReservedRawPaths {
// Create the first enc file
final Path zone = new Path("/zone");
fs.mkdirs(zone);
dfsAdmin.createEncryptionZone(zone, null);
dfsAdmin.createEncryptionZone(zone, TEST_KEY);
final Path encFile1 = new Path(zone, "myfile");
DFSTestUtil.createFile(fs, encFile1, len, (short) 1, 0xFEED);
// Read them back in and compare byte-by-byte
@ -150,7 +152,7 @@ public class TestReservedRawPaths {
final Path zone = new Path("zone");
final Path slashZone = new Path("/", zone);
fs.mkdirs(slashZone);
dfsAdmin.createEncryptionZone(slashZone, null);
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
final Path base = new Path("base");
final Path reservedRaw = new Path("/.reserved/raw");
@ -182,7 +184,7 @@ public class TestReservedRawPaths {
final Path zone = new Path("zone");
final Path slashZone = new Path("/", zone);
fs.mkdirs(slashZone);
dfsAdmin.createEncryptionZone(slashZone, null);
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
final Path rawRoot = new Path("/.reserved/raw");
final Path dir1 = new Path("dir1");
final Path rawDir1 = new Path(rawRoot, dir1);
@ -220,7 +222,7 @@ public class TestReservedRawPaths {
final Path zone = new Path("zone");
final Path slashZone = new Path("/", zone);
fs.mkdirs(slashZone);
dfsAdmin.createEncryptionZone(slashZone, null);
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
final Path base = new Path("base");
final Path reservedRaw = new Path("/.reserved/raw");
final int len = 8192;