mirror of https://github.com/apache/jclouds.git
Fixes in live tests
This commit is contained in:
parent
f52f331be9
commit
7f02824928
|
@ -26,7 +26,6 @@ import com.google.common.collect.Iterables;
|
|||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.io.Payload;
|
||||
|
@ -75,15 +74,16 @@ public class NovaClientLiveTest {
|
|||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String adminPass2;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
private int createdImageId;
|
||||
|
||||
protected Properties setupProperties() throws IOException {
|
||||
Properties overrides = new Properties();
|
||||
|
@ -266,6 +266,7 @@ public class NovaClientLiveTest {
|
|||
assert client.getFlavor(12312987) == null;
|
||||
}
|
||||
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testCreateServer() throws Exception {
|
||||
String imageRef = client.getImage(13).getURI().toASCIIString();
|
||||
|
@ -279,7 +280,8 @@ public class NovaClientLiveTest {
|
|||
serverId = server.getId();
|
||||
adminPass = server.getAdminPass();
|
||||
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 {
|
||||
|
@ -300,39 +302,38 @@ public class NovaClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
private void blockUntilImageActive(int imageId) throws InterruptedException {
|
||||
private void blockUntilImageActive(int createdImageId) throws InterruptedException {
|
||||
Image currentDetails;
|
||||
for (currentDetails = client.getImage(imageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
|
||||
.getImage(imageId)) {
|
||||
for (currentDetails = client.getImage(createdImageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
|
||||
.getImage(createdImageId)) {
|
||||
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
||||
Thread.sleep(5 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
||||
@Test(enabled = true, timeOut = 300000)
|
||||
public void testServerDetails() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
Server server = client.getServer(serverId);
|
||||
|
||||
assertNotNull(server.getHostId());
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
|
||||
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");
|
||||
|
||||
|
||||
assertEquals(server.getImageRef(), endpoint + "/v1.1/images/13");
|
||||
// listAddresses tests..
|
||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||
assertEquals(server.getAddresses().getPublicAddresses().size(), 1);
|
||||
assertEquals(client.listPublicAddresses(serverId), server.getAddresses().getPublicAddresses());
|
||||
assertEquals(server.getAddresses().getPrivateAddresses().size(), 1);
|
||||
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 {
|
||||
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")
|
||||
@Test(enabled = true, timeOut = 5 * 60 * 1000)
|
||||
public void testRenameServer() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
Server server = client.getServer(serverId);
|
||||
String oldName = server.getName();
|
||||
client.renameServer(serverId, oldName + "new");
|
||||
|
@ -374,99 +363,92 @@ public class NovaClientLiveTest {
|
|||
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 {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
client.changeAdminPass(serverId, "elmo");
|
||||
blockUntilServerActive(serverId);
|
||||
assertPassword(client.getServer(serverId), "elmo");
|
||||
this.adminPass = "elmo";
|
||||
}
|
||||
|
||||
private void assertIpConfigured(Server server, String password) {
|
||||
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")
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
public void testCreateImage() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
Image image = client.createImageFromServer("hoofie", serverId);
|
||||
assertEquals("hoofie", image.getName());
|
||||
assertEquals(serverId, image.getServerRef());
|
||||
imageId = image.getId();
|
||||
blockUntilImageActive(imageId);
|
||||
createdImageId = image.getId();
|
||||
blockUntilImageActive(createdImageId);
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
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);
|
||||
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
||||
assertEquals(imageId, client.getServer(serverId).getImageRef());
|
||||
// issue Web Hosting #119580 createdImageId comes back incorrect after rebuild
|
||||
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 {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
client.rebootServer(serverId, RebootType.HARD);
|
||||
blockUntilServerActive(serverId);
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
public void testRebootSoft() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
client.rebootServer(serverId, RebootType.SOFT);
|
||||
blockUntilServerActive(serverId);
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||
public void testRevertResize() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
client.resizeServer(serverId, 2);
|
||||
blockUntilServerVerifyResize(serverId);
|
||||
client.revertResizeServer(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 {
|
||||
client.resizeServer(serverId2, 2);
|
||||
blockUntilServerVerifyResize(serverId2);
|
||||
client.confirmResizeServer(serverId2);
|
||||
blockUntilServerActive(serverId2);
|
||||
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorRef());
|
||||
if (serverId <= 0) testCreateServer();
|
||||
client.resizeServer(serverId, 2);
|
||||
blockUntilServerVerifyResize(serverId);
|
||||
client.confirmResizeServer(serverId);
|
||||
blockUntilServerActive(serverId);
|
||||
assertEquals(2, client.getServer(serverId).getFlavorRef());
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = {"testRebootSoft", "testRevertResize",
|
||||
"testConfirmResize"})
|
||||
void deleteServer2() {
|
||||
if (serverId2 > 0) {
|
||||
client.deleteServer(serverId2);
|
||||
assert client.getServer(serverId2) == null;
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
void deleteServer2() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
if (serverId > 0) {
|
||||
client.deleteServer(serverId);
|
||||
Thread.sleep(1000);
|
||||
assert client.getServer(serverId) == null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2")
|
||||
void testDeleteImage() {
|
||||
if (imageId > 0) {
|
||||
client.deleteImage(imageId);
|
||||
assert client.getImage(imageId) == null;
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
void testDeleteImage() throws Exception {
|
||||
if (createdImageId <= 0) {
|
||||
testCreateImage();
|
||||
}
|
||||
if (createdImageId > 0) {
|
||||
client.deleteImage(createdImageId);
|
||||
assert client.getImage(createdImageId) == null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage")
|
||||
void deleteServer1() {
|
||||
@Test(enabled = true, timeOut = 10 * 60 * 1000)
|
||||
void deleteServer1() throws Exception {
|
||||
if (serverId <= 0) testCreateServer();
|
||||
if (serverId > 0) {
|
||||
client.deleteServer(serverId);
|
||||
assert client.getServer(serverId) == null;
|
||||
|
@ -476,10 +458,7 @@ public class NovaClientLiveTest {
|
|||
@AfterTest
|
||||
void deleteServersOnEnd() {
|
||||
if (serverId > 0) {
|
||||
//client.deleteServer(serverId);
|
||||
}
|
||||
if (serverId2 > 0) {
|
||||
client.deleteServer(serverId2);
|
||||
client.deleteServer(serverId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,9 @@ package org.jclouds.openstack.nova;
|
|||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: VGalkin
|
||||
* Date: 4/14/11
|
||||
* Time: 4:32 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
* @author Victor Galkin
|
||||
*/
|
||||
|
||||
public class PropertyHelper {
|
||||
|
||||
public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue