Fixes in live tests

This commit is contained in:
vicglarson 2011-04-20 17:39:01 +04:00 committed by Dmitri Babaev
parent 1035516c2d
commit 3899ff2f99
4 changed files with 328 additions and 194 deletions

View File

@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import org.jclouds.Constants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
@ -40,7 +39,7 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.IOException; import java.io.IOException;
@ -50,8 +49,7 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.openstack.nova.PropertyHelper.*;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails; import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.testng.Assert.*; import static org.testng.Assert.*;
@ -69,67 +67,19 @@ public class NovaClientLiveTest {
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
private Predicate<IPSocket> socketTester; private Predicate<IPSocket> socketTester;
protected String provider = "nova"; protected String provider = "nova";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
private String ip;
private String adminPass2;
private String serverPrefix = System.getProperty("user.name") + ".cs"; private String serverPrefix = System.getProperty("user.name") + ".cs";
protected Map<String, String> keyPair;
private int serverId; private int serverId;
private String adminPass; private String adminPass;
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace"); Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private int createdImageId; private int createdImageId;
protected Properties setupProperties() throws IOException { @BeforeTest
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
}
protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = properties.getProperty("test." + provider + ".endpoint");
apiversion = properties.getProperty("test." + provider + ".apiversion");
}
protected void updateProperties(final Properties properties) {
properties.setProperty(provider + ".identity", identity);
properties.setProperty(provider + ".credential", credential);
if (endpoint != null)
properties.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
properties.setProperty(provider + ".apiversion", apiversion);
}
@BeforeGroups(groups = {"live"})
public void setupClient() throws IOException { public void setupClient() throws IOException {
Properties overrides = setupProperties(); Properties properties = setupOverrides(setupProperties(this.getClass()));
setupCredentials(overrides);
updateProperties(overrides);
String identity = "admin"; Injector injector = new RestContextFactory().createContextBuilder(provider,
String credential = "d744752f-20d3-4d75-979f-f62f16033b07"; ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), properties)
// ComputeServiceContextFactory contextFactory = new ComputeServiceContextFactory();
// ComputeServiceContext context = contextFactory.createContext(provider, identity, credential, Collections.singleton(new JschSshClientModule()), overrides);
Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential,
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), overrides)
.buildInjector(); .buildInjector();
client = injector.getInstance(NovaClient.class); client = injector.getInstance(NovaClient.class);
@ -138,16 +88,16 @@ public class NovaClientLiveTest {
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger injector.injectMembers(socketOpen); // add logger
keyPair = setupKeyPair(properties);
} }
@Test @Test
public void testListServers() throws Exception { public void testListServers() throws Exception {
Set<Server> response = client.listServers(); Set<Server> response = client.listServers();
assert null != response; assert null != response;
long initialContainerCount = response.size(); long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0); assertTrue(initialContainerCount >= 0);
} }
@Test @Test
@ -216,6 +166,14 @@ public class NovaClientLiveTest {
Set<Server> response = client.listServers(withDetails()); Set<Server> response = client.listServers(withDetails());
assert null != response; assert null != response;
assertTrue(response.size() >= 0); assertTrue(response.size() >= 0);
for (Server server : response) {
Server newDetails = client.getServer(server.getId());
System.out.println("====");
System.out.println(server);
System.out.println(newDetails);
System.out.println("====");
}
for (Server server : response) { for (Server server : response) {
Server newDetails = client.getServer(server.getId()); Server newDetails = client.getServer(server.getId());
assertEquals(server, newDetails); assertEquals(server, newDetails);
@ -269,7 +227,7 @@ public class NovaClientLiveTest {
@Test(enabled = true) @Test(enabled = true)
public void testCreateServer() throws Exception { public void testCreateServer() throws Exception {
String imageRef = client.getImage(13).getURI().toASCIIString(); String imageRef = client.getImage(95).getURI().toASCIIString();
String flavorRef = client.getFlavor(1).getURI().toASCIIString(); String flavorRef = client.getFlavor(1).getURI().toASCIIString();
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt(); String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt", Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",
@ -280,10 +238,17 @@ public class NovaClientLiveTest {
serverId = server.getId(); serverId = server.getId();
adminPass = server.getAdminPass(); adminPass = server.getAdminPass();
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
Thread.sleep(2000); blockUntilPublicAddress(serverId);
client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress(); client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress();
} }
private void blockUntilPublicAddress(int serverId) throws InterruptedException {
while (client.getServer(serverId).getAddresses().getPublicAddresses().isEmpty()) {
System.out.println("Awaiting public address");
Thread.sleep(1000);
}
}
private void blockUntilServerActive(int serverId) throws InterruptedException { private void blockUntilServerActive(int serverId) throws InterruptedException {
Server currentDetails; Server currentDetails;
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client
@ -313,7 +278,7 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 300000) @Test(enabled = true, timeOut = 300000)
public void testServerDetails() throws Exception { public void testServerDetails() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
assertNotNull(server.getHostId(), "Host id: "); assertNotNull(server.getHostId(), "Host id: ");
@ -324,7 +289,7 @@ public class NovaClientLiveTest {
assertEquals(server.getMetadata(), metadata); assertEquals(server.getMetadata(), metadata);
assertEquals(server.getImageRef(), endpoint + "/v1.1/images/13"); assertEquals(server.getImageRef(), "endpoint" + "/v1.1/images/95");
// listAddresses tests.. // listAddresses tests..
assertEquals(client.getAddresses(serverId), server.getAddresses()); assertEquals(client.getAddresses(serverId), server.getAddresses());
assertEquals(server.getAddresses().getPublicAddresses().size(), 1); assertEquals(server.getAddresses().getPublicAddresses().size(), 1);
@ -332,7 +297,7 @@ public class NovaClientLiveTest {
assertEquals(server.getAddresses().getPrivateAddresses().size(), 1); assertEquals(server.getAddresses().getPrivateAddresses().size(), 1);
assertEquals(client.listPrivateAddresses(serverId), server.getAddresses().getPrivateAddresses()); assertEquals(client.listPrivateAddresses(serverId), server.getAddresses().getPrivateAddresses());
assertPassword(server, adminPass); assertPassword(server, adminPass);
assertEquals(server.getFlavorRef(), endpoint + "/v1.1/flavors/1"); assertEquals(server.getFlavorRef(), "endpoint" + "/v1.1/flavors/1");
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress(); assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
} }
@ -341,7 +306,7 @@ public class NovaClientLiveTest {
IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0).getAddress(), 22); IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0).getAddress(), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass)); SshClient client = sshFactory.create(socket, new Credentials("root", keyPair.get("private")));
try { try {
client.connect(); client.connect();
Payload etcPasswd = client.get("/etc/jclouds.txt"); Payload etcPasswd = client.get("/etc/jclouds.txt");
@ -355,7 +320,7 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 5 * 60 * 1000) @Test(enabled = true, timeOut = 5 * 60 * 1000)
public void testRenameServer() throws Exception { public void testRenameServer() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
String oldName = server.getName(); String oldName = server.getName();
client.renameServer(serverId, oldName + "new"); client.renameServer(serverId, oldName + "new");
@ -365,7 +330,7 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 5 * 60 * 1000) @Test(enabled = true, timeOut = 5 * 60 * 1000)
public void testChangePassword() throws Exception { public void testChangePassword() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
client.changeAdminPass(serverId, "elmo"); client.changeAdminPass(serverId, "elmo");
assertPassword(client.getServer(serverId), "elmo"); assertPassword(client.getServer(serverId), "elmo");
@ -374,7 +339,7 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 10 * 600 * 1000) @Test(enabled = true, timeOut = 10 * 600 * 1000)
public void testCreateImage() throws Exception { public void testCreateImage() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
Image image = client.createImageFromServer("hoofie", serverId); Image image = client.createImageFromServer("hoofie", serverId);
assertEquals("hoofie", image.getName()); assertEquals("hoofie", image.getName());
assertEquals(serverId, image.getServerRef()); assertEquals(serverId, image.getServerRef());
@ -384,7 +349,7 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 10 * 60 * 1000) @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebuildServer() throws Exception { public void testRebuildServer() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
client.rebuildServer(serverId, new RebuildServerOptions().withImage(String.valueOf(createdImageId))); client.rebuildServer(serverId, new RebuildServerOptions().withImage(String.valueOf(createdImageId)));
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
// issue Web Hosting #119580 createdImageId comes back incorrect after rebuild // issue Web Hosting #119580 createdImageId comes back incorrect after rebuild
@ -393,21 +358,21 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 10 * 60 * 1000) @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebootHard() throws Exception { public void testRebootHard() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
client.rebootServer(serverId, RebootType.HARD); client.rebootServer(serverId, RebootType.HARD);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
} }
@Test(enabled = true, timeOut = 10 * 60 * 1000) @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebootSoft() throws Exception { public void testRebootSoft() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
client.rebootServer(serverId, RebootType.SOFT); client.rebootServer(serverId, RebootType.SOFT);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
} }
@Test(enabled = false, timeOut = 60000, dependsOnMethods = "testRebootSoft") @Test(enabled = false, timeOut = 60000, dependsOnMethods = "testRebootSoft")
public void testRevertResize() throws Exception { public void testRevertResize() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
client.resizeServer(serverId, 2); client.resizeServer(serverId, 2);
blockUntilServerVerifyResize(serverId); blockUntilServerVerifyResize(serverId);
client.revertResizeServer(serverId); client.revertResizeServer(serverId);
@ -417,7 +382,7 @@ public class NovaClientLiveTest {
@Test(enabled = false, timeOut = 10 * 60 * 1000) @Test(enabled = false, timeOut = 10 * 60 * 1000)
public void testConfirmResize() throws Exception { public void testConfirmResize() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
client.resizeServer(serverId, 2); client.resizeServer(serverId, 2);
blockUntilServerVerifyResize(serverId); blockUntilServerVerifyResize(serverId);
client.confirmResizeServer(serverId); client.confirmResizeServer(serverId);
@ -427,11 +392,12 @@ public class NovaClientLiveTest {
@Test(enabled = true, timeOut = 60000) @Test(enabled = true, timeOut = 60000)
void deleteServer2() throws Exception { void deleteServer2() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
if (serverId > 0) { if (serverId > 0) {
client.deleteServer(serverId); client.deleteServer(serverId);
waitServerDeleted(serverId); waitServerDeleted(serverId);
} }
serverId = 0;
} }
@Test(enabled = true, timeOut = 60000) @Test(enabled = true, timeOut = 60000)
@ -443,25 +409,43 @@ public class NovaClientLiveTest {
client.deleteImage(createdImageId); client.deleteImage(createdImageId);
assert client.getImage(createdImageId) == null; assert client.getImage(createdImageId) == null;
} }
//TODO all servers created from the image should be deleted
} }
@Test(enabled = true, timeOut = 60000) @Test(enabled = true, timeOut = 60000)
void deleteServer1() throws Exception { void deleteServer1() throws Exception {
if (serverId <= 0) testCreateServer(); if (!isServerExist(serverId)) testCreateServer();
if (serverId > 0) { if (serverId > 0) {
client.deleteServer(serverId); client.deleteServer(serverId);
waitServerDeleted(serverId); waitServerDeleted(serverId);
} }
serverId = 0;
}
private boolean isServerExist(int serverId) {
return client.getServer(serverId) != null;
} }
private void waitServerDeleted(int serverId) throws InterruptedException { private void waitServerDeleted(int serverId) throws InterruptedException {
while (null != client.getServer(serverId)) Thread.sleep(1000); while (null != client.getServer(serverId)) {
System.out.println("Await deleted server" + serverId);
Thread.sleep(1000);
}
}
@Test
public void testDeleteAllCreatedServers() {
for (Server server : client.listServers()) {
if (server.getName().startsWith(serverPrefix)) {
client.deleteServer(server.getId());
System.out.println("Deleted server: " + server);
}
}
} }
@AfterTest @AfterTest
void deleteServersOnEnd() { void deleteServersOnEnd() {
if (serverId > 0) { testDeleteAllCreatedServers();
client.deleteServer(serverId);
}
} }
} }

View File

@ -1,5 +1,14 @@
package org.jclouds.openstack.nova; package org.jclouds.openstack.nova;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import org.jclouds.Constants;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
@ -8,10 +17,40 @@ import java.util.Properties;
public class PropertyHelper { public class PropertyHelper {
public static String provider = "nova";
public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) { public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}")) if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName)); properties.setProperty(propertyName, System.getProperty(propertyName));
} }
public static Map<String, String> setupKeyPair(Properties properties) throws FileNotFoundException, IOException {
return ImmutableMap.<String, String>of(
"private", Files.toString(new File(properties.getProperty("test.ssh.keyfile.private")), Charsets.UTF_8),
"public", Files.toString(new File(properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8));
}
public static Properties setupProperties(Class clazz) throws IOException {
Properties properties = new Properties();
properties.load(clazz.getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(properties, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(properties, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(properties, "test." + provider + ".identity");
overridePropertyFromSystemProperty(properties, "test." + provider + ".credential");
overridePropertyFromSystemProperty(properties, "test.initializer");
return properties;
}
public static Properties setupOverrides(final Properties properties) {
properties.setProperty(provider + ".identity", properties.getProperty("test." + provider + ".identity"));
properties.setProperty(provider + ".credential", properties.getProperty("test." + provider + ".credential"));
properties.setProperty(provider + ".endpoint", properties.getProperty("test." + provider + ".endpoint"));
properties.setProperty(provider + ".apiversion", "test." + provider + ".apiversion");
properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return properties;
}
} }

View File

@ -18,63 +18,15 @@
*/ */
package org.jclouds.openstack.nova.compute; package org.jclouds.openstack.nova.compute;
import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Function;
import static com.google.common.base.Predicates.and; import com.google.common.base.Predicate;
import static com.google.common.base.Predicates.not; import com.google.common.collect.ImmutableSet;
import static com.google.common.base.Throwables.getRootCause; import com.google.common.collect.Iterables;
import static com.google.common.collect.Iterables.concat; import com.google.inject.Guice;
import static com.google.common.collect.Iterables.get; import com.google.inject.Module;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Sets.filter;
import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.blockOnComplete;
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCredentialsWith;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import static org.jclouds.compute.predicates.NodePredicates.runningInGroup;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.*;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.*;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.RunScriptData;
import org.jclouds.compute.RunScriptOnNodesException;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -96,15 +48,31 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets; import java.io.IOException;
import com.google.common.base.Function; import java.util.*;
import com.google.common.base.Predicate; import java.util.concurrent.ExecutionException;
import com.google.common.collect.ImmutableMap; import java.util.concurrent.TimeUnit;
import com.google.common.collect.ImmutableSet; import java.util.concurrent.TimeoutException;
import com.google.common.collect.Iterables;
import com.google.common.io.Files; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.inject.Guice; import static com.google.common.base.Predicates.and;
import com.google.inject.Module; import static com.google.common.base.Predicates.not;
import static com.google.common.base.Throwables.getRootCause;
import static com.google.common.collect.Iterables.*;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Sets.filter;
import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.blockOnComplete;
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCredentialsWith;
import static org.jclouds.compute.predicates.NodePredicates.*;
import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.jclouds.openstack.nova.PropertyHelper.setupKeyPair;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
/** /**
* Generally disabled, as it incurs higher fees. * Generally disabled, as it incurs higher fees.
@ -119,7 +87,7 @@ public class NovaComputeServiceLiveTest {
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<IPSocket> socketTester;
protected SortedSet<NodeMetadata> nodes; protected SortedSet<NodeMetadata> nodes;
protected ComputeServiceContext context; protected ComputeServiceContext context;
protected ComputeService client; protected ComputeService computeService;
protected Template template; protected Template template;
protected Map<String, String> keyPair; protected Map<String, String> keyPair;
@ -181,13 +149,7 @@ public class NovaComputeServiceLiveTest {
context.close(); context.close();
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of( context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of(
new SLF4JLoggingModule(), getSshModule()), properties); new SLF4JLoggingModule(), getSshModule()), properties);
client = context.getComputeService(); computeService = context.getComputeService();
}
public static Map<String, String> setupKeyPair(Properties properties) throws FileNotFoundException, IOException {
return ImmutableMap.<String, String>of(
"private", Files.toString(new File(properties.getProperty("test.ssh.keyfile.private")), Charsets.UTF_8),
"public", Files.toString(new File(properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8));
} }
@ -270,33 +232,33 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true) @Test(enabled = true)
public void testImagesCache() throws Exception { public void testImagesCache() throws Exception {
client.listImages(); computeService.listImages();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
client.listImages(); computeService.listImages();
long duration = System.currentTimeMillis() - time; long duration = System.currentTimeMillis() - time;
assert duration < 1000 : String.format("%dms to get images", duration); assert duration < 1000 : String.format("%dms to get images", duration);
} }
@Test(enabled = true, expectedExceptions = NoSuchElementException.class) @Test(enabled = true, expectedExceptions = NoSuchElementException.class)
public void testCorrectExceptionRunningNodesNotFound() throws Exception { public void testCorrectExceptionRunningNodesNotFound() throws Exception {
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), buildScript(new OperatingSystem.Builder() computeService.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), buildScript(new OperatingSystem.Builder()
.family(OsFamily.UBUNTU).description("ffoo").build())); .family(OsFamily.UBUNTU).description("ffoo").build()));
} }
// since surefire and eclipse don't otherwise guarantee the order, we are // since surefire and eclipse don't otherwise guarantee the order, we are
// starting this one alphabetically before create2nodes.. // starting this one alphabetically before create2nodes..
@Test(enabled = true, dependsOnMethods = {"testCompareSizes"}) @Test(enabled = true)
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
String group = this.group + "r"; String group = this.group + "r";
try { try {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} catch (Exception e) { } catch (Exception e) {
} }
TemplateOptions options = client.templateOptions().blockOnPort(22, 120); Template template = getDefaultTemplateBuilder().options(computeService.templateOptions().blockOnPort(22, 120)).build();
try { try {
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options); Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(group, 1, template);
Credentials good = nodes.iterator().next().getCredentials(); Credentials good = nodes.iterator().next().getCredentials();
assert good.identity != null : nodes; assert good.identity != null : nodes;
assert good.credential != null : nodes; assert good.credential != null : nodes;
@ -310,7 +272,7 @@ public class NovaComputeServiceLiveTest {
assert getRootCause(e).getMessage().contains("Auth fail") : e; assert getRootCause(e).getMessage().contains("Auth fail") : e;
} }
for (Map.Entry<? extends NodeMetadata, ExecResponse> response : client.runScriptOnNodesMatching( for (Map.Entry<? extends NodeMetadata, ExecResponse> response : computeService.runScriptOnNodesMatching(
runningInGroup(group), Statements.exec("echo hello"), runningInGroup(group), Statements.exec("echo hello"),
overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet()) overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet())
assert response.getValue().getOutput().trim().equals("hello") : response.getKey() + ": " assert response.getValue().getOutput().trim().equals("hello") : response.getKey() + ": "
@ -321,14 +283,14 @@ public class NovaComputeServiceLiveTest {
checkNodes(nodes, group); checkNodes(nodes, group);
} finally { } finally {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} }
} }
@Test(enabled = true, dependsOnMethods = {"testImagesCache"}) @Test(enabled = true, dependsOnMethods = {"testImagesCache"})
public void testTemplateMatch() throws Exception { public void testTemplateMatch() throws Exception {
template = buildTemplate(client.templateBuilder()); template = buildTemplate(computeService.templateBuilder());
Template toMatch = client.templateBuilder().imageId(template.getImage().getId()).build(); Template toMatch = computeService.templateBuilder().imageId(template.getImage().getId()).build();
assertEquals(toMatch.getImage(), template.getImage()); assertEquals(toMatch.getImage(), template.getImage());
} }
@ -339,13 +301,13 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCompareSizes") @Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testCreateTwoNodesWithRunScript() throws Exception { public void testCreateTwoNodesWithRunScript() throws Exception {
try { try {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
} }
refreshTemplate(); refreshTemplate();
try { try {
nodes = newTreeSet(client.createNodesInGroup(group, 2, template)); nodes = newTreeSet(computeService.createNodesInGroup(group, 2, template));
} catch (RunNodesException e) { } catch (RunNodesException e) {
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
throw e; throw e;
@ -366,7 +328,7 @@ public class NovaComputeServiceLiveTest {
} }
private void refreshTemplate() { private void refreshTemplate() {
template = buildTemplate(client.templateBuilder()); template = buildTemplate(computeService.templateBuilder());
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
.runScript(buildScript(template.getImage().getOperatingSystem())); .runScript(buildScript(template.getImage().getOperatingSystem()));
@ -396,7 +358,7 @@ public class NovaComputeServiceLiveTest {
public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception {
initializeContextAndClient(overrides); initializeContextAndClient(overrides);
refreshTemplate(); refreshTemplate();
TreeSet<NodeMetadata> nodes = newTreeSet(client.createNodesInGroup(group, 1, template)); TreeSet<NodeMetadata> nodes = newTreeSet(computeService.createNodesInGroup(group, 1, template));
checkNodes(nodes, group); checkNodes(nodes, group);
NodeMetadata node = nodes.first(); NodeMetadata node = nodes.first();
this.nodes.add(node); this.nodes.add(node);
@ -415,7 +377,7 @@ public class NovaComputeServiceLiveTest {
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String group, OperatingSystem os, protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String group, OperatingSystem os,
Credentials creds) throws RunScriptOnNodesException { Credentials creds) throws RunScriptOnNodesException {
try { try {
return client.runScriptOnNodesMatching(runningInGroup(group), buildScript(os), overrideCredentialsWith(creds) return computeService.runScriptOnNodesMatching(runningInGroup(group), buildScript(os), overrideCredentialsWith(creds)
.nameTask("runScriptWithCreds")); .nameTask("runScriptWithCreds"));
} catch (SshException e) { } catch (SshException e) {
throw e; throw e;
@ -429,7 +391,7 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception { public void testGet() throws Exception {
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(computeService
.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))), .listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))),
new Function<NodeMetadata, String>() { new Function<NodeMetadata, String>() {
@ -441,7 +403,7 @@ public class NovaComputeServiceLiveTest {
})); }));
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
metadataMap.remove(node.getId()); metadataMap.remove(node.getId());
NodeMetadata metadata = client.getNodeMetadata(node.getId()); NodeMetadata metadata = computeService.getNodeMetadata(node.getId());
assertEquals(metadata.getProviderId(), node.getProviderId()); assertEquals(metadata.getProviderId(), node.getProviderId());
assertEquals(metadata.getGroup(), node.getGroup()); assertEquals(metadata.getGroup(), node.getGroup());
assertLocationSameOrChild(metadata.getLocation(), template.getLocation()); assertLocationSameOrChild(metadata.getLocation(), template.getLocation());
@ -462,14 +424,14 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testGet") @Test(enabled = true, dependsOnMethods = "testGet")
public void testReboot() throws Exception { public void testReboot() throws Exception {
client.rebootNodesMatching(inGroup(group));// TODO test computeService.rebootNodesMatching(inGroup(group));// TODO test
// validation // validation
testGet(); testGet();
} }
@Test(enabled = true, dependsOnMethods = "testReboot") @Test(enabled = true, dependsOnMethods = "testReboot")
public void testSuspendResume() throws Exception { public void testSuspendResume() throws Exception {
client.suspendNodesMatching(inGroup(group)); computeService.suspendNodesMatching(inGroup(group));
Set<? extends NodeMetadata> stoppedNodes = refreshNodes(); Set<? extends NodeMetadata> stoppedNodes = refreshNodes();
@ -485,13 +447,13 @@ public class NovaComputeServiceLiveTest {
}) : stoppedNodes; }) : stoppedNodes;
client.resumeNodesMatching(inGroup(group)); computeService.resumeNodesMatching(inGroup(group));
testGet(); testGet();
} }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Test(enabled = true, dependsOnMethods = "testSuspendResume")
public void testListNodes() throws Exception { public void testListNodes() throws Exception {
for (ComputeMetadata node : client.listNodes()) { for (ComputeMetadata node : computeService.listNodes()) {
assert node.getProviderId() != null; assert node.getProviderId() != null;
assert node.getLocation() != null; assert node.getLocation() != null;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
@ -500,7 +462,7 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Test(enabled = true, dependsOnMethods = "testSuspendResume")
public void testGetNodesWithDetails() throws Exception { public void testGetNodesWithDetails() throws Exception {
for (NodeMetadata node : client.listNodesDetailsMatching(all())) { for (NodeMetadata node : computeService.listNodesDetailsMatching(all())) {
assert node.getProviderId() != null : node; assert node.getProviderId() != null : node;
assert node.getLocation() != null : node; assert node.getLocation() != null : node;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
@ -522,16 +484,16 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = {"testListNodes", "testGetNodesWithDetails"}) @Test(enabled = true, dependsOnMethods = {"testListNodes", "testGetNodesWithDetails"})
public void testDestroyNodes() { public void testDestroyNodes() {
int toDestroy = refreshNodes().size(); int toDestroy = refreshNodes().size();
Set<? extends NodeMetadata> destroyed = client.destroyNodesMatching(inGroup(group)); Set<? extends NodeMetadata> destroyed = computeService.destroyNodesMatching(inGroup(group));
assertEquals(toDestroy, destroyed.size()); assertEquals(toDestroy, destroyed.size());
for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), inGroup(group))) { for (NodeMetadata node : filter(computeService.listNodesDetailsMatching(all()), inGroup(group))) {
assert node.getState() == NodeState.TERMINATED : node; assert node.getState() == NodeState.TERMINATED : node;
assertEquals(context.getCredentialStore().get("node#" + node.getId()), null); assertEquals(context.getCredentialStore().get("node#" + node.getId()), null);
} }
} }
private Set<? extends NodeMetadata> refreshNodes() { private Set<? extends NodeMetadata> refreshNodes() {
return filter(client.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))); return filter(computeService.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED)));
} }
@Test(enabled = true) @Test(enabled = true)
@ -539,12 +501,12 @@ public class NovaComputeServiceLiveTest {
String group = this.group + "s"; String group = this.group + "s";
try { try {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} catch (Exception e) { } catch (Exception e) {
} }
template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080)) template = getDefaultTemplateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080))
.build(); .build();
// note this is a dependency on the template resolution // note this is a dependency on the template resolution
@ -552,11 +514,11 @@ public class NovaComputeServiceLiveTest {
RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage()
.getOperatingSystem())); .getOperatingSystem()));
try { try {
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template)); NodeMetadata node = getOnlyElement(computeService.createNodesInGroup(group, 1, template));
checkHttpGet(node); checkHttpGet(node);
} finally { } finally {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} }
} }
@ -564,12 +526,12 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true/* , dependsOnMethods = "testCompareSizes" */) @Test(enabled = true/* , dependsOnMethods = "testCompareSizes" */)
public void testTemplateOptions() throws Exception { public void testTemplateOptions() throws Exception {
TemplateOptions options = new TemplateOptions().withMetadata(); TemplateOptions options = new TemplateOptions().withMetadata();
Template t = client.templateBuilder().smallest().options(options).build(); Template t = computeService.templateBuilder().smallest().options(options).build();
assert t.getOptions().isIncludeMetadata() : "The metadata option should be 'true' " + "for the created template"; assert t.getOptions().isIncludeMetadata() : "The metadata option should be 'true' " + "for the created template";
} }
public void testListImages() throws Exception { public void testListImages() throws Exception {
for (Image image : client.listImages()) { for (Image image : computeService.listImages()) {
assert image.getProviderId() != null : image; assert image.getProviderId() != null : image;
// image.getLocationId() can be null, if it is a location-free image // image.getLocationId() can be null, if it is a location-free image
assertEquals(image.getType(), ComputeType.IMAGE); assertEquals(image.getType(), ComputeType.IMAGE);
@ -578,7 +540,7 @@ public class NovaComputeServiceLiveTest {
@Test(groups = {"integration", "live"}) @Test(groups = {"integration", "live"})
public void testGetAssignableLocations() throws Exception { public void testGetAssignableLocations() throws Exception {
for (Location location : client.listAssignableLocations()) { for (Location location : computeService.listAssignableLocations()) {
System.err.printf("location %s%n", location); System.err.printf("location %s%n", location);
assert location.getId() != null : location; assert location.getId() != null : location;
assert location != location.getParent() : location; assert location != location.getParent() : location;
@ -611,21 +573,21 @@ public class NovaComputeServiceLiveTest {
public void testOptionToNotBlock() throws Exception { public void testOptionToNotBlock() throws Exception {
String group = this.group + "block"; String group = this.group + "block";
try { try {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} catch (Exception e) { } catch (Exception e) {
} }
// no inbound ports // no inbound ports
TemplateOptions options = client.templateOptions().blockUntilRunning(false).inboundPorts(); TemplateOptions options = computeService.templateOptions().blockUntilRunning(false).inboundPorts();
try { try {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options); Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(group, 1, options);
NodeMetadata node = getOnlyElement(nodes); NodeMetadata node = getOnlyElement(nodes);
assert node.getState() != NodeState.RUNNING; assert node.getState() != NodeState.RUNNING;
long duration = System.currentTimeMillis() - time; long duration = System.currentTimeMillis() - time;
assert duration < 30 * 1000 : "duration longer than 30 seconds!: " + duration / 1000; assert duration < 30 * 1000 : "duration longer than 30 seconds!: " + duration / 1000;
} finally { } finally {
client.destroyNodesMatching(inGroup(group)); computeService.destroyNodesMatching(inGroup(group));
} }
} }
@ -635,7 +597,7 @@ public class NovaComputeServiceLiveTest {
} }
public void testListSizes() throws Exception { public void testListSizes() throws Exception {
for (Hardware hardware : client.listHardwareProfiles()) { for (Hardware hardware : computeService.listHardwareProfiles()) {
assert hardware.getProviderId() != null; assert hardware.getProviderId() != null;
assert getCores(hardware) > 0; assert getCores(hardware) > 0;
assert hardware.getVolumes().size() >= 0; assert hardware.getVolumes().size() >= 0;
@ -644,13 +606,19 @@ public class NovaComputeServiceLiveTest {
} }
} }
private TemplateBuilder getDefaultTemplateBuilder() {
return computeService.templateBuilder().imageId("95");
}
@Test(enabled = true) @Test(enabled = true)
public void testCompareSizes() throws Exception { public void testCompareSizes() throws Exception {
Hardware defaultSize = client.templateBuilder().build().getHardware(); TemplateBuilder templateBuilder = getDefaultTemplateBuilder();
Hardware smallest = client.templateBuilder().smallest().build().getHardware(); Hardware defaultSize = templateBuilder.build().getHardware();
Hardware fastest = client.templateBuilder().fastest().build().getHardware();
Hardware biggest = client.templateBuilder().biggest().build().getHardware(); Hardware smallest = templateBuilder.smallest().build().getHardware();
Hardware fastest = templateBuilder.fastest().build().getHardware();
Hardware biggest = templateBuilder.biggest().build().getHardware();
System.out.printf("smallest %s%n", smallest); System.out.printf("smallest %s%n", smallest);
System.out.printf("fastest %s%n", fastest); System.out.printf("fastest %s%n", fastest);

View File

@ -0,0 +1,143 @@
/**
*
* Copyright (C) 2010 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.openstack.nova.live;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import org.jclouds.Constants;
import org.jclouds.http.HttpResponseException;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
/**
* @author Victor Galkin
*/
@Test(groups = "live", sequential = true)
public class DeleteServersInVariousStatesLiveTest {
protected NovaClient client;
protected SshClient.Factory sshFactory;
private Predicate<IPSocket> socketTester;
protected String provider = "nova";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
Server server = null;
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
}
protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = properties.getProperty("test." + provider + ".endpoint");
apiversion = properties.getProperty("test." + provider + ".apiversion");
}
protected void updateProperties(final Properties properties) {
properties.setProperty(provider + ".identity", identity);
properties.setProperty(provider + ".credential", credential);
if (endpoint != null)
properties.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
properties.setProperty(provider + ".apiversion", apiversion);
}
@Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = ".*Internal Server Error.*")
public void testCreateServerWithUnknownImage() throws Exception {
try {
server = client.createServer("serverName", String.valueOf(88888888), "1", withFile("/etc/jclouds.txt",
"rackspace".getBytes()).withMetadata(metadata));
} catch (HttpResponseException e) {
throw e;
}
}
@Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = ".*Internal Server Error.*")
public void testCreateServerWithUnknownFlavor() throws Exception {
try {
server = client.createServer("serverName", String.valueOf(13), "88888888", withFile("/etc/jclouds.txt",
"rackspace".getBytes()).withMetadata(metadata));
} catch (HttpResponseException e) {
throw e;
}
}
@AfterMethod
public void after() {
if (server != null) client.deleteServer(server.getId());
}
@Test(enabled = true)
public void testCreateServer() throws Exception {
// String imageRef = client.getImage(13).getURI().toASCIIString();
// String flavorRef = client.getFlavor(1).getURI().toASCIIString();
// String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
// Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",
// "rackspace".getBytes()).withMetadata(metadata));
//
// assertNotNull(server.getAdminPass());
// assertEquals(server.getStatus(), ServerStatus.BUILD);
// serverId = server.getId();
// adminPass = server.getAdminPass();
// blockUntilServerActive(serverId);
// client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress();
}
private void blockUntilServerActive(int serverId) throws InterruptedException {
Server currentDetails;
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client
.getServer(serverId)) {
System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000);
}
}
}