mirror of https://github.com/apache/jclouds.git
carved out a test to help guide completion of softlayer
This commit is contained in:
parent
5469c324d1
commit
eb598a7c39
|
@ -70,14 +70,12 @@ public class SoftLayerComputeServiceAdapter implements
|
|||
@Override
|
||||
public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name,
|
||||
Template template, Map<String, Credentials> credentialStore) {
|
||||
VirtualGuest from = null; // TODO create the backend object using parameters from the
|
||||
// template. ex.
|
||||
// VirtualGuest from =
|
||||
// client.getVirtualGuestClient().createServerInDC(template.getLocation().getId(), name,
|
||||
// Long.parseLong(template.getImage().getProviderId()),
|
||||
// Long.parseLong(template.getHardware().getProviderId()));
|
||||
// store the credentials so that later functions can use them
|
||||
// credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser,
|
||||
VirtualGuest from = null; // from testCancelAndPlaceOrder()
|
||||
// use name for hostname as possible
|
||||
// you can ignore group, unless it is valid to set as domain
|
||||
// get the cpu, mem, datacenter from the template ids
|
||||
// make sure you store the credentials so that later functions can use them
|
||||
// credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser (might be root),
|
||||
// from.password));
|
||||
return from;
|
||||
}
|
||||
|
|
|
@ -20,30 +20,41 @@ package org.jclouds.softlayer.compute;
|
|||
|
||||
import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode;
|
||||
import static org.jclouds.softlayer.predicates.ProductItemPredicates.units;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
|
||||
import org.jclouds.softlayer.domain.ProductItem;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
import org.jclouds.softlayer.features.BaseSoftLayerClientLiveTest;
|
||||
import org.jclouds.softlayer.features.ProductPackageClientLiveTest;
|
||||
import org.testng.Assert;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
||||
@Test(groups = "live", testName = "SoftLayerComputeServiceAdapterLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest")
|
||||
public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientLiveTest {
|
||||
|
||||
private SoftLayerComputeServiceAdapter adapter;
|
||||
private VirtualGuest guest;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
adapter = new SoftLayerComputeServiceAdapter(context.getApi(), ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME);
|
||||
adapter = new SoftLayerComputeServiceAdapter(context.getApi(),
|
||||
ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,18 +62,56 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
|
|||
assertFalse(Iterables.isEmpty(adapter.listLocations()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
|
||||
String group = "foo";
|
||||
String name = "foo-ef4";
|
||||
Template template = computeContext.getComputeService().templateBuilder().build();
|
||||
Map<String, Credentials> credentialStore = Maps.newLinkedHashMap();
|
||||
guest = adapter.createNodeWithGroupEncodedIntoNameThenStoreCredentials(group, name, template, credentialStore);
|
||||
assertEquals(guest.getHostname(), name);
|
||||
assertEquals(guest.getDomain(), group);
|
||||
// check other things, like cpu correct, mem correct, image/os is correct
|
||||
// (as possible)
|
||||
assert credentialStore.containsKey("node#" + guest.getId()) : "credentials to log into guest not found " + guest;
|
||||
assert InetAddresses.isInetAddress(guest.getPrimaryBackendIpAddress()) : guest;
|
||||
doConnectViaSsh(guest, credentialStore.get("node#" + guest.getId()));
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(VirtualGuest guest, Credentials creds) {
|
||||
SshClient ssh = computeContext.utils().sshFactory()
|
||||
.create(new IPSocket(guest.getPrimaryBackendIpAddress(), 22), creds);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
assertEquals(hello.getOutput().trim(), "hello");
|
||||
System.err.println(ssh.exec("df -k").getOutput());
|
||||
System.err.println(ssh.exec("mount").getOutput());
|
||||
System.err.println(ssh.exec("uname -a").getOutput());
|
||||
} finally {
|
||||
if (ssh != null)
|
||||
ssh.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListHardwareProfiles() {
|
||||
Iterable<Set<ProductItem>> profiles = adapter.listHardwareProfiles();
|
||||
assertFalse(Iterables.isEmpty(profiles));
|
||||
|
||||
for( Set<ProductItem> profile: profiles) {
|
||||
for (Set<ProductItem> profile : profiles) {
|
||||
// CPU, RAM and Volume
|
||||
assertEquals(profile.size(), 3);
|
||||
ProductItem cpuItem = Iterables.getOnlyElement(Iterables.filter(profile, units("PRIVATE_CORE")));
|
||||
ProductItem ramItem = Iterables.getOnlyElement(Iterables.filter(profile,categoryCode("ram")));
|
||||
Assert.assertEquals(cpuItem.getCapacity(),ramItem.getCapacity());
|
||||
ProductItem ramItem = Iterables.getOnlyElement(Iterables.filter(profile, categoryCode("ram")));
|
||||
assertEquals(cpuItem.getCapacity(), ramItem.getCapacity());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (guest != null)
|
||||
adapter.destroyNode(guest.getId() + "");
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,13 @@ package org.jclouds.softlayer.features;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -41,15 +43,16 @@ import com.google.inject.Module;
|
|||
public class BaseSoftLayerClientLiveTest {
|
||||
|
||||
protected RestContext<SoftLayerClient, SoftLayerAsyncClient> context;
|
||||
protected ComputeServiceContext computeContext;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||
|
||||
|
||||
context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule())).getProviderSpecificContext();
|
||||
computeContext = new ComputeServiceContextFactory().createContext("softlayer", identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||
context = computeContext.getProviderSpecificContext();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue