HDFS-11042. Add missing cleanupSSLConfig() call for tests that use setupSSLConfig(). Contributed by Kuhu Shukla.

This commit is contained in:
Kihwal Lee 2016-10-24 08:28:44 -05:00
parent d0a347984d
commit b18f35f097
7 changed files with 49 additions and 17 deletions

View File

@ -40,6 +40,7 @@ public class TestHttpFSFWithSWebhdfsFileSystem
private static String classpathDir; private static String classpathDir;
private static final String BASEDIR = private static final String BASEDIR =
GenericTestUtils.getTempPath(UUID.randomUUID().toString()); GenericTestUtils.getTempPath(UUID.randomUUID().toString());
private static String keyStoreDir;
private static Configuration sslConf; private static Configuration sslConf;
@ -57,7 +58,7 @@ public class TestHttpFSFWithSWebhdfsFileSystem
File base = new File(BASEDIR); File base = new File(BASEDIR);
FileUtil.fullyDelete(base); FileUtil.fullyDelete(base);
base.mkdirs(); base.mkdirs();
String keyStoreDir = new File(BASEDIR).getAbsolutePath(); keyStoreDir = new File(BASEDIR).getAbsolutePath();
try { try {
sslConf = new Configuration(); sslConf = new Configuration();
KeyStoreTestUtil.setupSSLConfig(keyStoreDir, classpathDir, sslConf, false); KeyStoreTestUtil.setupSSLConfig(keyStoreDir, classpathDir, sslConf, false);
@ -69,9 +70,10 @@ public class TestHttpFSFWithSWebhdfsFileSystem
} }
@AfterClass @AfterClass
public static void cleanUp() { public static void cleanUp() throws Exception {
new File(classpathDir, "ssl-client.xml").delete(); new File(classpathDir, "ssl-client.xml").delete();
new File(classpathDir, "ssl-server.xml").delete(); new File(classpathDir, "ssl-server.xml").delete();
KeyStoreTestUtil.cleanupSSLConfig(keyStoreDir, classpathDir);
} }
public TestHttpFSFWithSWebhdfsFileSystem(Operation operation) { public TestHttpFSFWithSWebhdfsFileSystem(Operation operation) {

View File

@ -86,6 +86,8 @@ public class TestSecureEncryptionZoneWithKMS {
private static final Path TEST_PATH = new Path("/test-dir"); private static final Path TEST_PATH = new Path("/test-dir");
private static HdfsConfiguration baseConf; private static HdfsConfiguration baseConf;
private static File baseDir; private static File baseDir;
private static String keystoresDir;
private static String sslConfDir;
private static final EnumSet< CreateEncryptionZoneFlag > NO_TRASH = private static final EnumSet< CreateEncryptionZoneFlag > NO_TRASH =
EnumSet.of(CreateEncryptionZoneFlag.NO_TRASH); EnumSet.of(CreateEncryptionZoneFlag.NO_TRASH);
@ -189,8 +191,8 @@ public class TestSecureEncryptionZoneWithKMS {
baseConf.set(KMS_CLIENT_ENC_KEY_CACHE_SIZE, "4"); baseConf.set(KMS_CLIENT_ENC_KEY_CACHE_SIZE, "4");
baseConf.set(KMS_CLIENT_ENC_KEY_CACHE_LOW_WATERMARK, "0.5"); baseConf.set(KMS_CLIENT_ENC_KEY_CACHE_LOW_WATERMARK, "0.5");
String keystoresDir = baseDir.getAbsolutePath(); keystoresDir = baseDir.getAbsolutePath();
String sslConfDir = KeyStoreTestUtil.getClasspathDir( sslConfDir = KeyStoreTestUtil.getClasspathDir(
TestSecureEncryptionZoneWithKMS.class); TestSecureEncryptionZoneWithKMS.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, baseConf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, baseConf, false);
baseConf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY, baseConf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY,
@ -225,7 +227,7 @@ public class TestSecureEncryptionZoneWithKMS {
} }
@AfterClass @AfterClass
public static void destroy() { public static void destroy() throws Exception {
if (kdc != null) { if (kdc != null) {
kdc.stop(); kdc.stop();
} }
@ -233,6 +235,7 @@ public class TestSecureEncryptionZoneWithKMS {
miniKMS.stop(); miniKMS.stop();
} }
FileUtil.fullyDelete(baseDir); FileUtil.fullyDelete(baseDir);
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
} }
@Before @Before

View File

@ -50,6 +50,8 @@ import org.junit.BeforeClass;
public abstract class SaslDataTransferTestCase { public abstract class SaslDataTransferTestCase {
private static File baseDir; private static File baseDir;
private static String keystoresDir;
private static String sslConfDir;
private static String hdfsPrincipal; private static String hdfsPrincipal;
private static String userPrincipal; private static String userPrincipal;
private static MiniKdc kdc; private static MiniKdc kdc;
@ -99,11 +101,12 @@ public abstract class SaslDataTransferTestCase {
} }
@AfterClass @AfterClass
public static void shutdownKdc() { public static void shutdownKdc() throws Exception {
if (kdc != null) { if (kdc != null) {
kdc.stop(); kdc.stop();
} }
FileUtil.fullyDelete(baseDir); FileUtil.fullyDelete(baseDir);
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
} }
/** /**
@ -129,8 +132,8 @@ public abstract class SaslDataTransferTestCase {
conf.set(DFS_DATANODE_HTTPS_ADDRESS_KEY, "localhost:0"); conf.set(DFS_DATANODE_HTTPS_ADDRESS_KEY, "localhost:0");
conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY, 10); conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY, 10);
String keystoresDir = baseDir.getAbsolutePath(); keystoresDir = baseDir.getAbsolutePath();
String sslConfDir = KeyStoreTestUtil.getClasspathDir(this.getClass()); sslConfDir = KeyStoreTestUtil.getClasspathDir(this.getClass());
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
conf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY, conf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY,
KeyStoreTestUtil.getClientSSLConfigFileName()); KeyStoreTestUtil.getClientSSLConfigFileName());

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.hdfs.qjournal; package org.apache.hadoop.hdfs.qjournal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.apache.hadoop.fs.CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY;
@ -71,6 +73,8 @@ public class TestSecureNNWithQJM {
private static HdfsConfiguration baseConf; private static HdfsConfiguration baseConf;
private static File baseDir; private static File baseDir;
private static String keystoresDir;
private static String sslConfDir;
private static MiniKdc kdc; private static MiniKdc kdc;
private MiniDFSCluster cluster; private MiniDFSCluster cluster;
@ -127,8 +131,8 @@ public class TestSecureNNWithQJM {
baseConf.set(DFS_JOURNALNODE_HTTPS_ADDRESS_KEY, "localhost:0"); baseConf.set(DFS_JOURNALNODE_HTTPS_ADDRESS_KEY, "localhost:0");
baseConf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY, 10); baseConf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY, 10);
String keystoresDir = baseDir.getAbsolutePath(); keystoresDir = baseDir.getAbsolutePath();
String sslConfDir = KeyStoreTestUtil.getClasspathDir( sslConfDir = KeyStoreTestUtil.getClasspathDir(
TestSecureNNWithQJM.class); TestSecureNNWithQJM.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, baseConf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, baseConf, false);
baseConf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY, baseConf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY,
@ -138,11 +142,12 @@ public class TestSecureNNWithQJM {
} }
@AfterClass @AfterClass
public static void destroy() { public static void destroy() throws Exception {
if (kdc != null) { if (kdc != null) {
kdc.stop(); kdc.stop();
} }
FileUtil.fullyDelete(baseDir); FileUtil.fullyDelete(baseDir);
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
} }
@Before @Before

View File

@ -44,6 +44,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LAZY_PERSIST_FILE_SCRUB_INTERVAL_SEC; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LAZY_PERSIST_FILE_SCRUB_INTERVAL_SEC;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY;
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -138,6 +139,8 @@ public class TestBalancer {
final static private String username = "balancer"; final static private String username = "balancer";
private static String principal; private static String principal;
private static File baseDir; private static File baseDir;
private static String keystoresDir;
private static String sslConfDir;
private static MiniKdc kdc; private static MiniKdc kdc;
private static File keytabFile; private static File keytabFile;
private MiniDFSCluster cluster; private MiniDFSCluster cluster;
@ -252,8 +255,8 @@ public class TestBalancer {
conf.set(DFS_BALANCER_KEYTAB_FILE_KEY, keytab); conf.set(DFS_BALANCER_KEYTAB_FILE_KEY, keytab);
conf.set(DFS_BALANCER_KERBEROS_PRINCIPAL_KEY, principal); conf.set(DFS_BALANCER_KERBEROS_PRINCIPAL_KEY, principal);
String keystoresDir = baseDir.getAbsolutePath(); keystoresDir = baseDir.getAbsolutePath();
String sslConfDir = KeyStoreTestUtil.getClasspathDir(TestBalancer.class); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestBalancer.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
conf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY, conf.set(DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY,
@ -263,6 +266,15 @@ public class TestBalancer {
initConf(conf); initConf(conf);
} }
@AfterClass
public static void destroy() throws Exception {
if (kdc != null) {
kdc.stop();
}
FileUtil.fullyDelete(baseDir);
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}
/* create a file with a length of <code>fileLen</code> */ /* create a file with a length of <code>fileLen</code> */
public static void createFile(MiniDFSCluster cluster, Path filePath, long public static void createFile(MiniDFSCluster cluster, Path filePath, long
fileLen, fileLen,

View File

@ -55,6 +55,8 @@ public class TestNameNodeRespectsBindHostKeys {
public static final Log LOG = LogFactory.getLog(TestNameNodeRespectsBindHostKeys.class); public static final Log LOG = LogFactory.getLog(TestNameNodeRespectsBindHostKeys.class);
private static final String WILDCARD_ADDRESS = "0.0.0.0"; private static final String WILDCARD_ADDRESS = "0.0.0.0";
private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1:0"; private static final String LOCALHOST_SERVER_ADDRESS = "127.0.0.1:0";
private static String keystoresDir;
private static String sslConfDir;
private static String getRpcServerAddress(MiniDFSCluster cluster) { private static String getRpcServerAddress(MiniDFSCluster cluster) {
NameNodeRpcServer rpcServer = (NameNodeRpcServer) cluster.getNameNodeRpc(); NameNodeRpcServer rpcServer = (NameNodeRpcServer) cluster.getNameNodeRpc();
@ -250,8 +252,8 @@ public class TestNameNodeRespectsBindHostKeys {
File base = new File(BASEDIR); File base = new File(BASEDIR);
FileUtil.fullyDelete(base); FileUtil.fullyDelete(base);
assertTrue(base.mkdirs()); assertTrue(base.mkdirs());
final String keystoresDir = new File(BASEDIR).getAbsolutePath(); keystoresDir = new File(BASEDIR).getAbsolutePath();
final String sslConfDir = KeyStoreTestUtil.getClasspathDir(TestNameNodeRespectsBindHostKeys.class); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestNameNodeRespectsBindHostKeys.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
} }
@ -309,6 +311,10 @@ public class TestNameNodeRespectsBindHostKeys {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
} }
if (keystoresDir != null && !keystoresDir.isEmpty()
&& sslConfDir != null && !sslConfDir.isEmpty()) {
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}
} }
} }
} }

View File

@ -193,6 +193,8 @@ public class TestWebHdfsTokens {
public void testLazyTokenFetchForSWebhdfs() throws Exception { public void testLazyTokenFetchForSWebhdfs() throws Exception {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
SWebHdfsFileSystem fs = null; SWebHdfsFileSystem fs = null;
String keystoresDir;
String sslConfDir;
try { try {
final Configuration clusterConf = new HdfsConfiguration(conf); final Configuration clusterConf = new HdfsConfiguration(conf);
SecurityUtil.setAuthenticationMethod(SIMPLE, clusterConf); SecurityUtil.setAuthenticationMethod(SIMPLE, clusterConf);
@ -200,8 +202,6 @@ public class TestWebHdfsTokens {
.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true); .DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true);
String baseDir = String baseDir =
GenericTestUtils.getTempPath(TestWebHdfsTokens.class.getSimpleName()); GenericTestUtils.getTempPath(TestWebHdfsTokens.class.getSimpleName());
String keystoresDir;
String sslConfDir;
clusterConf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTPS_ONLY.name()); clusterConf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTPS_ONLY.name());
clusterConf.set(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, "localhost:0"); clusterConf.set(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, "localhost:0");
@ -238,6 +238,7 @@ public class TestWebHdfsTokens {
cluster.shutdown(); cluster.shutdown();
} }
} }
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
} }
@Test @Test