setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); String pid = tryGetPid(p); LOG.info("Launched fencing command '" + cmd + "' with " + ((pid != null) ? ("pid " + pid) : "unknown pid")); String logPrefix = abbreviate(cmd, ABBREV_LENGTH); if (pid != null) { logPrefix = "[PID " + pid + "] " + logPrefix;
/** * Set the environment of the subprocess to be the Configuration, * with '.'s replaced by '_'s. */ private void setConfAsEnvVars(Map<String, String> env) { for (Map.Entry<String, String> pair : getConf()) { env.put(pair.getKey().replace('.', '_'), pair.getValue()); } }
@Test public void testCommandAbbreviation() { assertEquals("a...f", ShellCommandFencer.abbreviate("abcdef", 5)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 6)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 7)); assertEquals("a...g", ShellCommandFencer.abbreviate("abcdefg", 5)); assertEquals("a...h", ShellCommandFencer.abbreviate("abcdefgh", 5)); assertEquals("a...gh", ShellCommandFencer.abbreviate("abcdefgh", 6)); assertEquals("ab...gh", ShellCommandFencer.abbreviate("abcdefgh", 7)); } }
/** * Test that the exit code of the script determines * whether the fencer succeeded or failed */ @Test public void testBasicSuccessFailure() { assertTrue(fencer.tryFence(TEST_TARGET, "echo")); assertFalse(fencer.tryFence(TEST_TARGET, "exit 1")); // bad path should also fail assertFalse(fencer.tryFence(TEST_TARGET, "xxxxxxxxxxxx")); }
private static ShellCommandFencer createFencer() { Configuration conf = new Configuration(); conf.set("in.fencing.tests", "yessir"); ShellCommandFencer fencer = new ShellCommandFencer(); fencer.setConf(conf); return fencer; }
@Test public void testCommandAbbreviation() { assertEquals("a...f", ShellCommandFencer.abbreviate("abcdef", 5)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 6)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 7)); assertEquals("a...g", ShellCommandFencer.abbreviate("abcdefg", 5)); assertEquals("a...h", ShellCommandFencer.abbreviate("abcdefgh", 5)); assertEquals("a...gh", ShellCommandFencer.abbreviate("abcdefgh", 6)); assertEquals("ab...gh", ShellCommandFencer.abbreviate("abcdefgh", 7)); } }
/** * Test that the exit code of the script determines * whether the fencer succeeded or failed */ @Test public void testBasicSuccessFailure() { assertTrue(fencer.tryFence(TEST_TARGET, "echo")); assertFalse(fencer.tryFence(TEST_TARGET, "exit 1")); // bad path should also fail assertFalse(fencer.tryFence(TEST_TARGET, "xxxxxxxxxxxx")); }
private static ShellCommandFencer createFencer() { Configuration conf = new Configuration(); conf.set("in.fencing.tests", "yessir"); ShellCommandFencer fencer = new ShellCommandFencer(); fencer.setConf(conf); return fencer; }
setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); String pid = tryGetPid(p); LOG.info("Launched fencing command '" + cmd + "' with " + ((pid != null) ? ("pid " + pid) : "unknown pid")); String logPrefix = abbreviate(cmd, ABBREV_LENGTH); if (pid != null) { logPrefix = "[PID " + pid + "] " + logPrefix;
/** * Set the environment of the subprocess to be the Configuration, * with '.'s replaced by '_'s. */ private void setConfAsEnvVars(Map<String, String> env) { for (Map.Entry<String, String> pair : getConf()) { env.put(pair.getKey().replace('.', '_'), pair.getValue()); } }
/** * Verify that the Configuration gets passed as * environment variables to the fencer. */ @Test public void testConfAsEnvironment() { if (!Shell.WINDOWS) { fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo $in...ing_tests: yessir")); } else { fencer.tryFence(TEST_TARGET, "echo %in_fencing_tests%"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo %in...ng_tests%: yessir")); } }
setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); String pid = tryGetPid(p); LOG.info("Launched fencing command '" + cmd + "' with " + ((pid != null) ? ("pid " + pid) : "unknown pid")); String logPrefix = abbreviate(cmd, ABBREV_LENGTH); if (pid != null) { logPrefix = "[PID " + pid + "] " + logPrefix;
/** * Set the environment of the subprocess to be the Configuration, * with '.'s replaced by '_'s. */ private void setConfAsEnvVars(Map<String, String> env) { for (Map.Entry<String, String> pair : getConf()) { env.put(pair.getKey().replace('.', '_'), pair.getValue()); } }
/** * Verify that information about the fencing target gets passed as * environment variables to the fencer. */ @Test public void testTargetAsEnvironment() { if (!Shell.WINDOWS) { fencer.tryFence(TEST_TARGET, "echo $target_host $target_port"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo $ta...rget_port: dummyhost 1234")); } else { fencer.tryFence(TEST_TARGET, "echo %target_host% %target_port%"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo %ta...get_port%: dummyhost 1234")); } }
setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); String pid = tryGetPid(p); LOG.info("Launched fencing command '" + cmd + "' with " + ((pid != null) ? ("pid " + pid) : "unknown pid")); String logPrefix = abbreviate(cmd, ABBREV_LENGTH); if (pid != null) { logPrefix = "[PID " + pid + "] " + logPrefix;
/** * Set the environment of the subprocess to be the Configuration, * with '.'s replaced by '_'s. */ private void setConfAsEnvVars(Map<String, String> env) { for (Map.Entry<String, String> pair : getConf()) { env.put(pair.getKey().replace('.', '_'), pair.getValue()); } }
/** * Verify that information about the fencing target gets passed as * environment variables to the fencer. */ @Test public void testTargetAsEnvironment() { if (!Shell.WINDOWS) { fencer.tryFence(TEST_TARGET, "echo $target_host $target_port"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo $ta...rget_port: dummyhost 1234")); } else { fencer.tryFence(TEST_TARGET, "echo %target_host% %target_port%"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo %ta...get_port%: dummyhost 1234")); } }
setConfAsEnvVars(builder.environment()); addTargetInfoAsEnvVars(target, builder.environment()); String pid = tryGetPid(p); LOG.info("Launched fencing command '" + cmd + "' with " + ((pid != null) ? ("pid " + pid) : "unknown pid")); String logPrefix = abbreviate(cmd, ABBREV_LENGTH); if (pid != null) { logPrefix = "[PID " + pid + "] " + logPrefix;
/** * Set the environment of the subprocess to be the Configuration, * with '.'s replaced by '_'s. */ private void setConfAsEnvVars(Map<String, String> env) { for (Map.Entry<String, String> pair : getConf()) { env.put(pair.getKey().replace('.', '_'), pair.getValue()); } }
/** * Verify that the Configuration gets passed as * environment variables to the fencer. */ @Test public void testConfAsEnvironment() { if (!Shell.WINDOWS) { fencer.tryFence(TEST_TARGET, "echo $in_fencing_tests"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo $in...ing_tests: yessir")); } else { fencer.tryFence(TEST_TARGET, "echo %in_fencing_tests%"); Mockito.verify(ShellCommandFencer.LOG).info( Mockito.endsWith("echo %in...ng_tests%: yessir")); } }