Issue 740:update tests to use JDK7

This commit is contained in:
Adrian Cole 2011-11-01 04:23:59 +00:00
parent 29ee165de2
commit 0f8a2eec17
7 changed files with 311 additions and 147 deletions

View File

@ -32,6 +32,9 @@ import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
import static java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.RunScriptData.JBOSS7_URL;
import static org.jclouds.compute.RunScriptData.JBOSS_HOME;
import static org.jclouds.compute.RunScriptData.JDK7_URL;
import static org.jclouds.compute.RunScriptData.installAdminUserJBossAndOpenPorts;
import static org.jclouds.compute.RunScriptData.startJBoss;
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
@ -49,15 +52,19 @@ import static org.testng.Assert.assertNotNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
@ -85,6 +92,7 @@ import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
import org.jclouds.scriptbuilder.domain.Statements;
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
import org.jclouds.ssh.SshClient;
@ -97,11 +105,13 @@ import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gson.annotations.SerializedName;
import com.google.inject.Guice;
import com.google.inject.Module;
@ -148,7 +158,8 @@ public abstract class BaseComputeServiceLiveTest {
setServiceDefaults();
if (group == null)
group = checkNotNull(provider, "provider");
// groups need to work with hyphens in them, so let's make sure there is one!
// groups need to work with hyphens in them, so let's make sure there is
// one!
if (group.indexOf('-') == -1)
group = group + "-";
setupCredentials();
@ -176,8 +187,8 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null)
context.close();
Properties props = setupProperties();
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule()), props);
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService();
}
@ -193,7 +204,7 @@ public abstract class BaseComputeServiceLiveTest {
long interval = 50;
// get more precise than default socket tester
preciseSocketTester = new RetryablePredicate<IPSocket>(socketOpen, maxWait, interval, interval,
TimeUnit.MILLISECONDS);
TimeUnit.MILLISECONDS);
}
abstract protected Module getSshModule();
@ -204,7 +215,7 @@ public abstract class BaseComputeServiceLiveTest {
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, "MOMMA", "MIA",
ImmutableSet.<Module> of(new Log4JLoggingModule()));
ImmutableSet.<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes();
} catch (AuthorizationException e) {
throw e;
@ -229,7 +240,7 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, expectedExceptions = NoSuchElementException.class)
public void testCorrectExceptionRunningNodesNotFound() throws Exception {
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), buildScript(new OperatingSystem.Builder()
.family(OsFamily.UBUNTU).description("ffoo").build()));
.family(OsFamily.UBUNTU).description("ffoo").build()));
}
// since surefire and eclipse don't otherwise guarantee the order, we are
@ -252,14 +263,14 @@ public abstract class BaseComputeServiceLiveTest {
assert good.credential != null : nodes;
for (Entry<? extends NodeMetadata, ExecResponse> response : client.runScriptOnNodesMatching(
runningInGroup(group), Statements.exec("hostname"),
wrapInInitScript(false).runAsRoot(false).overrideCredentialsWith(good)).entrySet()) {
runningInGroup(group), Statements.exec("hostname"),
wrapInInitScript(false).runAsRoot(false).overrideCredentialsWith(good)).entrySet()) {
checkResponseEqualsHostname(response.getValue(), response.getKey());
}
// test single-node execution
ExecResponse response = client.runScriptOnNode(node.getId(), "hostname", wrapInInitScript(false).runAsRoot(
false));
ExecResponse response = client.runScriptOnNode(node.getId(), "hostname",
wrapInInitScript(false).runAsRoot(false));
checkResponseEqualsHostname(response, node);
OperatingSystem os = node.getOperatingSystem();
@ -270,9 +281,10 @@ public abstract class BaseComputeServiceLiveTest {
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()
.adminUsername("foo").build(), nameTask("adminUpdate"));
.adminUsername("foo").build(), nameTask("adminUpdate"));
response = future.get(3, TimeUnit.MINUTES);
@ -282,7 +294,7 @@ public abstract class BaseComputeServiceLiveTest {
// 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;
@ -300,20 +312,22 @@ public abstract class BaseComputeServiceLiveTest {
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")));
"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!";
+ " not authexception!";
}
}
@Test(enabled = false)
public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException {
ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), nameTask("sleeper").runAsRoot(false));
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);
@ -321,11 +335,11 @@ public abstract class BaseComputeServiceLiveTest {
} catch (TimeoutException e) {
assert !future.isDone();
response = client.runScriptOnNode(node.getId(), Statements.exec("./sleeper status"), wrapInInitScript(false)
.runAsRoot(false));
.runAsRoot(false));
assert !response.getOutput().trim().equals("") : node.getId() + ": " + response;
future.cancel(true);
response = client.runScriptOnNode(node.getId(), Statements.exec("./sleeper status"), wrapInInitScript(false)
.runAsRoot(false));
.runAsRoot(false));
assert response.getOutput().trim().equals("") : node.getId() + ": " + response;
try {
future.get();
@ -386,8 +400,7 @@ public abstract class BaseComputeServiceLiveTest {
protected static Template addRunScriptToTemplate(Template template) {
template.getOptions().runScript(
Statements.newStatementList(AdminAccess.standard(),
buildScript(template.getImage().getOperatingSystem())));
Statements.newStatementList(AdminAccess.standard(), buildScript(template.getImage().getOperatingSystem())));
return template;
}
@ -399,8 +412,8 @@ public abstract class BaseComputeServiceLiveTest {
protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node
.getOperatingSystem());
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(),
node.getOperatingSystem());
}
void assertLocationSameOrChild(Location test, Location expected) {
@ -416,18 +429,18 @@ public abstract class BaseComputeServiceLiveTest {
initializeContextAndClient();
Location existingLocation = Iterables.get(this.nodes, 0).getLocation();
boolean existingLocationIsAssignable = Iterables.any(client.listAssignableLocations(), Predicates
.equalTo(existingLocation));
boolean existingLocationIsAssignable = Iterables.any(client.listAssignableLocations(),
Predicates.equalTo(existingLocation));
if (existingLocationIsAssignable) {
getAnonymousLogger().info("creating another node based on existing nodes' location: " + existingLocation);
template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template).locationId(
existingLocation.getId()).build());
template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template)
.locationId(existingLocation.getId()).build());
} else {
refreshTemplate();
getAnonymousLogger().info(
format("%s is not assignable; using template's location %s as ", existingLocation, template
.getLocation()));
format("%s is not assignable; using template's location %s as ", existingLocation,
template.getLocation()));
}
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
@ -450,9 +463,9 @@ public abstract class BaseComputeServiceLiveTest {
}
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String group, OperatingSystem os,
Credentials creds) throws RunScriptOnNodesException {
Credentials creds) throws RunScriptOnNodesException {
return client.runScriptOnNodesMatching(runningInGroup(group), buildScript(os), overrideCredentialsWith(creds)
.nameTask("runScriptWithCreds"));
.nameTask("runScriptWithCreds"));
}
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String taskName) throws IOException {
@ -479,16 +492,16 @@ public abstract class BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception {
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client
.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))),
new Function<NodeMetadata, String>() {
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(
filter(client.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))),
new Function<NodeMetadata, String>() {
@Override
public String apply(NodeMetadata from) {
return from.getId();
}
@Override
public String apply(NodeMetadata from) {
return from.getId();
}
}));
}));
for (NodeMetadata node : nodes) {
metadataMap.remove(node.getId());
NodeMetadata metadata = client.getNodeMetadata(node.getId());
@ -507,7 +520,7 @@ public abstract class BaseComputeServiceLiveTest {
protected void assertNodeZero(Collection<? extends NodeMetadata> metadataSet) {
assert metadataSet.size() == 0 : format("nodes left in set: [%s] which didn't match set: [%s]", metadataSet,
nodes);
nodes);
}
@Test(enabled = true, dependsOnMethods = "testGet")
@ -577,7 +590,7 @@ public abstract class BaseComputeServiceLiveTest {
for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), inGroup(group))) {
assert node.getState() == NodeState.TERMINATED : node;
assert context.getCredentialStore().get("node#" + node.getId()) == null : "credential should have been null for "
+ "node#" + node.getId();
+ "node#" + node.getId();
}
}
@ -586,32 +599,33 @@ public abstract class BaseComputeServiceLiveTest {
}
static class ServiceStats {
long backgroundProcessSeconds;
long backgroundProcessMilliseconds;
long socketOpenMilliseconds;
long reportedStartupTimeMilliseconds;
@Override
public String toString() {
return String.format(
"[backgroundProcessSeconds=%s, socketOpenMilliseconds=%s, reportedStartupTimeMilliseconds=%s]",
backgroundProcessSeconds, socketOpenMilliseconds, reportedStartupTimeMilliseconds);
"[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s, reportedStartupTimeMilliseconds=%s]",
backgroundProcessMilliseconds, socketOpenMilliseconds, reportedStartupTimeMilliseconds);
}
}
protected ServiceStats trackAvailabilityOfProcessOnNode(Supplier<ExecResponse> bgProcess, String processName,
NodeMetadata node, Pattern parseReported) {
protected ServiceStats trackAvailabilityOfProcessOnNode(Future<ExecResponse> bgProcess, String processName,
NodeMetadata node, Pattern parseReported) throws InterruptedException, ExecutionException {
ServiceStats stats = new ServiceStats();
long startSeconds = currentTimeMillis();
Stopwatch watch = new Stopwatch().start();
ExecResponse exec = bgProcess.get();
stats.backgroundProcessSeconds = (currentTimeMillis() - startSeconds) / 1000;
stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
watch.reset().start();
IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 8080);
assert preciseSocketTester.apply(socket) : String.format("failed to open socket %s on node %s", socket, node);
stats.socketOpenMilliseconds = currentTimeMillis() - startSeconds;
stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
exec = client.runScriptOnNode(node.getId(), "./" + processName + " tail", runAsRoot(false)
.wrapInInitScript(false));
.wrapInInitScript(false));
Matcher matcher = parseReported.matcher(exec.getOutput());
if (matcher.find())
@ -624,8 +638,19 @@ public abstract class BaseComputeServiceLiveTest {
// started in 6462ms -
public static final Pattern JBOSS_PATTERN = Pattern.compile("started in ([0-9]+)ms -");
protected ServiceStats trackAvailabilityOfJBossProcessOnNode(Supplier<ExecResponse> startProcess, NodeMetadata node) {
return trackAvailabilityOfProcessOnNode(startProcess, "jboss", node, JBOSS_PATTERN);
private static class FreeGeoIPLocation {
private String ip;
@SerializedName("countrycode")
private String countryCode;
@SerializedName("regioncode")
private String regionCode;
private String city;
@Override
public String toString() {
return format("FreeGeoIPLocation [ip=%s, countryCode=%s, regionCode=%s, city=%s]", ip, countryCode,
regionCode, city);
}
}
@Test(enabled = true)
@ -633,7 +658,7 @@ public abstract class BaseComputeServiceLiveTest {
String group = this.group + "s";
final String configuration = Strings2.toStringAndClose(RunScriptData.class
.getResourceAsStream("/standalone-basic.xml"));
.getResourceAsStream("/standalone-basic.xml"));
try {
client.destroyNodesMatching(inGroup(group));
} catch (Exception e) {
@ -642,40 +667,71 @@ public abstract class BaseComputeServiceLiveTest {
try {
ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("Name", group);
long startSeconds = currentTimeMillis();
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080).blockOnPort(22,
300).userMetadata(userMetadata)));
Stopwatch watch = new Stopwatch().start();
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1,
inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata)));
long createSeconds = watch.elapsedTime(TimeUnit.SECONDS);
final String nodeId = node.getId();
long createSeconds = (currentTimeMillis() - startSeconds) / 1000;
checkUserMetadataInNodeEquals(node, userMetadata);
getAnonymousLogger()
.info(
format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(),
createSeconds));
getAnonymousLogger().info(
format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds));
startSeconds = currentTimeMillis();
watch.reset().start();
// note this is a dependency on the template resolution so we have the right process per
// operating system. moreover, we wish this to run as root, so that it can change ip
// note this is a dependency on the template resolution so we have the
// right process per
// operating system. moreover, we wish this to run as root, so that it
// can change ip
// tables rules and setup our admin user
client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()),
nameTask("configure-jboss"));
nameTask("configure-jboss"));
long configureSeconds = (currentTimeMillis() - startSeconds) / 1000;
long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS);
getAnonymousLogger().info(
format("<< configured node(%s) with %s in %ss", nodeId, client.runScriptOnNode(nodeId,
"java -fullversion", runAsRoot(false).wrapInInitScript(false)).getOutput().trim(),
configureSeconds));
format(
"<< configured node(%s) with %s and JBoss %s in %ss",
nodeId,
exec(nodeId, "java -fullversion"),
// version of the jboss jar
exec(nodeId,
format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'",
JBOSS_HOME)), configureSeconds));
trackAvailabilityOfJBossProcessOnNode(new Supplier<ExecResponse>() {
for (Entry<String, URI> download : ImmutableMap.<String, URI> of("jboss7", JBOSS7_URL, "jdk7", JDK7_URL)
.entrySet()) {
// note we cannot use nslookup until we've configured the system, as
// it may have not been present checking the address of the download
// host using the local node's DNS config
String downloadSourceIp = exec(
nodeId,
format("nslookup -query=a -timeout=5 %s|grep Address|tail -1|sed 's/.* //g'", download.getValue()
.getHost()));
if (InetAddresses.isInetAddress(downloadSourceIp)) {
getAnonymousLogger().info(
format("<< location of %s(%s) from perpective of node(%s): %s", download.getKey(), download
.getValue().getHost(), nodeId, getLocationForIp(downloadSourceIp)));
}
}
// the current IP configuration could show NAT destinations, as opposed
// to the real ip address of the host, so we'll use checkip to see what
// the world view this host as.
String nodeIp = exec(nodeId, SaveHttpResponseTo.CURL + " http://checkip.amazonaws.com/");
if (InetAddresses.isInetAddress(nodeIp)) {
getAnonymousLogger()
.info(format("<< location of node(%s) from perspective of amazonaws: %s", nodeId,
getLocationForIp(nodeIp)));
}
trackAvailabilityOfProcessOnNode(context.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse get() {
public ExecResponse call() {
return client.runScriptOnNode(nodeId, startJBoss(configuration), runAsRoot(false).blockOnComplete(false)
.nameTask("jboss"));
.nameTask("jboss"));
}
@Override
@ -683,14 +739,14 @@ public abstract class BaseComputeServiceLiveTest {
return "initial start of jboss";
}
}, node);
}), "jboss", node, JBOSS_PATTERN);
client.runScriptOnNode(nodeId, "./jboss stop", runAsRoot(false).wrapInInitScript(false));
trackAvailabilityOfJBossProcessOnNode(new Supplier<ExecResponse>() {
trackAvailabilityOfProcessOnNode(context.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse get() {
public ExecResponse call() {
return client.runScriptOnNode(nodeId, "./jboss start", runAsRoot(false).wrapInInitScript(false));
}
@ -699,7 +755,7 @@ public abstract class BaseComputeServiceLiveTest {
return "warm start of jboss";
}
}, node);
}), "jboss", node, JBOSS_PATTERN);
} finally {
client.destroyNodesMatching(inGroup(group));
@ -707,9 +763,24 @@ public abstract class BaseComputeServiceLiveTest {
}
protected String getLocationForIp(String ip) throws IOException {
InputStream json = context.utils().http().get(URI.create("http://freegeoip.appspot.com/" + ip));
String text = null;
if (json != null && (text = Strings2.toStringAndClose(json)).indexOf("}") != -1) {
return context.utils().json().fromJson(text, FreeGeoIPLocation.class).toString();
} else {
getAnonymousLogger().warning("could not get info on ip " + ip + "; check freegeoip");
}
return ip;
}
protected String exec(final String nodeId, String command) {
return client.runScriptOnNode(nodeId, command, runAsRoot(false).wrapInInitScript(false)).getOutput().trim();
}
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
assert node.getUserMetadata().equals(userMetadata) : String.format("node userMetadata did not match %s %s",
userMetadata, node);
userMetadata, node);
}
public void testListImages() throws Exception {
@ -728,26 +799,26 @@ public abstract class BaseComputeServiceLiveTest {
assert location != location.getParent() : location;
assert location.getScope() != null : location;
switch (location.getScope()) {
case PROVIDER:
assertProvider(location);
break;
case REGION:
assertProvider(location.getParent());
break;
case ZONE:
Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getParent().getParent();
assertProvider(provider2);
break;
case PROVIDER:
assertProvider(location);
break;
case REGION:
assertProvider(location.getParent());
break;
case ZONE:
Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getParent().getParent();
assertProvider(provider2);
break;
}
}
}
@ -770,7 +841,7 @@ public abstract class BaseComputeServiceLiveTest {
assert node.getState() != NodeState.RUNNING : node;
long duration = (currentTimeMillis() - time) / 1000;
assert duration < nonBlockDurationSeconds : format("duration(%d) longer than expected(%d) seconds! ",
duration, nonBlockDurationSeconds);
duration, nonBlockDurationSeconds);
} finally {
client.destroyNodesMatching(inGroup(group));
}
@ -837,8 +908,9 @@ public abstract class BaseComputeServiceLiveTest {
ExecResponse hello = ssh.exec("echo hello");
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/" + taskName + "/stdout.log /tmp/" + taskName + "/stderr.log");
assert exec.getError().indexOf("1.7") != -1 || exec.getOutput().indexOf("1.7") != -1 : exec + "\n"
+ ssh.exec("cat /tmp/" + taskName + "/" + taskName + ".sh /tmp/" + taskName + "/stdout.log /tmp/"
+ taskName + "/stderr.log");
} finally {
if (ssh != null)
ssh.disconnect();

View File

@ -39,6 +39,7 @@ import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
*
@ -46,7 +47,12 @@ import com.google.common.collect.ImmutableMap;
*/
public class RunScriptData {
private static String jbossHome = "/usr/local/jboss";
public static final URI JDK7_URL = URI.create(System.getProperty("test.jdk7-url",
"http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz"));
public static final URI JBOSS7_URL = URI.create(System.getProperty("test.jboss7-url",//
"http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz"));
public static String JBOSS_HOME = "/usr/local/jboss";
public static Statement installJavaAndCurl(OperatingSystem os) {
if (os == null || OperatingSystemPredicates.supportsApt().apply(os))
@ -72,22 +78,21 @@ public class RunScriptData {
AdminAccess.builder().adminUsername("web").build(),//
installJavaAndCurl(os),//
authorizePortsInIpTables(22, 8080),//
extractTargzIntoDirectory(URI.create(System.getProperty("test.jboss-url",//
"http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz")), "/usr/local"),//
exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " + jbossHome),//
extractTargzIntoDirectory(JBOSS7_URL, "/usr/local"),//
exec("{md} " + JBOSS_HOME), exec("mv /usr/local/jboss-*/* " + JBOSS_HOME),//
changeStandaloneConfigToListenOnAllIPAddresses(),
exec("chmod -R oug+r+w " + jbossHome),
exec("chown -R web " + jbossHome));
exec("chmod -R oug+r+w " + JBOSS_HOME),
exec("chown -R web " + JBOSS_HOME));
}
// NOTE do not name this the same as your login user, or the init process may kill you!
public static InitBuilder startJBoss(String configuration) {
return new InitBuilder(
"jboss",
jbossHome,
jbossHome,
ImmutableMap.of("jbossHome", jbossHome),
ImmutableList.<Statement>of(appendFile(jbossHome + "/standalone/configuration/standalone-custom.xml", Splitter.on('\n').split(configuration))),
JBOSS_HOME,
JBOSS_HOME,
ImmutableMap.of("jbossHome", JBOSS_HOME),
ImmutableList.<Statement>of(appendFile(JBOSS_HOME + "/standalone/configuration/standalone-custom.xml", Splitter.on('\n').split(configuration))),
ImmutableList
.<Statement> of(interpret(new StringBuilder().append("java ").append(' ')
.append("-server -Xms128m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:+TieredCompilation -Xverify:none -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000").append(' ')
@ -122,30 +127,44 @@ public class RunScriptData {
private static Statement changeStandaloneConfigToListenOnAllIPAddresses() {
return exec(format(
"(cd %s/standalone/configuration && sed 's~inet-address value=.*/~any-address/~g' standalone.xml > standalone.xml.new && mv standalone.xml.new standalone.xml)",
jbossHome));
JBOSS_HOME));
}
public static final ImmutableSet<String> exportJavaHomeAndAddToPath = ImmutableSet.of(
"export JAVA_HOME=/usr/local/jdk", "export PATH=$JAVA_HOME/bin:$PATH");
public static final Statement JDK7_INSTALL_TGZ = newStatementList(//
exec("{md} /usr/local/jdk"), extractTargzIntoDirectory(JDK7_URL, "/usr/local"),//
exec("mv /usr/local/jdk1.7*/* /usr/local/jdk/"),//
exec("test -n \"$SUDO_USER\" && "), appendFile("/home/$SUDO_USER/.bashrc", exportJavaHomeAndAddToPath),//
appendFile("/etc/bashrc", exportJavaHomeAndAddToPath),//
appendFile("$HOME/.bashrc", exportJavaHomeAndAddToPath),//
appendFile("/etc/skel/.bashrc", exportJavaHomeAndAddToPath),//
// TODO:
// eventhough we are setting the above, sometimes images (ex.
// cloudservers ubuntu) kick out of .bashrc (ex. [ -z "$PS1" ] &&
// return), for this reason, we should also explicitly link.
// A better way would be to update using alternatives or the like
exec("ln -fs /usr/local/jdk/bin/java /usr/bin/java"));
public static String aptInstall = "apt-get install -f -y -qq --force-yes";
public static final Statement APT_RUN_SCRIPT = newStatementList(//
normalizeHostAndDNSConfig(),//
exec("apt-get update -qq"),
exec("which curl || " + aptInstall + " curl"),//
exec(aptInstall + " openjdk-6-jdk"),//
exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> $HOME/.bashrc"));
normalizeHostAndDNSConfig(),//
exec("which curl >&- 2>&-|| " + aptInstall + " curl"),//
exec("which nslookup >&- 2>&-|| " + aptInstall + " dnsutils"),//
JDK7_INSTALL_TGZ);
public static String yumInstall = "yum --nogpgcheck -y install";
public static final Statement YUM_RUN_SCRIPT = newStatementList(//
normalizeHostAndDNSConfig(),//
exec("which curl || " + yumInstall + " curl"),//
exec(yumInstall + " java-1.6.0-openjdk-devel"),//
exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /etc/bashrc"));
normalizeHostAndDNSConfig(),//
exec("which curl >&- 2>&-|| " + yumInstall + " curl"),//
exec("which nslookup >&- 2>&-|| " + yumInstall + " bind-utils"),//
JDK7_INSTALL_TGZ);
public static final Statement ZYPPER_RUN_SCRIPT = newStatementList(//
normalizeHostAndDNSConfig(),//
exec("which curl || zypper install curl"),//
exec("zypper install java-1.6.0-openjdk"),//
exec("echo \"export PATH=\\\"\\$JAVA_HOME/bin/:\\$PATH\\\"\" >> /etc/bashrc"));
normalizeHostAndDNSConfig(),//
exec("which curl >&- 2>&-|| zypper install curl"),//
JDK7_INSTALL_TGZ);
}

View File

@ -143,7 +143,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn(
client1);
expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("web", "privateKey"))).andReturn(
client1New).times(6);
client1New).times(10);
runScriptAndService(client1, client1New);
expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn(
@ -257,6 +257,22 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
// note we have to reconnect here, as we updated the login user.
client.disconnect();
clientNew.connect();
expect(clientNew.exec("ls /usr/local/jboss/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("nslookup -query=a -timeout=5 download.jboss.org|grep Address|tail -1|sed 's/.* //g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("nslookup -query=a -timeout=5 download.oracle.com|grep Address|tail -1|sed 's/.* //g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 http://checkip.amazonaws.com/\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("java -fullversion\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
@ -328,7 +344,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
client.connect();
expect(client.exec("echo hello")).andReturn(new ExecResponse("hello", "", 0));
expect(client.exec("java -version")).andReturn(new ExecResponse("", "1.6", 0));
expect(client.exec("java -version")).andReturn(new ExecResponse("", "1.7", 0));
client.disconnect();
}

View File

@ -84,9 +84,9 @@ root ALL = (ALL) ALL
%wheel ALL = (ALL) NOPASSWD:ALL
END_OF_FILE
chmod 0440 /etc/sudoers
mkdir -p /home/users/defaultAdminUsername
mkdir -p /home/users
groupadd -f wheel
useradd -s /bin/bash -g wheel -d /home/users/defaultAdminUsername -p 'crypt(randompassword)' defaultAdminUsername
useradd -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(randompassword)' defaultAdminUsername
mkdir -p /home/users/defaultAdminUsername/.ssh
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
publicKey
@ -101,10 +101,29 @@ awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN {
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
apt-get update -qq
which curl || apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes openjdk-6-jdk
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> $HOME/.bashrc
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils
mkdir -p /usr/local/jdk
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk1.7*/* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> $HOME/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/skel/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
END_OF_SCRIPT

View File

@ -84,9 +84,9 @@ root ALL = (ALL) ALL
%wheel ALL = (ALL) NOPASSWD:ALL
END_OF_FILE
chmod 0440 /etc/sudoers
mkdir -p /home/users/web
mkdir -p /home/users
groupadd -f wheel
useradd -s /bin/bash -g wheel -d /home/users/web -p 'crypt(randompassword)' web
useradd -s /bin/bash -g wheel -m -d /home/users/web -p 'crypt(randompassword)' web
mkdir -p /home/users/web/.ssh
cat >> /home/users/web/.ssh/authorized_keys <<'END_OF_FILE'
publicKey
@ -101,10 +101,29 @@ awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN {
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
apt-get update -qq
which curl || apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes openjdk-6-jdk
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> $HOME/.bashrc
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils
mkdir -p /usr/local/jdk
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk1.7*/* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> $HOME/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/skel/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables-save

View File

@ -80,10 +80,29 @@ END_OF_SCRIPT
cd $INSTANCE_HOME
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
apt-get update -qq
which curl || apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes openjdk-6-jdk
echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> $HOME/.bashrc
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils
mkdir -p /usr/local/jdk
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk1.7*/* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> $HOME/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
cat >> /etc/skel/.bashrc <<'END_OF_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
END_OF_SCRIPT

View File

@ -84,9 +84,9 @@ root ALL = (ALL) ALL
%wheel ALL = (ALL) NOPASSWD:ALL
END_OF_FILE
chmod 0440 /etc/sudoers
mkdir -p /home/users/foo
mkdir -p /home/users
groupadd -f wheel
useradd -s /bin/bash -g wheel -d /home/users/foo -p 'crypt(randompassword)' foo
useradd -s /bin/bash -g wheel -m -d /home/users/foo -p 'crypt(randompassword)' foo
mkdir -p /home/users/foo/.ssh
cat >> /home/users/foo/.ssh/authorized_keys <<'END_OF_FILE'
publicKey