Issue 412: elastichosts drive now verifies ssh opens properly

This commit is contained in:
Adrian Cole 2010-12-19 12:28:56 +01:00
parent c57e09c5ae
commit 70fbb3a5b8
6 changed files with 113 additions and 38 deletions

View File

@ -119,6 +119,8 @@ public interface CommonElasticStackClient {
* <p/>
* Sends the server an ACPI power-down event. Server reverts to a stopped status if it is
* persistent and is automatically destroyed otherwise.
* <h4>note</h4> behaviour on shutdown depends on how your server OS is set up to respond to an
* ACPI power button signal.
*
* @param uuid
* what to shutdown

View File

@ -130,6 +130,13 @@ public class Server extends Item {
return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics,
vnc, description);
}
public static Builder fromServer(Server in) {
return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem())
.persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices())
.bootDeviceIds(in.getBootDeviceIds()).tags(in.getTags()).userMetadata(in.getUserMetadata())
.nics(in.getNics()).vnc(in.getVnc());
}
}
protected final int cpu;

View File

@ -0,0 +1,54 @@
/**
*
* 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.elasticstack.util;
import org.jclouds.elasticstack.domain.IDEDevice;
import org.jclouds.elasticstack.domain.Model;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.Server;
import org.jclouds.elasticstack.domain.VNC;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class Servers {
/**
* Helper to create a small persistent server
*
* @param name
* what to name the server
* @param driveUuuid
* id of the boot drive
* @param vncPassword
* password for vnc
* @return a builder for a persistent 1Ghz 512m server with DHCP enabled network.
*/
public static Server.Builder small(String name, String driveUuuid, String vncPassword) {
return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true)
.devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build()))
.bootDeviceIds(ImmutableSet.of("ide:0:0"))
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build()))
.vnc(new VNC(null, vncPassword, false));
}
}

View File

@ -26,6 +26,7 @@ import static org.testng.Assert.assertNotNull;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.jclouds.Constants;
import org.jclouds.elasticstack.domain.ClaimType;
@ -39,17 +40,19 @@ import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.Server;
import org.jclouds.elasticstack.domain.ServerInfo;
import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.domain.VNC;
import org.jclouds.elasticstack.predicates.DriveClaimed;
import org.jclouds.elasticstack.util.Servers;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -68,6 +71,7 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
protected static final String VNC_PASSWORD = "XXXXXXXX";
protected S client;
protected RestContext<S, A> context;
protected Predicate<IPSocket> socketTester;
protected String provider = "elasticstack";
protected String identity;
@ -105,14 +109,9 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
overrides);
client = context.getApi();
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), 30, 1,
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), 120, 1,
TimeUnit.SECONDS);
}
@AfterGroups(groups = "live")
void tearDown() {
if (context != null)
context.close();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 120, 1, TimeUnit.SECONDS);
}
@Test
@ -211,13 +210,12 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
@Test(dependsOnMethods = "testSetDriveData")
public void testCreateAndStartServer() throws Exception {
Logger.getAnonymousLogger().info("preparing drive");
prepareDrive();
Server serverRequest = new Server.Builder().name(prefix).cpu(1000).mem(512).persistent(true)
.devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()))
.bootDeviceIds(ImmutableSet.of("ide:0:0")).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).
build())).vnc(new VNC(null, VNC_PASSWORD, false)).build();
Server serverRequest = Servers.small(prefix, drive.getUuid(), VNC_PASSWORD).build();
Logger.getAnonymousLogger().info("starting server");
server = client.createAndStartServer(serverRequest);
checkCreatedServer();
@ -240,6 +238,7 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
assertEquals(server.getNics(), ImmutableSet.of(new NIC.Builder()
.dhcp(server.getVnc().getIp())
.model(Model.E1000)
.block(
ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22",
@ -247,25 +246,15 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
}
// TODO
// @Test(dependsOnMethods = "testCreateAndStartServer")
// public void testSetServerConfiguration() throws Exception {
//
// ServerInfo server2 = client.setServerConfiguration(server.getUuid(), new
// Server.Builder().name("rediculous")
// .tags(ImmutableSet.of("networking", "security",
// "gateway")).userMetadata(ImmutableMap.of("foo", "bar"))
// .build());
//
// assertNotNull(server2.getUuid(), server.getUuid());
// assertEquals(server2.getName(), "rediculous");
// assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
// assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
// server = server2;
// }
// @Test(dependsOnMethods = "testSetServerConfiguration")
@Test(dependsOnMethods = "testCreateAndStartServer")
public void testConnectivity() throws Exception {
Logger.getAnonymousLogger().info("awaiting vnc");
assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server;
Logger.getAnonymousLogger().info("awaiting ssh");
assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server;
}
@Test(dependsOnMethods = "testConnectivity")
public void testLifeCycle() throws Exception {
client.stopServer(server.getUuid());
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
@ -276,12 +265,32 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
client.resetServer(server.getUuid());
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
// for some reason shutdown doesn't immediately occur
client.shutdownServer(server.getUuid());
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
// behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
// button signal
assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo(
server.getUuid()).getStatus() == ServerStatus.STOPPED);
}
@Test(dependsOnMethods = "testLifeCycle")
public void testSetServerConfiguration() throws Exception {
client.stopServer(server.getUuid());
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
ServerInfo server2 = client.setServerConfiguration(
server.getUuid(),
Server.Builder.fromServer(server).name("rediculous")
.tags(ImmutableSet.of("networking", "security", "gateway"))
.userMetadata(ImmutableMap.of("foo", "bar")).build());
assertNotNull(server2.getUuid(), server.getUuid());
assertEquals(server2.getName(), "rediculous");
assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
server = server2;
}
@Test(dependsOnMethods = "testSetServerConfiguration")
public void testDestroyServer() throws Exception {
client.destroyServer(server.getUuid());
assertEquals(client.getServerInfo(server.getUuid()), null);
@ -293,8 +302,8 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
assertEquals(client.getDriveInfo(drive.getUuid()), null);
}
@AfterTest
public void cleanUp() {
@AfterGroups(groups = "live")
protected void tearDown() {
try {
client.destroyServer(server.getUuid());
} catch (Exception e) {
@ -305,5 +314,7 @@ public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticSt
} catch (Exception e) {
}
if (context != null)
context.close();
}
}

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.DriveInfo;
import org.jclouds.elasticstack.domain.ImageConversionType;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -68,7 +69,7 @@ public class ElasticStackClientLiveTest extends
@Override
protected void prepareDrive() {
System.err.println("before prepare" + client.getDriveInfo(drive.getUuid()));
client.imageDrive("e6111e4c-67af-4438-b1bc-189747d5a8e5", drive.getUuid());
client.imageDrive("e6111e4c-67af-4438-b1bc-189747d5a8e5", drive.getUuid(), ImageConversionType.GUNZIP);
assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid());
System.err.println("after prepare" + client.getDriveInfo(drive.getUuid()));
}

View File

@ -73,9 +73,9 @@ public class KeyValuesDelimitedByBlankLinesToServerInfoTest {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class
.getResourceAsStream("/servers.txt")))), MapToServerInfoTest.ONE);
}
public void testNew() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToServerInfoTest.class
.getResourceAsStream("/new_server.txt")))), MapToServerInfoTest.ONE);
.getResourceAsStream("/new_server.txt")))), MapToServerInfoTest.NEW);
}
}