HDFS-14461. RBF: Fix intermittently failing kerberos related unit test. Contributed by Xiaoqiao He.

This commit is contained in:
Inigo Goiri 2019-09-26 15:26:23 -07:00
parent 06998a1126
commit b1e55cfb55
15 changed files with 39 additions and 49 deletions

View File

@ -43,16 +43,20 @@ public RouterHDFSContract(Configuration conf) {
}
public static void createCluster() throws IOException {
createCluster(null);
createCluster(false);
}
public static void createCluster(Configuration conf) throws IOException {
createCluster(true, 2, conf);
public static void createCluster(boolean security) throws IOException {
createCluster(true, 2, security);
}
public static void createCluster(
boolean ha, int numNameServices, Configuration conf) throws IOException {
boolean ha, int numNameServices, boolean security) throws IOException {
try {
Configuration conf = null;
if (security) {
conf = SecurityConfUtil.initSecurity();
}
cluster = new MiniRouterDFSCluster(ha, numNameServices, conf);
// Start NNs and DNs and wait until ready
@ -88,6 +92,11 @@ public static void destroyCluster() throws IOException {
cluster.shutdown();
cluster = null;
}
try {
SecurityConfUtil.destroy();
} catch (Exception e) {
throw new IOException("Cannot destroy security context", e);
}
}
public static MiniDFSCluster getCluster() {

View File

@ -65,6 +65,9 @@ public final class SecurityConfUtil {
private static final String ROUTER_USER_NAME = "router";
private static final String PREFIX = "hadoop.http.authentication.";
private static MiniKdc kdc;
private static File baseDir;
private static String spnegoPrincipal;
private static String routerPrincipal;
@ -78,14 +81,14 @@ public static String getRouterUserName() {
public static Configuration initSecurity() throws Exception {
// delete old test dir
File baseDir = GenericTestUtils.getTestDir(
baseDir = GenericTestUtils.getTestDir(
SecurityConfUtil.class.getSimpleName());
FileUtil.fullyDelete(baseDir);
assertTrue(baseDir.mkdirs());
// start a mini kdc with default conf
Properties kdcConf = MiniKdc.createConf();
MiniKdc kdc = new MiniKdc(kdcConf, baseDir);
kdc = new MiniKdc(kdcConf, baseDir);
kdc.start();
Configuration conf = new HdfsConfiguration();
@ -156,4 +159,12 @@ public static Configuration initSecurity() throws Exception {
return conf;
}
public static void destroy() throws Exception {
if (kdc != null) {
kdc.stop();
FileUtil.fullyDelete(baseDir);
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}
}
}

View File

@ -21,8 +21,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure append operations on the Router-based FS.
*/
@ -31,7 +29,7 @@ public class TestRouterHDFSContractAppendSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -23,9 +23,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure concat operations on the Router-based FS.
*/
@ -34,7 +31,7 @@ public class TestRouterHDFSContractConcatSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
// perform a simple operation on the cluster to verify it is up
RouterHDFSContract.getFileSystem().getDefaultBlockSize(new Path("/"));
}

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure create operations on the Router-based FS.
*/
@ -33,7 +30,7 @@ public class TestRouterHDFSContractCreateSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -46,7 +46,7 @@ public class TestRouterHDFSContractDelegationToken
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(false, 1, initSecurity());
RouterHDFSContract.createCluster(false, 1, true);
}
@AfterClass

View File

@ -21,8 +21,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure delete operations on the Router-based FS.
*/
@ -31,7 +29,7 @@ public class TestRouterHDFSContractDeleteSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -21,9 +21,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure get file status operations on the Router-based FS.
*/
@ -32,7 +29,7 @@ public class TestRouterHDFSContractGetFileStatusSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure dir operations on the Router-based FS.
*/
@ -33,7 +30,7 @@ public class TestRouterHDFSContractMkdirSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure open operations on the Router-based FS.
*/
@ -32,7 +29,7 @@ public class TestRouterHDFSContractOpenSecure extends AbstractContractOpenTest {
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure rename operations on the Router-based FS.
*/
@ -33,7 +30,7 @@ public class TestRouterHDFSContractRenameSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure root dir operations on the Router-based FS.
*/
@ -33,7 +30,7 @@ public class TestRouterHDFSContractRootDirectorySecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure seek operations on the Router-based FS.
*/
@ -32,7 +29,7 @@ public class TestRouterHDFSContractSeekSecure extends AbstractContractSeekTest {
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -22,9 +22,6 @@
import java.io.IOException;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/**
* Test secure set times operations on the Router-based FS.
*/
@ -33,7 +30,7 @@ public class TestRouterHDFSContractSetTimesSecure
@BeforeClass
public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity());
RouterHDFSContract.createCluster(true);
}
@AfterClass

View File

@ -144,6 +144,7 @@ public void cleanup() throws Exception {
router.stop();
router.close();
}
SecurityConfUtil.destroy();
}
@Test