2010-09-12 05:27:42 -04:00
|
|
|
/**
|
|
|
|
*
|
2011-04-09 06:20:17 -04:00
|
|
|
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
2010-09-12 05:27:42 -04:00
|
|
|
*
|
|
|
|
* ====================================================================
|
|
|
|
* 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;
|
2010-09-28 18:56:05 -04:00
|
|
|
import static org.jclouds.compute.ComputeTestUtils.setupKeyPair;
|
2010-09-12 05:27:42 -04:00
|
|
|
|
2010-09-20 01:58:56 -04:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Map;
|
2010-09-19 16:30:11 -04:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.jclouds.Constants;
|
2010-09-12 05:27:42 -04:00
|
|
|
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";
|
2010-09-19 16:30:11 -04:00
|
|
|
|
2010-09-12 05:27:42 -04:00
|
|
|
protected String blobStoreProvider;
|
|
|
|
protected String computeServiceProvider;
|
2010-09-20 01:58:56 -04:00
|
|
|
protected Map<String, String> keyPair;
|
2010-09-12 05:27:42 -04:00
|
|
|
|
2010-09-19 16:30:11 -04:00
|
|
|
protected Properties setupCredentials(String provider) {
|
|
|
|
String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider
|
2010-09-28 18:56:05 -04:00
|
|
|
+ ".identity");
|
2010-09-19 16:30:11 -04:00
|
|
|
String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
|
2010-09-28 18:56:05 -04:00
|
|
|
+ ".credential");
|
2010-09-20 00:30:07 -04:00
|
|
|
String endpoint = System.getProperty("test." + provider + ".endpoint");
|
|
|
|
String apiversion = System.getProperty("test." + provider + ".apiversion");
|
2010-09-19 16:30:11 -04:00
|
|
|
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);
|
2010-09-20 00:30:07 -04:00
|
|
|
if (endpoint != null)
|
|
|
|
overrides.setProperty(provider + ".endpoint", endpoint);
|
|
|
|
if (apiversion != null)
|
|
|
|
overrides.setProperty(provider + ".apiversion", apiversion);
|
2010-09-19 16:30:11 -04:00
|
|
|
return overrides;
|
2010-09-12 05:27:42 -04:00
|
|
|
}
|
|
|
|
|
2010-09-20 01:58:56 -04:00
|
|
|
protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
|
2010-09-28 18:56:05 -04:00
|
|
|
keyPair = setupKeyPair();
|
2010-09-20 01:58:56 -04:00
|
|
|
}
|
|
|
|
|
2010-09-12 05:27:42 -04:00
|
|
|
@BeforeGroups(groups = { "live" })
|
2010-09-20 01:58:56 -04:00
|
|
|
public void setupClient() throws FileNotFoundException, IOException {
|
|
|
|
setupKeyPairForTest();
|
2010-09-28 18:56:05 -04:00
|
|
|
computeContext = new ComputeServiceContextFactory().createContext(computeServiceProvider,
|
|
|
|
ImmutableSet.of(new Log4JLoggingModule(), new JschSshClientModule()),
|
|
|
|
setupCredentials(computeServiceProvider));
|
|
|
|
blobContext = new BlobStoreContextFactory().createContext(blobStoreProvider,
|
|
|
|
ImmutableSet.of(new Log4JLoggingModule()), setupCredentials(blobStoreProvider));
|
2010-09-12 05:27:42 -04:00
|
|
|
blobContext.getAsyncBlobStore().createContainerInLocation(null, tag);
|
|
|
|
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void assertSshOutputOfCommandContains(Iterable<? extends NodeMetadata> nodes, String cmd, String expects) {
|
2010-09-12 20:35:51 -04:00
|
|
|
for (NodeMetadata node : nodes) {
|
|
|
|
IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22);
|
2010-09-12 05:27:42 -04:00
|
|
|
|
2010-12-30 17:40:23 -05:00
|
|
|
SshClient ssh = computeContext.utils().sshFactory().create(socket, node.getCredentials());
|
2010-09-12 20:35:51 -04:00
|
|
|
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();
|
|
|
|
}
|
2010-09-12 05:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void uploadBlob(String container, String name, String script) {
|
|
|
|
Blob blob = blobContext.getBlobStore().newBlob(name);
|
|
|
|
blob.setPayload(script);
|
2010-09-19 05:15:03 -04:00
|
|
|
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
2010-09-12 05:27:42 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|