@Override public String apply(ExecResponse input) { return input.getOutput(); } };
protected void checkCustomizationOccurred(ExecResponse exec) { // note that vmwaretools throws in \r characters when executing scripts assert exec.getOutput().equals(iLoveAscii + "\r\n") : exec; }
protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { // hostname is not predictable based on node metadata assert execResponse.getOutput().trim().equals("ubuntu"); }
protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { // hostname is not predictable based on node metadata assert execResponse.getOutput().trim().equals("ubuntu"); } }
public static void assertResponsesContain(Map<? extends NodeMetadata, ExecResponse> responses, Statement statement, String text) { for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses.entrySet()) { if (!entry.getValue().getOutput().contains(text)) { failNotEquals("Node: " + entry.getKey().getId() + " failed to execute the command: " + statement + " as could not find expected text", text, entry.getValue()); } } }
public static void assertResponsesContain(Map<? extends NodeMetadata, ExecResponse> responses, Statement statement, String text) { for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses.entrySet()) { if (!entry.getValue().getOutput().contains(text)) { failNotEquals("Node: " + entry.getKey().getId() + " failed to execute the command: " + statement + " as could not find expected text", text, entry.getValue()); } } }
private static void assertResponsesContain( Map<? extends NodeMetadata, ExecResponse> responses, Statement statement, String text) { for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses .entrySet()) { if (!entry.getValue().getOutput().contains(text)) { failNotEquals("Node: " + entry.getKey().getId() + " failed to execute the command: " + statement + " as could not find expected text", text, entry.getValue()); } } }
public static void assertResponsesContain( Map<? extends NodeMetadata, ExecResponse> responses, Statement statement, String text) { for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses .entrySet()) { if (!entry.getValue().getOutput().contains(text)) { failNotEquals("Node: " + entry.getKey().getId() + " failed to execute the command: " + statement + " as could not find expected text", text, entry.getValue()); } } }
public void testExecHostname() throws IOException, InterruptedException { SshClient client = setupClient(); ExecResponse response = client.exec("hostname"); assertEquals(response.getError(), ""); assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName() : sshHost); }
@Test public void testExecInvalidCommand() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("thisCommandDoesNotExist"); assertNotEquals(response.getExitStatus(), 0); assertTrue(response.getOutput().contains("not found") || response.getError().contains("not found"), "stdout="+response.getOutput()+"; stderr="+response.getError()); } finally { client.disconnect(); } }
@Test public void testExecHostname() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("hostname"); assertEquals(response.getExitStatus(), 0); assertEquals(response.getError(), ""); assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName() : sshHost); } finally { client.disconnect(); } }
public void testCanRunCommandAsCurrentUser() throws Exception { Map<? extends NodeMetadata, ExecResponse> responses = context.getComputeService().runScriptOnNodesMatching( Predicates.<NodeMetadata> alwaysTrue(), exec("id"), wrapInInitScript(false).runAsRoot(false)); for (Entry<? extends NodeMetadata, ExecResponse> response : responses.entrySet()) assert response.getValue().getOutput().trim().contains(System.getProperty("user.name")) : response.getKey() + ": " + response.getValue(); }
@Test public void testExecInvalidCommand() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("thisCommandDoesNotExist"); assertNotEquals(response.getExitStatus(), 0); assertTrue(response.getOutput().contains("not found") || response.getError().contains("not found"), "stdout=" + response.getOutput() + "; stderr=" + response.getError()); } finally { client.disconnect(); } }
protected void checkSSH(HostAndPort socket) { socketTester.apply(socket); SshClient client = sshFactory.create(socket, loginCredentials); try { client.connect(); ExecResponse exec = client.exec("echo hello"); System.out.println(exec); assertEquals(exec.getOutput().trim(), "hello"); } finally { if (client != null) client.disconnect(); } }
@Override public ExecResponse apply(@Nullable org.jclouds.compute.domain.ExecResponse input) { if (input == null) { return null; } return ExecResponse.builder().output(input.getOutput()).error(input.getError()).exitStatus(input.getExitStatus()) .build(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }