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
|
@Override
|
||||||
public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name,
|
public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name,
|
||||||
Template template, Map<String, Credentials> credentialStore) {
|
Template template, Map<String, Credentials> credentialStore) {
|
||||||
VirtualGuest from = null; // TODO create the backend object using parameters from the
|
VirtualGuest from = null; // from testCancelAndPlaceOrder()
|
||||||
// template. ex.
|
// use name for hostname as possible
|
||||||
// VirtualGuest from =
|
// you can ignore group, unless it is valid to set as domain
|
||||||
// client.getVirtualGuestClient().createServerInDC(template.getLocation().getId(), name,
|
// get the cpu, mem, datacenter from the template ids
|
||||||
// Long.parseLong(template.getImage().getProviderId()),
|
// make sure you store the credentials so that later functions can use them
|
||||||
// Long.parseLong(template.getHardware().getProviderId()));
|
// credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser (might be root),
|
||||||
// store the credentials so that later functions can use them
|
|
||||||
// credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser,
|
|
||||||
// from.password));
|
// from.password));
|
||||||
return from;
|
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.categoryCode;
|
||||||
import static org.jclouds.softlayer.predicates.ProductItemPredicates.units;
|
import static org.jclouds.softlayer.predicates.ProductItemPredicates.units;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.AssertJUnit.assertEquals;
|
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.compute.strategy.SoftLayerComputeServiceAdapter;
|
||||||
import org.jclouds.softlayer.domain.ProductItem;
|
import org.jclouds.softlayer.domain.ProductItem;
|
||||||
|
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||||
import org.jclouds.softlayer.features.BaseSoftLayerClientLiveTest;
|
import org.jclouds.softlayer.features.BaseSoftLayerClientLiveTest;
|
||||||
import org.jclouds.softlayer.features.ProductPackageClientLiveTest;
|
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.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
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 {
|
public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
|
|
||||||
private SoftLayerComputeServiceAdapter adapter;
|
private SoftLayerComputeServiceAdapter adapter;
|
||||||
|
private VirtualGuest guest;
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
adapter = new SoftLayerComputeServiceAdapter(context.getApi(), ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME);
|
adapter = new SoftLayerComputeServiceAdapter(context.getApi(),
|
||||||
|
ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,18 +62,56 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
|
||||||
assertFalse(Iterables.isEmpty(adapter.listLocations()));
|
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
|
@Test
|
||||||
public void testListHardwareProfiles() {
|
public void testListHardwareProfiles() {
|
||||||
Iterable<Set<ProductItem>> profiles = adapter.listHardwareProfiles();
|
Iterable<Set<ProductItem>> profiles = adapter.listHardwareProfiles();
|
||||||
assertFalse(Iterables.isEmpty(profiles));
|
assertFalse(Iterables.isEmpty(profiles));
|
||||||
|
|
||||||
for( Set<ProductItem> profile: profiles) {
|
for (Set<ProductItem> profile : profiles) {
|
||||||
// CPU, RAM and Volume
|
// CPU, RAM and Volume
|
||||||
assertEquals(profile.size(), 3);
|
assertEquals(profile.size(), 3);
|
||||||
ProductItem cpuItem = Iterables.getOnlyElement(Iterables.filter(profile, units("PRIVATE_CORE")));
|
ProductItem cpuItem = Iterables.getOnlyElement(Iterables.filter(profile, units("PRIVATE_CORE")));
|
||||||
ProductItem ramItem = Iterables.getOnlyElement(Iterables.filter(profile,categoryCode("ram")));
|
ProductItem ramItem = Iterables.getOnlyElement(Iterables.filter(profile, categoryCode("ram")));
|
||||||
Assert.assertEquals(cpuItem.getCapacity(),ramItem.getCapacity());
|
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 static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||||
import org.jclouds.softlayer.SoftLayerClient;
|
import org.jclouds.softlayer.SoftLayerClient;
|
||||||
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -41,15 +43,16 @@ import com.google.inject.Module;
|
||||||
public class BaseSoftLayerClientLiveTest {
|
public class BaseSoftLayerClientLiveTest {
|
||||||
|
|
||||||
protected RestContext<SoftLayerClient, SoftLayerAsyncClient> context;
|
protected RestContext<SoftLayerClient, SoftLayerAsyncClient> context;
|
||||||
|
protected ComputeServiceContext computeContext;
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||||
|
|
||||||
|
computeContext = new ComputeServiceContextFactory().createContext("softlayer", identity, credential,
|
||||||
context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential,
|
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||||
ImmutableSet.<Module> of(new Log4JLoggingModule())).getProviderSpecificContext();
|
context = computeContext.getProviderSpecificContext();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue