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 class RouterHDFSContract extends HDFSContract {
} }
public static void createCluster() throws IOException { public static void createCluster() throws IOException {
createCluster(null); createCluster(false);
} }
public static void createCluster(Configuration conf) throws IOException { public static void createCluster(boolean security) throws IOException {
createCluster(true, 2, conf); createCluster(true, 2, security);
} }
public static void createCluster( public static void createCluster(
boolean ha, int numNameServices, Configuration conf) throws IOException { boolean ha, int numNameServices, boolean security) throws IOException {
try { try {
Configuration conf = null;
if (security) {
conf = SecurityConfUtil.initSecurity();
}
cluster = new MiniRouterDFSCluster(ha, numNameServices, conf); cluster = new MiniRouterDFSCluster(ha, numNameServices, conf);
// Start NNs and DNs and wait until ready // Start NNs and DNs and wait until ready
@ -88,6 +92,11 @@ public class RouterHDFSContract extends HDFSContract {
cluster.shutdown(); cluster.shutdown();
cluster = null; cluster = null;
} }
try {
SecurityConfUtil.destroy();
} catch (Exception e) {
throw new IOException("Cannot destroy security context", e);
}
} }
public static MiniDFSCluster getCluster() { 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 ROUTER_USER_NAME = "router";
private static final String PREFIX = "hadoop.http.authentication."; private static final String PREFIX = "hadoop.http.authentication.";
private static MiniKdc kdc;
private static File baseDir;
private static String spnegoPrincipal; private static String spnegoPrincipal;
private static String routerPrincipal; private static String routerPrincipal;
@ -78,14 +81,14 @@ public final class SecurityConfUtil {
public static Configuration initSecurity() throws Exception { public static Configuration initSecurity() throws Exception {
// delete old test dir // delete old test dir
File baseDir = GenericTestUtils.getTestDir( baseDir = GenericTestUtils.getTestDir(
SecurityConfUtil.class.getSimpleName()); SecurityConfUtil.class.getSimpleName());
FileUtil.fullyDelete(baseDir); FileUtil.fullyDelete(baseDir);
assertTrue(baseDir.mkdirs()); assertTrue(baseDir.mkdirs());
// start a mini kdc with default conf // start a mini kdc with default conf
Properties kdcConf = MiniKdc.createConf(); Properties kdcConf = MiniKdc.createConf();
MiniKdc kdc = new MiniKdc(kdcConf, baseDir); kdc = new MiniKdc(kdcConf, baseDir);
kdc.start(); kdc.start();
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
@ -156,4 +159,12 @@ public final class SecurityConfUtil {
return conf; 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.apache.hadoop.fs.contract.AbstractFSContract;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
/** /**
* Test secure append operations on the Router-based FS. * Test secure append operations on the Router-based FS.
*/ */
@ -31,7 +29,7 @@ public class TestRouterHDFSContractAppendSecure
@BeforeClass @BeforeClass
public static void createCluster() throws Exception { public static void createCluster() throws Exception {
RouterHDFSContract.createCluster(initSecurity()); RouterHDFSContract.createCluster(true);
} }
@AfterClass @AfterClass

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -144,6 +144,7 @@ public class TestRouterHttpDelegationToken {
router.stop(); router.stop();
router.close(); router.close();
} }
SecurityConfUtil.destroy();
} }
@Test @Test