ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getOptionalPassword().isPresent() ? node.getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getOptionalPassword().isPresent() ? node.getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getOptionalPassword().isPresent() ? node .getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getOptionalPassword().isPresent() ? node .getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
private void runScript(SshClient client, String scriptName, String script, int nodeId) { client.put("/tmp/init-" + scriptName, script); expect(client.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD); expect(client.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD); expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); expect(client.exec("/tmp/init-" + scriptName + " init")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " start")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " status")).andReturn(EXEC_GOOD); // next status says the script is done, since not found. expect(client.exec("/tmp/init-" + scriptName + " status")).andReturn(EXEC_BAD); expect(client.exec("/tmp/init-" + scriptName + " stdout")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " stderr")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " exitstatus")).andReturn(EXEC_RC_GOOD); }
private void runScript(SshClient client, String scriptName, String script, int nodeId) { client.put("/tmp/init-" + scriptName, script); expect(client.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD); expect(client.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD); expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); expect(client.exec("/tmp/init-" + scriptName + " init")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " start")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " status")).andReturn(EXEC_GOOD); // next status says the script is done, since not found. expect(client.exec("/tmp/init-" + scriptName + " status")).andReturn(EXEC_BAD); expect(client.exec("/tmp/init-" + scriptName + " stdout")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " stderr")).andReturn(EXEC_GOOD); expect(client.exec("/tmp/init-" + scriptName + " exitstatus")).andReturn(EXEC_RC_GOOD); }
public void simpleTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(false)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect(sshClient.exec("echo $USER\n" + "echo $USER\n")).andReturn(new ExecResponse("tester\ntester\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
public void simpleTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(false)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect(sshClient.exec("echo $USER\n" + "echo $USER\n")).andReturn(new ExecResponse("tester\ntester\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
public void simpleRootTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(true)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect( sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "echo $USER\n" + "echo $USER\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("root\nroot\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
public void simpleRootTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(true)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect( sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "echo $USER\n" + "echo $USER\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("root\nroot\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
public void simpleRootTestWithSudoPassword() { node = createMock(NodeMetadata.class); expect(node.getCredentials()).andReturn(LoginCredentials.builder().user("tester").password("testpassword!").authenticateSudo(true).build()) .atLeastOnce(); replay(node); RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(true)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect( sshClient.exec("sudo -S sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "testpassword!\n" + "echo $USER\n" + "echo $USER\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("root\nroot\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
public void testUserAddAsRoot() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, UserAdd.builder() .login("testuser").build(), wrapInInitScript(false).runAsRoot(true).overrideLoginPassword("test")); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect( sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "mkdir -p /home/users\n" + "useradd -c testuser -s /bin/bash -m -d /home/users/testuser testuser\n" + "chown -R testuser /home/users/testuser\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn( new ExecResponse("done", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); } }