Ignored some asserts

This commit is contained in:
vicglarson 2011-04-16 03:55:35 +04:00 committed by Dmitri Babaev
parent a48850f1ac
commit a2ec3ba34c
1 changed files with 368 additions and 374 deletions

View File

@ -51,6 +51,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull; 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; 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.*;
@ -73,12 +74,30 @@ public class NovaClientLiveTest {
protected String endpoint; protected String endpoint;
protected String apiversion; protected String apiversion;
private void overridePropertyFromSystemProperty(final Properties properties, String propertyName) { private String serverPrefix = System.getProperty("user.name") + ".cs";
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}")) private int serverId;
properties.setProperty(propertyName, System.getProperty(propertyName)); private String adminPass;
} Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private String ip;
private int serverId2;
private String adminPass2;
private int imageId;
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) { protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
@ -96,19 +115,6 @@ public class NovaClientLiveTest {
properties.setProperty(provider + ".apiversion", apiversion); properties.setProperty(provider + ".apiversion", apiversion);
} }
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;
}
@BeforeGroups(groups = {"live"}) @BeforeGroups(groups = {"live"})
public void setupClient() throws IOException { public void setupClient() throws IOException {
@ -208,14 +214,14 @@ public class NovaClientLiveTest {
public void testGetServersDetail() throws Exception { public void testGetServersDetail() throws Exception {
Set<Server> response = client.listServers(withDetails()); Set<Server> response = client.listServers(withDetails());
assert null != response; assert null != response;
long serverCount = response.size(); assertTrue(response.size() >= 0);
assertTrue(serverCount >= 0);
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);
} }
} }
@Test
public void testListFlavors() throws Exception { public void testListFlavors() throws Exception {
Set<Flavor> response = client.listFlavors(); Set<Flavor> response = client.listFlavors();
assert null != response; assert null != response;
@ -228,6 +234,7 @@ public class NovaClientLiveTest {
} }
@Test
public void testListFlavorsDetail() throws Exception { public void testListFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors(withDetails()); Set<Flavor> response = client.listFlavors(withDetails());
assert null != response; assert null != response;
@ -241,6 +248,7 @@ public class NovaClientLiveTest {
} }
} }
@Test
public void testGetFlavorsDetail() throws Exception { public void testGetFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors(withDetails()); Set<Flavor> response = client.listFlavors(withDetails());
assert null != response; assert null != response;
@ -257,29 +265,20 @@ public class NovaClientLiveTest {
assert client.getFlavor(12312987) == null; assert client.getFlavor(12312987) == null;
} }
private String serverPrefix = System.getProperty("user.name") + ".cs";
private int serverId;
private String adminPass;
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private String ip;
private int serverId2;
private String adminPass2;
private int imageId;
@Test(enabled = true) @Test(enabled = true)
public void testCreateServer() throws Exception { public void testCreateServer() throws Exception {
String imageRef = "14362"; String imageRef = client.getImage(13).getURI().toASCIIString();
String flavorRef = "1"; 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",
"rackspace".getBytes()).withMetadata(metadata)); "rackspace".getBytes()).withMetadata(metadata));
assertNotNull(server.getAdminPass()); assertNotNull(server.getAdminPass());
assertEquals(server.getStatus(), ServerStatus.BUILD);
serverId = server.getId(); serverId = server.getId();
adminPass = server.getAdminPass(); adminPass = server.getAdminPass();
ip = server.getAddresses().getPublicAddresses().iterator().next().getAddress();
assertEquals(server.getStatus(), ServerStatus.BUILD);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
ip = client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next();
} }
private void blockUntilServerActive(int serverId) throws InterruptedException { private void blockUntilServerActive(int serverId) throws InterruptedException {
@ -309,16 +308,23 @@ public class NovaClientLiveTest {
} }
} }
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") @Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testServerDetails() throws Exception { public void testServerDetails() throws Exception {
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
assertNotNull(server.getHostId()); assertNotNull(server.getHostId());
assertEquals(server.getStatus(), ServerStatus.ACTIVE); assertEquals(server.getStatus(), ServerStatus.ACTIVE);
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
assertEquals(new Integer(14362), server.getImageRef());
assertEquals(new Integer(1), server.getFlavorRef());
assertNotNull(server.getAddresses()); assertNotNull(server.getAddresses());
// check metadata
assertEquals(server.getMetadata(), metadata);
assertPassword(server, adminPass);
assertEquals(server.getFlavorRef(), endpoint + "/flavors/1");
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
assertEquals(server.getImageRef(), endpoint + "/images/13");
// 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);
@ -326,23 +332,11 @@ 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());
// check metadata
assertEquals(server.getMetadata(), metadata);
checkPassOk(server, adminPass);
}
/**
* this tests "personality" as the file looked up was sent during server creation
*/
private void checkPassOk(Server newDetails, String pass) throws IOException {
doCheckPass(newDetails, pass);
} }
private void doCheckPass(Server newDetails, String pass) throws IOException { private void assertPassword(Server server, String pass) throws IOException {
IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0).getAddress(), 22); IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass)); SshClient client = sshFactory.create(socket, new Credentials("root", pass));
@ -358,7 +352,7 @@ public class NovaClientLiveTest {
} }
private ExecResponse exec(Server details, String pass, String command) throws IOException { private ExecResponse exec(Server details, String pass, String command) throws IOException {
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0).getAddress(), 22); IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass)); SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try { try {
@ -383,7 +377,7 @@ public class NovaClientLiveTest {
public void testChangePassword() throws Exception { public void testChangePassword() throws Exception {
client.changeAdminPass(serverId, "elmo"); client.changeAdminPass(serverId, "elmo");
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
checkPassOk(client.getServer(serverId), "elmo"); assertPassword(client.getServer(serverId), "elmo");
this.adminPass = "elmo"; this.adminPass = "elmo";
} }
@ -420,7 +414,7 @@ public class NovaClientLiveTest {
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId)); client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
// issue Web Hosting #119580 imageId comes back incorrect after rebuild // issue Web Hosting #119580 imageId comes back incorrect after rebuild
assertEquals(new Integer(imageId), client.getServer(serverId).getImageRef()); assertEquals(imageId, client.getServer(serverId).getImageRef());
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
@ -481,7 +475,7 @@ public class NovaClientLiveTest {
@AfterTest @AfterTest
void deleteServersOnEnd() { void deleteServersOnEnd() {
if (serverId > 0) { if (serverId > 0) {
client.deleteServer(serverId); //client.deleteServer(serverId);
} }
if (serverId2 > 0) { if (serverId2 > 0) {
client.deleteServer(serverId2); client.deleteServer(serverId2);