mirror of https://github.com/apache/jclouds.git
Harder tests relating to installing admin user
This commit is contained in:
parent
7491f764f3
commit
0c14365399
|
@ -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<CloudServersClient, CloudServersAsyncClient> tmContext = new ComputeServiceContextFactory()
|
||||
.createContext(provider, identity, credential).getProviderSpecificContext();
|
||||
.createContext(provider, identity, credential).getProviderSpecificContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException {
|
||||
super.checkNodes(nodes, tag);
|
||||
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
|
||||
super.checkNodes(nodes, group, task);
|
||||
for (NodeMetadata node : nodes) {
|
||||
assertEquals(node.getLocation().getScope(), LocationScope.HOST);
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ public class ProvidersInPropertiesTest {
|
|||
@Test
|
||||
public void testSupportedProviders() {
|
||||
Iterable<String> providers = Providers.getSupportedProviders();
|
||||
assert Iterables.contains(providers, "cloudsigma-zrh") : providers;
|
||||
assert Iterables.contains(providers, "cloudsigma") : providers;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedComputeServiceProviders() {
|
||||
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
|
||||
assert Iterables.contains(providers, "cloudsigma-zrh") : providers;
|
||||
assert Iterables.contains(providers, "cloudsigma") : providers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, String> userMetadata) {
|
||||
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 {
|
||||
@SuppressWarnings("unused")
|
||||
RestContext<DeltacloudClient, DeltacloudAsyncClient> tmContext = new ComputeServiceContextFactory()
|
||||
|
@ -64,8 +65,8 @@ public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException {
|
||||
super.checkNodes(nodes, tag);
|
||||
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
|
||||
super.checkNodes(nodes, group, task);
|
||||
for (NodeMetadata node : nodes) {
|
||||
assertEquals(node.getLocation().getScope(), LocationScope.ZONE);
|
||||
}
|
||||
|
|
|
@ -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<ExecResponse> response = runScriptOnNodeFactory.submit(node, runScript, options);
|
||||
ListenableFuture<ExecResponse> response = runScriptOnNodeFactory.submit(node1, runScript, options);
|
||||
response.addListener(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
@ -663,8 +663,13 @@ public class BaseComputeService implements ComputeService {
|
|||
: new Credentials.Builder<Credentials>();
|
||||
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;
|
||||
|
|
|
@ -264,21 +264,11 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
OperatingSystem os = node.getOperatingSystem();
|
||||
|
||||
// test bad password
|
||||
try {
|
||||
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!";
|
||||
}
|
||||
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<ExecResponse> 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<? 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)
|
||||
public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException {
|
||||
ListenableFuture<ExecResponse> future;
|
||||
future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper"));
|
||||
ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper").runAsRoot(false));
|
||||
ExecResponse response = null;
|
||||
try {
|
||||
response = future.get(1, TimeUnit.MILLISECONDS);
|
||||
|
@ -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<? extends NodeMetadata> 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<? extends NodeMetadata> nodes, String group) throws IOException {
|
||||
protected void checkNodes(Iterable<? extends NodeMetadata> 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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -62,6 +63,11 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer
|
|||
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<String, String> userMetadata) {
|
||||
|
|
Loading…
Reference in New Issue