diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/network/NetUtil.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/network/NetUtil.java index ea7a107d2de..81c661fb519 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/network/NetUtil.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/network/NetUtil.java @@ -90,19 +90,29 @@ private enum OS { osUsed = osTmp; } - public static void failIfNotSudo() { - Assume.assumeTrue("non supported OS", osUsed != OS.NON_SUPORTED); - if (!canSudo()) { + public static void skipIfNotSudo() { + skipIfNotSupportedOS(); + + boolean canSudo = canSudo(); + if (!canSudo) { StringWriter writer = new StringWriter(); 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(user + " ALL = NOPASSWD: /sbin/ifconfig"); 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() { nextDevice.set(0); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/NetworkFailureFailoverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/NetworkFailureFailoverTest.java index 8bae6e8f8af..ee6a3097fc6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/NetworkFailureFailoverTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/NetworkFailureFailoverTest.java @@ -55,8 +55,8 @@ /** * 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. - * If you don't have sudoer access to ifutil, this test will fail. - * You should add sudoer on your environment. otherwise you will have to ignore failures here. + * If you don't have sudoer access to ifutil, this test will skip. + * You should add sudoer on your environment to run the test. */ public class NetworkFailureFailoverTest extends FailoverTestBase { @@ -65,7 +65,7 @@ public class NetworkFailureFailoverTest extends FailoverTestBase { @BeforeClass public static void start() { - NetUtil.failIfNotSudo(); + NetUtil.skipIfNotSudo(); } // 192.0.2.0 is reserved for documentation (and testing on this case). diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/dnsswitch/DNSSwitchTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/dnsswitch/DNSSwitchTest.java index f837fba9541..b29b0c65cc7 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/dnsswitch/DNSSwitchTest.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/dnsswitch/DNSSwitchTest.java @@ -143,12 +143,17 @@ private static ActiveMQServerControl getServerControl(String uri, @BeforeClass public static void beforeClassMethod() throws Exception { + NetUtil.skipIfNotSupportedOS(); + if (USE_ETC_HOSTS) { if (!ETC_HOSTS.canWrite()) { 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()); + } else { + NetUtil.skipIfNotSudo(); } + serverLocation = getServerLocation(SERVER_NAME_0); // Before anything we must copy the jave security and change what we need for no cache // this will be used to spawn new tests @@ -163,7 +168,6 @@ public static void beforeClassMethod() throws Exception { Files.copy(ETC_HOSTS.toPath(), ETC_BACKUP.toPath(), StandardCopyOption.COPY_ATTRIBUTES); } } - NetUtil.failIfNotSudo(); } private static File getETCBackup() {