ARTEMIS-3409: skip tests if preconditions cant be satisfied
This commit is contained in:
parent
1883801604
commit
6b8fdcb079
|
@ -90,19 +90,29 @@ public class NetUtil extends ExecuteUtil {
|
||||||
osUsed = osTmp;
|
osUsed = osTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void failIfNotSudo() {
|
public static void skipIfNotSudo() {
|
||||||
Assume.assumeTrue("non supported OS", osUsed != OS.NON_SUPORTED);
|
skipIfNotSupportedOS();
|
||||||
if (!canSudo()) {
|
|
||||||
|
boolean canSudo = canSudo();
|
||||||
|
if (!canSudo) {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
PrintWriter out = new PrintWriter(writer);
|
PrintWriter out = new PrintWriter(writer);
|
||||||
out.println("Add the following at the end of your /etc/sudoers (use the visudo command)");
|
out.println("In order to run this test you must be able to sudo ifconfig.");
|
||||||
|
out.println("E.g add the following at the end of your /etc/sudoers (use the visudo command)");
|
||||||
out.println("# ------------------------------------------------------- ");
|
out.println("# ------------------------------------------------------- ");
|
||||||
out.println(user + " ALL = NOPASSWD: /sbin/ifconfig");
|
out.println(user + " ALL = NOPASSWD: /sbin/ifconfig");
|
||||||
out.println("# ------------------------------------------------------- ");
|
out.println("# ------------------------------------------------------- ");
|
||||||
Assert.fail(writer.toString());
|
|
||||||
|
System.out.println(writer.toString());
|
||||||
|
|
||||||
|
Assume.assumeTrue("Not able to sudo ifconfig", canSudo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void skipIfNotSupportedOS() {
|
||||||
|
Assume.assumeTrue("non supported OS", osUsed != OS.NON_SUPORTED);
|
||||||
|
}
|
||||||
|
|
||||||
public static void cleanup() {
|
public static void cleanup() {
|
||||||
nextDevice.set(0);
|
nextDevice.set(0);
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ import org.junit.Test;
|
||||||
/**
|
/**
|
||||||
* This test will simulate a failure where the network card is gone.
|
* This test will simulate a failure where the network card is gone.
|
||||||
* On that case the server should fail (as in stop) and not hung.
|
* On that case the server should fail (as in stop) and not hung.
|
||||||
* If you don't have sudoer access to ifutil, this test will fail.
|
* If you don't have sudoer access to ifutil, this test will skip.
|
||||||
* You should add sudoer on your environment. otherwise you will have to ignore failures here.
|
* You should add sudoer on your environment to run the test.
|
||||||
*/
|
*/
|
||||||
public class NetworkFailureFailoverTest extends FailoverTestBase {
|
public class NetworkFailureFailoverTest extends FailoverTestBase {
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class NetworkFailureFailoverTest extends FailoverTestBase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void start() {
|
public static void start() {
|
||||||
NetUtil.failIfNotSudo();
|
NetUtil.skipIfNotSudo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 192.0.2.0 is reserved for documentation (and testing on this case).
|
// 192.0.2.0 is reserved for documentation (and testing on this case).
|
||||||
|
|
|
@ -143,12 +143,17 @@ public class DNSSwitchTest extends SmokeTestBase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClassMethod() throws Exception {
|
public static void beforeClassMethod() throws Exception {
|
||||||
|
NetUtil.skipIfNotSupportedOS();
|
||||||
|
|
||||||
if (USE_ETC_HOSTS) {
|
if (USE_ETC_HOSTS) {
|
||||||
if (!ETC_HOSTS.canWrite()) {
|
if (!ETC_HOSTS.canWrite()) {
|
||||||
System.out.println("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS);
|
System.out.println("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS);
|
||||||
}
|
}
|
||||||
Assume.assumeTrue("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS + "'", ETC_HOSTS.canWrite());
|
Assume.assumeTrue("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS + "'", ETC_HOSTS.canWrite());
|
||||||
|
} else {
|
||||||
|
NetUtil.skipIfNotSudo();
|
||||||
}
|
}
|
||||||
|
|
||||||
serverLocation = getServerLocation(SERVER_NAME_0);
|
serverLocation = getServerLocation(SERVER_NAME_0);
|
||||||
// Before anything we must copy the jave security and change what we need for no cache
|
// Before anything we must copy the jave security and change what we need for no cache
|
||||||
// this will be used to spawn new tests
|
// this will be used to spawn new tests
|
||||||
|
@ -163,7 +168,6 @@ public class DNSSwitchTest extends SmokeTestBase {
|
||||||
Files.copy(ETC_HOSTS.toPath(), ETC_BACKUP.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
|
Files.copy(ETC_HOSTS.toPath(), ETC_BACKUP.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetUtil.failIfNotSudo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getETCBackup() {
|
private static File getETCBackup() {
|
||||||
|
|
Loading…
Reference in New Issue