From e76a93e1decb8ca9a9c35bf6abbe81cc76fe91e5 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Sat, 21 May 2011 06:43:57 -0400 Subject: [PATCH] Removed tests that are never run --- .../BlobStoreAndComputeServiceLiveTest.java | 136 ------------------ ...teAndBlobStoreTogetherHappilyLiveTest.java | 114 --------------- .../CredentialsStoredInBlobStoreTest.java | 101 ------------- 3 files changed, 351 deletions(-) delete mode 100644 demos/test/BlobStoreAndComputeServiceLiveTest.java delete mode 100644 demos/test/ComputeAndBlobStoreTogetherHappilyLiveTest.java delete mode 100644 demos/test/CredentialsStoredInBlobStoreTest.java diff --git a/demos/test/BlobStoreAndComputeServiceLiveTest.java b/demos/test/BlobStoreAndComputeServiceLiveTest.java deleted file mode 100644 index f9dabe60f6..0000000000 --- a/demos/test/BlobStoreAndComputeServiceLiveTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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 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 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(); - } - } - -} \ No newline at end of file diff --git a/demos/test/ComputeAndBlobStoreTogetherHappilyLiveTest.java b/demos/test/ComputeAndBlobStoreTogetherHappilyLiveTest.java deleted file mode 100644 index 2aa0fa0d9d..0000000000 --- a/demos/test/ComputeAndBlobStoreTogetherHappilyLiveTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - *

- * 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. - *

- * 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. - *

- * 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). - *

- * execHttpResponse simply assembles an http request, headers and all, and passes it to bash - *

- * 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 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 + ""); - - } -} diff --git a/demos/test/CredentialsStoredInBlobStoreTest.java b/demos/test/CredentialsStoredInBlobStoreTest.java deleted file mode 100644 index 9c51aa09eb..0000000000 --- a/demos/test/CredentialsStoredInBlobStoreTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - *

- * 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 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 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 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 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)); - } - } -}