Harder tests relating to installing admin user

This commit is contained in:
Adrian Cole 2011-10-16 03:08:36 -07:00
parent 7491f764f3
commit 0c14365399
7 changed files with 59 additions and 37 deletions

View File

@ -40,7 +40,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @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 class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public CloudServersComputeServiceLiveTest() { public CloudServersComputeServiceLiveTest() {
provider = "cloudservers"; provider = "cloudservers";
@ -54,12 +54,12 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<CloudServersClient, CloudServersAsyncClient> tmContext = new ComputeServiceContextFactory() RestContext<CloudServersClient, CloudServersAsyncClient> tmContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
} }
@Override @Override
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException { protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
super.checkNodes(nodes, tag); super.checkNodes(nodes, group, task);
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
assertEquals(node.getLocation().getScope(), LocationScope.HOST); assertEquals(node.getLocation().getScope(), LocationScope.HOST);
} }

View File

@ -35,13 +35,13 @@ public class ProvidersInPropertiesTest {
@Test @Test
public void testSupportedProviders() { public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders(); Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "cloudsigma-zrh") : providers; assert Iterables.contains(providers, "cloudsigma") : providers;
} }
@Test @Test
public void testSupportedComputeServiceProviders() { public void testSupportedComputeServiceProviders() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders(); Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
assert Iterables.contains(providers, "cloudsigma-zrh") : providers; assert Iterables.contains(providers, "cloudsigma") : providers;
} }
} }

View File

@ -40,7 +40,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @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 class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public DeltacloudComputeServiceLiveTest() { public DeltacloudComputeServiceLiveTest() {
provider = "deltacloud"; provider = "deltacloud";
@ -55,8 +55,9 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest
@Override @Override
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) { protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format( assert node.getUserMetadata().equals(ImmutableMap.<String, String> 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 { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<DeltacloudClient, DeltacloudAsyncClient> tmContext = new ComputeServiceContextFactory() RestContext<DeltacloudClient, DeltacloudAsyncClient> tmContext = new ComputeServiceContextFactory()
@ -64,8 +65,8 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest
} }
@Override @Override
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException { protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
super.checkNodes(nodes, tag); super.checkNodes(nodes, group, task);
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
assertEquals(node.getLocation().getScope(), LocationScope.ZONE); assertEquals(node.getLocation().getScope(), LocationScope.ZONE);
} }

View File

@ -628,7 +628,7 @@ public class BaseComputeService implements ComputeService {
+ " needs to be running before executing a script on it. current state: " + node.getState()); + " needs to be running before executing a script on it. current state: " + node.getState());
initAdminAccess.visit(runScript); initAdminAccess.visit(runScript);
final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options); final NodeMetadata node1 = updateNodeWithCredentialsIfPresent(node, options);
ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node, runScript, options); ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options);
response.addListener(new Runnable() { response.addListener(new Runnable() {
@Override @Override
@ -663,8 +663,13 @@ public class BaseComputeService implements ComputeService {
: new Credentials.Builder<Credentials>(); : new Credentials.Builder<Credentials>();
if (options.getOverridingCredentials().identity != null) if (options.getOverridingCredentials().identity != null)
builder.identity(options.getOverridingCredentials().identity); 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); builder.credential(options.getOverridingCredentials().credential);
}
node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(builder.build()).build(); node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(builder.build()).build();
} }
return node; return node;

View File

@ -264,21 +264,11 @@ public abstract class BaseComputeServiceLiveTest {
OperatingSystem os = node.getOperatingSystem(); OperatingSystem os = node.getOperatingSystem();
// test bad password // test bad password
try { tryBadPassword(group, good);
Map<? extends NodeMetadata, ExecResponse> 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!";
}
runScriptWithCreds(group, os, 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 // test adding AdminAccess later changes the default boot user, in this case to foo
ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), AdminAccess.builder() ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), AdminAccess.builder()
@ -288,6 +278,11 @@ public abstract class BaseComputeServiceLiveTest {
assert response.getExitCode() == 0 : node.getId() + ": " + response; 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); weCanCancelTasks(node);
assert response.getExitCode() == 0 : node.getId() + ": " + response; 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<? extends NodeMetadata, ExecResponse> 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) @Test(enabled = false)
public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException { public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException {
ListenableFuture<ExecResponse> future; ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper").runAsRoot(false));
future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper"));
ExecResponse response = null; ExecResponse response = null;
try { try {
response = future.get(1, TimeUnit.MILLISECONDS); response = future.get(1, TimeUnit.MILLISECONDS);
@ -326,7 +335,7 @@ public abstract class BaseComputeServiceLiveTest {
} }
} }
} }
protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) {
assert execResponse.getOutput().trim().equals(node1.getHostname()) : node1 + ": " + execResponse; assert execResponse.getOutput().trim().equals(node1.getHostname()) : node1 + ": " + execResponse;
} }
@ -357,7 +366,7 @@ public abstract class BaseComputeServiceLiveTest {
throw e; throw e;
} }
assertEquals(nodes.size(), 2); assertEquals(nodes.size(), 2);
checkNodes(nodes, group); checkNodes(nodes, group, "bootstrap");
NodeMetadata node1 = nodes.first(); NodeMetadata node1 = nodes.first();
NodeMetadata node2 = nodes.last(); NodeMetadata node2 = nodes.last();
// credentials aren't always the same // credentials aren't always the same
@ -423,7 +432,7 @@ public abstract class BaseComputeServiceLiveTest {
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template); Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
assertEquals(nodes.size(), 1); assertEquals(nodes.size(), 1);
checkNodes(nodes, group); checkNodes(nodes, group, "bootstrap");
NodeMetadata node = Iterables.getOnlyElement(nodes); NodeMetadata node = Iterables.getOnlyElement(nodes);
if (existingLocationIsAssignable) if (existingLocationIsAssignable)
assertEquals(node.getLocation(), existingLocation); assertEquals(node.getLocation(), existingLocation);
@ -446,7 +455,7 @@ public abstract class BaseComputeServiceLiveTest {
.nameTask("runScriptWithCreds")); .nameTask("runScriptWithCreds"));
} }
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group) throws IOException { protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String taskName) throws IOException {
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
assertNotNull(node.getProviderId()); assertNotNull(node.getProviderId());
assertNotNull(node.getGroup()); assertNotNull(node.getGroup());
@ -459,7 +468,7 @@ public abstract class BaseComputeServiceLiveTest {
if (node.getCredentials().identity != null) { if (node.getCredentials().identity != null) {
assertNotNull(node.getCredentials().identity); assertNotNull(node.getCredentials().identity);
assertNotNull(node.getCredentials().credential); 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); 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. for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate.
try { try {
doCheckJavaIsInstalledViaSsh(node); doCheckJavaIsInstalledViaSsh(node, taskName);
return; return;
} catch (SshException e) { } catch (SshException e) {
try { 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); SshClient ssh = context.utils().sshForNode().apply(node);
try { try {
ssh.connect(); ssh.connect();
@ -829,7 +838,7 @@ public abstract class BaseComputeServiceLiveTest {
assertEquals(hello.getOutput().trim(), "hello"); assertEquals(hello.getOutput().trim(), "hello");
ExecResponse exec = ssh.exec("java -version"); ExecResponse exec = ssh.exec("java -version");
assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec + "\n" 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 { } finally {
if (ssh != null) if (ssh != null)
ssh.disconnect(); ssh.disconnect();

View File

@ -31,6 +31,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.domain.Credentials;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
@ -73,7 +74,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format( assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format(
"node userMetadata did not match %s %s", userMetadata, node); "node userMetadata did not match %s %s", userMetadata, node);
} }
@Override @Override
protected Template buildTemplate(TemplateBuilder templateBuilder) { protected Template buildTemplate(TemplateBuilder templateBuilder) {
Template template = super.buildTemplate(templateBuilder); Template template = super.buildTemplate(templateBuilder);

View File

@ -29,6 +29,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.domain.Credentials;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
@ -61,7 +62,12 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer
assert image.getDefaultCredentials().credential != null : image; assert image.getDefaultCredentials().credential != null : image;
return template; 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 // terremark does not support metadata
@Override @Override
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) { protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {