Removed tests that are never run

This commit is contained in:
Andrew Phillips 2011-05-21 06:43:57 -04:00
parent 029f15f360
commit e76a93e1de
3 changed files with 0 additions and 351 deletions

View File

@ -1,136 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.get;
import static org.jclouds.compute.ComputeTestUtils.setupKeyPair;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.jclouds.Constants;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class BlobStoreAndComputeServiceLiveTest {
protected ComputeServiceContext computeContext;
protected BlobStoreContext blobContext;
protected String tag = System.getProperty("user.name") + "happy";
protected String blobStoreProvider;
protected String computeServiceProvider;
protected Map<String, String> keyPair;
protected Properties setupCredentials(String provider) {
String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider
+ ".identity");
String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
String endpoint = System.getProperty("test." + provider + ".endpoint");
String apiversion = System.getProperty("test." + provider + ".apiversion");
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
keyPair = setupKeyPair();
}
@BeforeGroups(groups = { "live" })
public void setupClient() throws FileNotFoundException, IOException {
setupKeyPairForTest();
computeContext = new ComputeServiceContextFactory().createContext(computeServiceProvider,
ImmutableSet.of(new Log4JLoggingModule(), new JschSshClientModule()),
setupCredentials(computeServiceProvider));
blobContext = new BlobStoreContextFactory().createContext(blobStoreProvider,
ImmutableSet.of(new Log4JLoggingModule()), setupCredentials(blobStoreProvider));
blobContext.getAsyncBlobStore().createContainerInLocation(null, tag);
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
}
protected void assertSshOutputOfCommandContains(Iterable<? extends NodeMetadata> nodes, String cmd, String expects) {
for (NodeMetadata node : nodes) {
IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22);
SshClient ssh = computeContext.utils().sshFactory().create(socket, node.getCredentials());
try {
ssh.connect();
ExecResponse exec = ssh.exec(cmd);
assert exec.getOutput().indexOf(expects) != -1 || exec.getError().indexOf(expects) != -1 : exec;
} finally {
if (ssh != null)
ssh.disconnect();
}
}
}
protected void uploadBlob(String container, String name, String script) {
Blob blob = blobContext.getBlobStore().newBlob(name);
blob.setPayload(script);
blob.getPayload().getContentMetadata().setContentType("text/plain");
blobContext.getBlobStore().putBlob(container, blob);
}
@AfterGroups(groups = { "live" })
public void teardownCompute() {
if (computeContext != null) {
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
computeContext.close();
}
}
@AfterGroups(groups = { "live" })
public void teardownBlobStore() {
if (blobContext != null) {
blobContext.getAsyncBlobStore().deleteContainer(tag);
blobContext.close();
}
}
}

View File

@ -1,114 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws;
import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.compute.util.ComputeServiceUtils.execHttpResponse;
import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory;
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
import java.net.URI;
import org.jclouds.aws.ec2.compute.BlobStoreAndComputeServiceLiveTest;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.http.HttpRequest;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.Statement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* This test helps us understand how we can use the power of blobstores to our favor.
* <p/>
* This test is in aws only because it happens to have both blobstore and compute
*
* TODO create a blobstore and compute integration module
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComputeServiceLiveTest {
@BeforeClass
protected void setupCredentials() {
blobStoreProvider = "s3";
computeServiceProvider = "ec2";
}
/**
* This test generates a bootstrap script based on the default operating system of the compute
* provider.
* <p/>
* It then uploads this to a blobstore, in a private location. Now, we want the bootstrap of the
* server to be able to load from this location without sending credentials to the starting
* machine. Accordingly, we send a signed url instead.
* <p/>
* Using the {@link BlobStore} api, we get a signed url corresponding to the bootstrap script. We
* next convert this into something that can be invoked via the commandline. Looking around, it
* seems like alestic runurl is pretty close. However, it is limited as it only works on requests
* that can be fully specified without headers (ex. Amazon S3). Instead, we use a variant
* (execHttpResponse).
* <p/>
* execHttpResponse simply assembles an http request, headers and all, and passes it to bash
* <p/>
* With this script ready, any node or nodes will take instructions from the blobstore when it
* boots up. we verify this with an assertion.
*
*/
@Test
public void testWeCanIndirectBootstrapInstructionsToAnArbitraryAndPrivateBlobStore() throws RunNodesException {
OperatingSystem defaultOperatingSystem = computeContext.getComputeService().templateBuilder().build().getImage()
.getOperatingSystem();
// using jclouds ability to detect operating systems before we launch them, we can avoid
// the bad practice of assuming everything is ubuntu.
uploadBlob(tag, "openjdk/install", buildScript(defaultOperatingSystem).render(OsFamily.UNIX));
// instead of hard-coding to amazon s3, we can use any blobstore, conceding this test is
// configured for amz. Note we are getting temporary access to a private blob.
HttpRequest signedRequestOfInstallScript = blobContext.getSigner().signGetBlob(tag, "openjdk/install");
// so one of our commands is to execute the contents of the blob above
Statement installOpenJDK = execHttpResponse(signedRequestOfInstallScript);
// if we want to, we can mix and match batched and ad-hoc commands, such as extracting maven
String mavenVersion = "3.0";
Statement extractMavenIntoUsrLocal = extractTargzIntoDirectory(
URI.create("http://mirrors.ibiblio.org/pub/mirrors/apache//maven/binaries/apache-maven-" + mavenVersion
+ "-bin.tar.gz"), "/usr/local");
// have both of these commands occur on boot
Statement bootstrapInstructions = newStatementList(installOpenJDK, extractMavenIntoUsrLocal);
// now that we have the correct instructions, kick-off the provisioner
Iterable<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag(tag, 2,
runScript(bootstrapInstructions));
// ensure the bootstrap operated by checking for the components we installed at boot time.
// Note this test will ensure both nodes are in sync.
assertSshOutputOfCommandContains(nodes, "java -version", "OpenJDK");
assertSshOutputOfCommandContains(nodes, "/usr/local/apache-maven-" + mavenVersion + "/bin/mvn -version",
"Apache Maven " + mavenVersion + "");
}
}

View File

@ -1,101 +0,0 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Credentials;
import org.jclouds.rest.config.CredentialStoreModule;
import org.jclouds.util.Strings2;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests that credentials stored in the blobstore can be reused across compute contexts.
* <p/>
* This test is in aws only because it happens to have both blobstore and compute
*
* TODO create a blobstore and compute integration module
*
* @author Adrian Cole
*/
@Test(testName = "jclouds.CredentialsStoredInBlobStoreTest")
public class CredentialsStoredInBlobStoreTest {
private BlobStoreContext blobContext;
private Map<String, InputStream> credentialsMap;
@BeforeTest
void setupCredentialContainerAndMap() {
blobContext = new BlobStoreContextFactory().createContext("transient", "foo", "bar");
blobContext.getBlobStore().createContainerInLocation(null, "credentials");
credentialsMap = blobContext.createInputStreamMap("credentials");
}
@Test
public void testWeCanUseBlobStoreToStoreCredentialsAcrossContexts() throws RunNodesException, IOException {
ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar",
ImmutableSet.of(new CredentialStoreModule(credentialsMap)));
Set<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag("foo", 10);
verifyCredentialsFromNodesAreInContext(nodes, computeContext);
computeContext.close();
// recreate the compute context with the same map and ensure it still works!
computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar", Collections
.singleton(new CredentialStoreModule(credentialsMap)));
verifyCredentialsFromNodesAreInContext(nodes, computeContext);
}
protected void verifyCredentialsFromNodesAreInContext(Set<? extends NodeMetadata> nodes,
ComputeServiceContext computeContext) throws IOException {
// verify each node's credential is in the map.
assertEquals(computeContext.credentialStore().size(), 10);
for (NodeMetadata node : nodes) {
assertEquals(computeContext.credentialStore().get("node#" + node.getId()), node.getCredentials());
}
// verify the credentials are in the backing store and of a known json format
assertEquals(credentialsMap.size(), 10);
for (Entry<String, InputStream> entry : credentialsMap.entrySet()) {
Credentials credentials = computeContext.credentialStore().get(entry.getKey());
assertEquals(Strings2.toStringAndClose(entry.getValue()), String.format(
"{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential));
}
}
}