HDFS-14461. RBF: Fix intermittently failing kerberos related unit test. Contributed by Xiaoqiao He.
This commit is contained in:
parent
06998a1126
commit
b1e55cfb55
|
@ -43,16 +43,20 @@ public class RouterHDFSContract extends HDFSContract {
|
|||
}
|
||||
|
||||
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 class RouterHDFSContract extends HDFSContract {
|
|||
cluster.shutdown();
|
||||
cluster = null;
|
||||
}
|
||||
try {
|
||||
SecurityConfUtil.destroy();
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Cannot destroy security context", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MiniDFSCluster getCluster() {
|
||||
|
|
|
@ -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 final class SecurityConfUtil {
|
|||
|
||||
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 final class SecurityConfUtil {
|
|||
|
||||
return conf;
|
||||
}
|
||||
|
||||
public static void destroy() throws Exception {
|
||||
if (kdc != null) {
|
||||
kdc.stop();
|
||||
FileUtil.fullyDelete(baseDir);
|
||||
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.apache.hadoop.fs.contract.AbstractFSContract;
|
|||
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
|
||||
|
|
|
@ -23,9 +23,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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("/"));
|
||||
}
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.apache.hadoop.fs.contract.AbstractFSContract;
|
|||
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
|
||||
|
|
|
@ -21,9 +21,6 @@ import org.apache.hadoop.fs.contract.AbstractFSContract;
|
|||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -22,9 +22,6 @@ import org.junit.BeforeClass;
|
|||
|
||||
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
|
||||
|
|
|
@ -144,6 +144,7 @@ public class TestRouterHttpDelegationToken {
|
|||
router.stop();
|
||||
router.close();
|
||||
}
|
||||
SecurityConfUtil.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue