From 0c14365399210c82fe76e301f7ca51ab3a3a3b5c Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Oct 2011 03:08:36 -0700 Subject: [PATCH] Harder tests relating to installing admin user --- .../CloudServersComputeServiceLiveTest.java | 8 +-- .../cloudsigma/ProvidersInPropertiesTest.java | 4 +- .../DeltacloudComputeServiceLiveTest.java | 9 +-- .../compute/internal/BaseComputeService.java | 9 ++- .../compute/BaseComputeServiceLiveTest.java | 55 +++++++++++-------- ...TerremarkECloudComputeServiceLiveTest.java | 3 +- ...rkVCloudExpressComputeServiceLiveTest.java | 8 ++- 7 files changed, 59 insertions(+), 37 deletions(-) diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java index ef03b16060..c725549435 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -40,7 +40,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true) +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "CloudServersComputeServiceLiveTest") public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTest { public CloudServersComputeServiceLiveTest() { provider = "cloudservers"; @@ -54,12 +54,12 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext tmContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } @Override - protected void checkNodes(Iterable nodes, String tag) throws IOException { - super.checkNodes(nodes, tag); + protected void checkNodes(Iterable nodes, String group, String task) throws IOException { + super.checkNodes(nodes, group, task); for (NodeMetadata node : nodes) { assertEquals(node.getLocation().getScope(), LocationScope.HOST); } diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java index 9734a007b0..0a93dc1625 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/ProvidersInPropertiesTest.java @@ -35,13 +35,13 @@ public class ProvidersInPropertiesTest { @Test public void testSupportedProviders() { Iterable providers = Providers.getSupportedProviders(); - assert Iterables.contains(providers, "cloudsigma-zrh") : providers; + assert Iterables.contains(providers, "cloudsigma") : providers; } @Test public void testSupportedComputeServiceProviders() { Iterable providers = ComputeServiceUtils.getSupportedProviders(); - assert Iterables.contains(providers, "cloudsigma-zrh") : providers; + assert Iterables.contains(providers, "cloudsigma") : providers; } } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java index bee83990b5..e2c8522958 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/compute/DeltacloudComputeServiceLiveTest.java @@ -40,7 +40,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true) +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "DeltacloudComputeServiceLiveTest") public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { public DeltacloudComputeServiceLiveTest() { provider = "deltacloud"; @@ -55,8 +55,9 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest @Override protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); + "node userMetadata did not match %s %s", userMetadata, node); } + public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext tmContext = new ComputeServiceContextFactory() @@ -64,8 +65,8 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest } @Override - protected void checkNodes(Iterable nodes, String tag) throws IOException { - super.checkNodes(nodes, tag); + protected void checkNodes(Iterable nodes, String group, String task) throws IOException { + super.checkNodes(nodes, group, task); for (NodeMetadata node : nodes) { assertEquals(node.getLocation().getScope(), LocationScope.ZONE); } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 3a346cd56c..36f68b3020 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -628,7 +628,7 @@ public class BaseComputeService implements ComputeService { + " needs to be running before executing a script on it. current state: " + node.getState()); initAdminAccess.visit(runScript); final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options); - ListenableFuture response = runScriptOnNodeFactory.submit(node, runScript, options); + ListenableFuture response = runScriptOnNodeFactory.submit(node1, runScript, options); response.addListener(new Runnable() { @Override @@ -663,8 +663,13 @@ public class BaseComputeService implements ComputeService { : new Credentials.Builder(); if (options.getOverridingCredentials().identity != null) builder.identity(options.getOverridingCredentials().identity); - if (options.getOverridingCredentials().credential != null) + if (options.getOverridingCredentials().credential != null) { + // custom credentials are related to the input + builder = options.getOverridingCredentials().toBuilder(); + Credentials cred = builder.build(); + builder.identity(cred.identity); builder.credential(options.getOverridingCredentials().credential); + } node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(builder.build()).build(); } return node; diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index ba4d70c292..75296a7ed7 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -264,21 +264,11 @@ public abstract class BaseComputeServiceLiveTest { OperatingSystem os = node.getOperatingSystem(); // test bad password - try { - Map responses = client.runScriptOnNodesMatching( - runningInGroup(group), "echo $USER", wrapInInitScript(false).runAsRoot(false) - .overrideCredentialsWith(new Credentials(good.identity, "romeo"))); - assert responses.size() == 0 : "shouldn't pass with a bad password\n" + responses; - } catch (AssertionError e) { - throw e; - } catch (RunScriptOnNodesException e) { - assert Iterables.any(e.getNodeErrors().values(), Predicates.instanceOf(AuthorizationException.class)) : e - + " not authexception!"; - } + tryBadPassword(group, good); runScriptWithCreds(group, os, good); - checkNodes(nodes, group); + checkNodes(nodes, group, "runScriptWithCreds"); // test adding AdminAccess later changes the default boot user, in this case to foo ListenableFuture future = client.submitScriptOnNode(node.getId(), AdminAccess.builder() @@ -288,6 +278,11 @@ public abstract class BaseComputeServiceLiveTest { assert response.getExitCode() == 0 : node.getId() + ": " + response; + node = client.getNodeMetadata(node.getId()); + // test that the node updated to the correct admin user! + assertEquals(node.getCredentials().identity, "foo"); + assert node.getCredentials().credential != null : nodes; + weCanCancelTasks(node); assert response.getExitCode() == 0 : node.getId() + ": " + response; @@ -301,10 +296,24 @@ public abstract class BaseComputeServiceLiveTest { } } + @Test(enabled = false) + protected void tryBadPassword(String group, Credentials good) throws AssertionError { + try { + Map responses = client.runScriptOnNodesMatching(runningInGroup(group), + "echo I put a bad password", wrapInInitScript(false).runAsRoot(false).overrideCredentialsWith( + new Credentials(good.identity, "romeo"))); + assert responses.size() == 0 : "shouldn't pass with a bad password\n" + responses; + } catch (AssertionError e) { + throw e; + } catch (RunScriptOnNodesException e) { + assert Iterables.any(e.getNodeErrors().values(), Predicates.instanceOf(AuthorizationException.class)) : e + + " not authexception!"; + } + } + @Test(enabled = false) public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException { - ListenableFuture future; - future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper")); + ListenableFuture future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper").runAsRoot(false)); ExecResponse response = null; try { response = future.get(1, TimeUnit.MILLISECONDS); @@ -326,7 +335,7 @@ public abstract class BaseComputeServiceLiveTest { } } } - + protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { assert execResponse.getOutput().trim().equals(node1.getHostname()) : node1 + ": " + execResponse; } @@ -357,7 +366,7 @@ public abstract class BaseComputeServiceLiveTest { throw e; } assertEquals(nodes.size(), 2); - checkNodes(nodes, group); + checkNodes(nodes, group, "bootstrap"); NodeMetadata node1 = nodes.first(); NodeMetadata node2 = nodes.last(); // credentials aren't always the same @@ -423,7 +432,7 @@ public abstract class BaseComputeServiceLiveTest { Set nodes = client.createNodesInGroup(group, 1, template); assertEquals(nodes.size(), 1); - checkNodes(nodes, group); + checkNodes(nodes, group, "bootstrap"); NodeMetadata node = Iterables.getOnlyElement(nodes); if (existingLocationIsAssignable) assertEquals(node.getLocation(), existingLocation); @@ -446,7 +455,7 @@ public abstract class BaseComputeServiceLiveTest { .nameTask("runScriptWithCreds")); } - protected void checkNodes(Iterable nodes, String group) throws IOException { + protected void checkNodes(Iterable nodes, String group, String taskName) throws IOException { for (NodeMetadata node : nodes) { assertNotNull(node.getProviderId()); assertNotNull(node.getGroup()); @@ -459,7 +468,7 @@ public abstract class BaseComputeServiceLiveTest { if (node.getCredentials().identity != null) { assertNotNull(node.getCredentials().identity); assertNotNull(node.getCredentials().credential); - sshPing(node); + sshPing(node, taskName); } } } @@ -806,10 +815,10 @@ public abstract class BaseComputeServiceLiveTest { assert getCores(fastest) >= getCores(smallest) : format("%s ! >= %s", fastest, smallest); } - private void sshPing(NodeMetadata node) throws IOException { + private void sshPing(NodeMetadata node, String taskName) throws IOException { for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. try { - doCheckJavaIsInstalledViaSsh(node); + doCheckJavaIsInstalledViaSsh(node, taskName); return; } catch (SshException e) { try { @@ -821,7 +830,7 @@ public abstract class BaseComputeServiceLiveTest { } } - protected void doCheckJavaIsInstalledViaSsh(NodeMetadata node) throws IOException { + protected void doCheckJavaIsInstalledViaSsh(NodeMetadata node, String taskName) throws IOException { SshClient ssh = context.utils().sshForNode().apply(node); try { ssh.connect(); @@ -829,7 +838,7 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(hello.getOutput().trim(), "hello"); ExecResponse exec = ssh.exec("java -version"); assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec + "\n" - + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); + + ssh.exec("cat /tmp/" + taskName + "/stdout.log /tmp/" + taskName + "/stderr.log"); } finally { if (ssh != null) ssh.disconnect(); diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java index c6f76dc10a..b6f34f8bbe 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java @@ -31,6 +31,7 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.domain.Credentials; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; @@ -73,7 +74,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } - + @Override protected Template buildTemplate(TemplateBuilder templateBuilder) { Template template = super.buildTemplate(templateBuilder); diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java index 81beb479b1..c88fabda19 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.domain.Credentials; import org.jclouds.rest.RestContext; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; @@ -61,7 +62,12 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer assert image.getDefaultCredentials().credential != null : image; return template; } - + + @Override + protected void tryBadPassword(String group, Credentials good) throws AssertionError { + // TODO: for some reason terremark operates ssh eventhough it shouldn't + } + // terremark does not support metadata @Override protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) {