Fixes in live tests

This commit is contained in:
vicglarson 2011-04-18 20:15:56 +04:00 committed by Dmitri Babaev
parent f52f331be9
commit 7f02824928
4 changed files with 238 additions and 91 deletions

View File

@ -26,7 +26,6 @@ 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.Constants;
import org.jclouds.compute.domain.ExecResponse;
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;
@ -75,15 +74,16 @@ public class NovaClientLiveTest {
protected String endpoint; protected String endpoint;
protected String apiversion; 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";
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 String ip; private int createdImageId;
private int serverId2;
private String adminPass2;
private int imageId;
protected Properties setupProperties() throws IOException { protected Properties setupProperties() throws IOException {
Properties overrides = new Properties(); Properties overrides = new Properties();
@ -266,6 +266,7 @@ public class NovaClientLiveTest {
assert client.getFlavor(12312987) == null; assert client.getFlavor(12312987) == null;
} }
@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(13).getURI().toASCIIString();
@ -279,7 +280,8 @@ public class NovaClientLiveTest {
serverId = server.getId(); serverId = server.getId();
adminPass = server.getAdminPass(); adminPass = server.getAdminPass();
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
ip = client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress(); Thread.sleep(2000);
client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress();
} }
private void blockUntilServerActive(int serverId) throws InterruptedException { private void blockUntilServerActive(int serverId) throws InterruptedException {
@ -300,39 +302,38 @@ public class NovaClientLiveTest {
} }
} }
private void blockUntilImageActive(int imageId) throws InterruptedException { private void blockUntilImageActive(int createdImageId) throws InterruptedException {
Image currentDetails; Image currentDetails;
for (currentDetails = client.getImage(imageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client for (currentDetails = client.getImage(createdImageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
.getImage(imageId)) { .getImage(createdImageId)) {
System.out.printf("blocking on status active%n%s%n", currentDetails); System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000); Thread.sleep(5 * 1000);
} }
} }
@Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") @Test(enabled = true, timeOut = 300000)
public void testServerDetails() throws Exception { public void testServerDetails() throws Exception {
if (serverId <= 0) testCreateServer();
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);
assertNotNull(server.getAddresses()); assertNotNull(server.getAddresses());
// check metadata // check metadata
assertEquals(server.getMetadata(), 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 + "/v1.1/images/13");
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);
assertEquals(client.listPublicAddresses(serverId), server.getAddresses().getPublicAddresses()); assertEquals(client.listPublicAddresses(serverId), server.getAddresses().getPublicAddresses());
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);
assertEquals(server.getFlavorRef(), endpoint + "/v1.1/flavors/1");
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
} }
@ -352,21 +353,9 @@ public class NovaClientLiveTest {
} }
} }
private ExecResponse exec(Server details, String pass, String command) throws IOException { @Test(enabled = true, timeOut = 5 * 60 * 1000)
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0).getAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try {
client.connect();
return client.exec(command);
} finally {
if (client != null)
client.disconnect();
}
}
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testRenameServer() throws Exception { public void testRenameServer() throws Exception {
if (serverId <= 0) 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");
@ -374,99 +363,92 @@ public class NovaClientLiveTest {
assertEquals(oldName + "new", client.getServer(serverId).getName()); assertEquals(oldName + "new", client.getServer(serverId).getName());
} }
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer") @Test(enabled = true, timeOut = 5 * 60 * 1000)
public void testChangePassword() throws Exception { public void testChangePassword() throws Exception {
if (serverId <= 0) testCreateServer();
client.changeAdminPass(serverId, "elmo"); client.changeAdminPass(serverId, "elmo");
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
assertPassword(client.getServer(serverId), "elmo"); assertPassword(client.getServer(serverId), "elmo");
this.adminPass = "elmo"; this.adminPass = "elmo";
} }
private void assertIpConfigured(Server server, String password) { @Test(enabled = true, timeOut = 10 * 60 * 1000)
try {
ExecResponse response = exec(server, password, "ifconfig -a");
assert response.getOutput().indexOf(ip) > 0 : String.format("server %s didn't get ip %s%n%s", server, ip,
response);
} catch (Exception e) {
e.printStackTrace();
} catch (AssertionError e) {
e.printStackTrace();
}
}
private void assertIpNotConfigured(Server server, String password) throws IOException {
ExecResponse response = exec(server, password, "ifconfig -a");
assert response.getOutput().indexOf(ip) == -1 : String.format("server %s still has get ip %s%n%s", server, ip,
response);
}
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup")
public void testCreateImage() throws Exception { public void testCreateImage() throws Exception {
if (serverId <= 0) 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());
imageId = image.getId(); createdImageId = image.getId();
blockUntilImageActive(imageId); blockUntilImageActive(createdImageId);
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage") @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebuildServer() throws Exception { public void testRebuildServer() throws Exception {
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId)); if (serverId <= 0) testCreateServer();
client.rebuildServer(serverId, new RebuildServerOptions().withImage(String.valueOf(createdImageId)));
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
// issue Web Hosting #119580 imageId comes back incorrect after rebuild // issue Web Hosting #119580 createdImageId comes back incorrect after rebuild
assertEquals(imageId, client.getServer(serverId).getImageRef()); assertEquals(createdImageId, client.getServer(serverId).getImageRef());
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer") @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebootHard() throws Exception { public void testRebootHard() throws Exception {
if (serverId <= 0) testCreateServer();
client.rebootServer(serverId, RebootType.HARD); client.rebootServer(serverId, RebootType.HARD);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard") @Test(enabled = true, timeOut = 10 * 60 * 1000)
public void testRebootSoft() throws Exception { public void testRebootSoft() throws Exception {
if (serverId <= 0) testCreateServer();
client.rebootServer(serverId, RebootType.SOFT); client.rebootServer(serverId, RebootType.SOFT);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") @Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
public void testRevertResize() throws Exception { public void testRevertResize() throws Exception {
if (serverId <= 0) testCreateServer();
client.resizeServer(serverId, 2); client.resizeServer(serverId, 2);
blockUntilServerVerifyResize(serverId); blockUntilServerVerifyResize(serverId);
client.revertResizeServer(serverId); client.revertResizeServer(serverId);
blockUntilServerActive(serverId); blockUntilServerActive(serverId);
assertEquals(new Integer(1), client.getServer(serverId).getFlavorRef()); assertEquals(1, client.getServer(serverId).getFlavorRef());
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft") @Test(enabled = false, timeOut = 10 * 60 * 1000)
public void testConfirmResize() throws Exception { public void testConfirmResize() throws Exception {
client.resizeServer(serverId2, 2); if (serverId <= 0) testCreateServer();
blockUntilServerVerifyResize(serverId2); client.resizeServer(serverId, 2);
client.confirmResizeServer(serverId2); blockUntilServerVerifyResize(serverId);
blockUntilServerActive(serverId2); client.confirmResizeServer(serverId);
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorRef()); blockUntilServerActive(serverId);
assertEquals(2, client.getServer(serverId).getFlavorRef());
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = {"testRebootSoft", "testRevertResize", @Test(enabled = true, timeOut = 10 * 60 * 1000)
"testConfirmResize"}) void deleteServer2() throws Exception {
void deleteServer2() { if (serverId <= 0) testCreateServer();
if (serverId2 > 0) { if (serverId > 0) {
client.deleteServer(serverId2); client.deleteServer(serverId);
assert client.getServer(serverId2) == null; Thread.sleep(1000);
assert client.getServer(serverId) == null;
} }
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2") @Test(enabled = true, timeOut = 10 * 60 * 1000)
void testDeleteImage() { void testDeleteImage() throws Exception {
if (imageId > 0) { if (createdImageId <= 0) {
client.deleteImage(imageId); testCreateImage();
assert client.getImage(imageId) == null; }
if (createdImageId > 0) {
client.deleteImage(createdImageId);
assert client.getImage(createdImageId) == null;
} }
} }
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage") @Test(enabled = true, timeOut = 10 * 60 * 1000)
void deleteServer1() { void deleteServer1() throws Exception {
if (serverId <= 0) testCreateServer();
if (serverId > 0) { if (serverId > 0) {
client.deleteServer(serverId); client.deleteServer(serverId);
assert client.getServer(serverId) == null; assert client.getServer(serverId) == null;
@ -476,10 +458,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) {
client.deleteServer(serverId2);
} }
} }
} }

View File

@ -3,12 +3,9 @@ package org.jclouds.openstack.nova;
import java.util.Properties; import java.util.Properties;
/** /**
* Created by IntelliJ IDEA. * @author Victor Galkin
* User: VGalkin
* Date: 4/14/11
* Time: 4:32 PM
* To change this template use File | Settings | File Templates.
*/ */
public class PropertyHelper { public class PropertyHelper {
public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) { public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {

View File

@ -0,0 +1,171 @@
/**
*
* 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 com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Module;
import org.jclouds.Constants;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
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.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
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 ServerCreateTest {
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);
}
@BeforeGroups(groups = {"live"})
public void setupClient() throws IOException {
Properties overrides = setupProperties();
setupCredentials(overrides);
updateProperties(overrides);
Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential,
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), overrides)
.buildInjector();
client = injector.getInstance(NovaClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger
}
@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);
}
}
}