mirror of https://github.com/apache/jclouds.git
Ignored some asserts
This commit is contained in:
parent
a48850f1ac
commit
a2ec3ba34c
|
@ -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.*;
|
||||||
|
@ -64,427 +65,420 @@ import static org.testng.Assert.*;
|
||||||
@Test(groups = "live", sequential = true)
|
@Test(groups = "live", sequential = true)
|
||||||
public class NovaClientLiveTest {
|
public class NovaClientLiveTest {
|
||||||
|
|
||||||
protected NovaClient client;
|
protected NovaClient client;
|
||||||
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 identity;
|
||||||
protected String credential;
|
protected String credential;
|
||||||
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 void setupCredentials(Properties properties) {
|
protected Properties setupProperties() throws IOException {
|
||||||
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
Properties overrides = new Properties();
|
||||||
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
|
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
|
||||||
+ ".credential");
|
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
|
||||||
endpoint = properties.getProperty("test." + provider + ".endpoint");
|
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
|
||||||
apiversion = properties.getProperty("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");
|
||||||
|
|
||||||
protected void updateProperties(final Properties properties) {
|
return overrides;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Properties setupProperties() throws IOException {
|
protected void setupCredentials(Properties properties) {
|
||||||
Properties overrides = new Properties();
|
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||||
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
|
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
|
||||||
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
|
+ ".credential");
|
||||||
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
|
endpoint = properties.getProperty("test." + provider + ".endpoint");
|
||||||
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
|
apiversion = properties.getProperty("test." + provider + ".apiversion");
|
||||||
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 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);
|
|
||||||
|
|
||||||
String identity = "admin";
|
@BeforeGroups(groups = {"live"})
|
||||||
String credential = "d744752f-20d3-4d75-979f-f62f16033b07";
|
public void setupClient() throws IOException {
|
||||||
|
Properties overrides = setupProperties();
|
||||||
|
setupCredentials(overrides);
|
||||||
|
updateProperties(overrides);
|
||||||
|
|
||||||
|
String identity = "admin";
|
||||||
|
String credential = "d744752f-20d3-4d75-979f-f62f16033b07";
|
||||||
// ComputeServiceContextFactory contextFactory = new ComputeServiceContextFactory();
|
// ComputeServiceContextFactory contextFactory = new ComputeServiceContextFactory();
|
||||||
// ComputeServiceContext context = contextFactory.createContext(provider, identity, credential, Collections.singleton(new JschSshClientModule()), overrides);
|
// ComputeServiceContext context = contextFactory.createContext(provider, identity, credential, Collections.singleton(new JschSshClientModule()), overrides);
|
||||||
|
|
||||||
Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential,
|
Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential,
|
||||||
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), overrides)
|
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), overrides)
|
||||||
.buildInjector();
|
.buildInjector();
|
||||||
|
|
||||||
client = injector.getInstance(NovaClient.class);
|
client = injector.getInstance(NovaClient.class);
|
||||||
|
|
||||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
public void testListServersDetail() throws Exception {
|
public void testListServersDetail() throws Exception {
|
||||||
Set<Server> response = client.listServers(withDetails());
|
Set<Server> response = client.listServers(withDetails());
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long initialContainerCount = response.size();
|
long initialContainerCount = response.size();
|
||||||
assertTrue(initialContainerCount >= 0);
|
assertTrue(initialContainerCount >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListImages() throws Exception {
|
public void testListImages() throws Exception {
|
||||||
Set<Image> response = client.listImages();
|
Set<Image> response = client.listImages();
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long imageCount = response.size();
|
long imageCount = response.size();
|
||||||
assertTrue(imageCount >= 1);
|
assertTrue(imageCount >= 1);
|
||||||
for (Image image : response) {
|
for (Image image : response) {
|
||||||
assertTrue(image.getId() >= 0);
|
assertTrue(image.getId() >= 0);
|
||||||
assert null != image.getName() : image;
|
assert null != image.getName() : image;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListImagesDetail() throws Exception {
|
public void testListImagesDetail() throws Exception {
|
||||||
Set<Image> response = client.listImages(withDetails());
|
Set<Image> response = client.listImages(withDetails());
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long imageCount = response.size();
|
long imageCount = response.size();
|
||||||
assertTrue(imageCount >= 0);
|
assertTrue(imageCount >= 0);
|
||||||
for (Image image : response) {
|
for (Image image : response) {
|
||||||
assertTrue(image.getId() >= 1);
|
assertTrue(image.getId() >= 1);
|
||||||
assert null != image.getName() : image;
|
assert null != image.getName() : image;
|
||||||
assert null != image.getStatus() : image;
|
assert null != image.getStatus() : image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetImagesDetail() throws Exception {
|
public void testGetImagesDetail() throws Exception {
|
||||||
Set<Image> response = client.listImages(withDetails());
|
Set<Image> response = client.listImages(withDetails());
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long imageCount = response.size();
|
long imageCount = response.size();
|
||||||
assertTrue(imageCount >= 0);
|
assertTrue(imageCount >= 0);
|
||||||
for (Image image : response) {
|
for (Image image : response) {
|
||||||
try {
|
try {
|
||||||
Image newDetails = client.getImage(image.getId());
|
Image newDetails = client.getImage(image.getId());
|
||||||
assertEquals(image, newDetails);
|
assertEquals(image, newDetails);
|
||||||
} catch (HttpResponseException e) {// Ticket #9867
|
} catch (HttpResponseException e) {// Ticket #9867
|
||||||
if (e.getResponse().getStatusCode() != 400)
|
if (e.getResponse().getStatusCode() != 400)
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetImageDetailsNotFound() throws Exception {
|
public void testGetImageDetailsNotFound() throws Exception {
|
||||||
assert client.getImage(12312987) == null;
|
assert client.getImage(12312987) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServerDetailsNotFound() throws Exception {
|
public void testGetServerDetailsNotFound() throws Exception {
|
||||||
assert client.getServer(12312987) == null;
|
assert client.getServer(12312987) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
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);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void testListFlavors() throws Exception {
|
@Test
|
||||||
Set<Flavor> response = client.listFlavors();
|
public void testListFlavors() throws Exception {
|
||||||
assert null != response;
|
Set<Flavor> response = client.listFlavors();
|
||||||
long flavorCount = response.size();
|
assert null != response;
|
||||||
assertTrue(flavorCount >= 1);
|
long flavorCount = response.size();
|
||||||
for (Flavor flavor : response) {
|
assertTrue(flavorCount >= 1);
|
||||||
assertTrue(flavor.getId() >= 0);
|
for (Flavor flavor : response) {
|
||||||
assert null != flavor.getName() : flavor;
|
assertTrue(flavor.getId() >= 0);
|
||||||
}
|
assert null != flavor.getName() : flavor;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListFlavorsDetail() throws Exception {
|
@Test
|
||||||
Set<Flavor> response = client.listFlavors(withDetails());
|
public void testListFlavorsDetail() throws Exception {
|
||||||
assert null != response;
|
Set<Flavor> response = client.listFlavors(withDetails());
|
||||||
long flavorCount = response.size();
|
assert null != response;
|
||||||
assertTrue(flavorCount >= 0);
|
long flavorCount = response.size();
|
||||||
for (Flavor flavor : response) {
|
assertTrue(flavorCount >= 0);
|
||||||
assertTrue(flavor.getId() >= 1);
|
for (Flavor flavor : response) {
|
||||||
assert null != flavor.getName() : flavor;
|
assertTrue(flavor.getId() >= 1);
|
||||||
assert null != flavor.getDisk() : flavor;
|
assert null != flavor.getName() : flavor;
|
||||||
assert null != flavor.getRam() : flavor;
|
assert null != flavor.getDisk() : flavor;
|
||||||
}
|
assert null != flavor.getRam() : flavor;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetFlavorsDetail() throws Exception {
|
@Test
|
||||||
Set<Flavor> response = client.listFlavors(withDetails());
|
public void testGetFlavorsDetail() throws Exception {
|
||||||
assert null != response;
|
Set<Flavor> response = client.listFlavors(withDetails());
|
||||||
long flavorCount = response.size();
|
assert null != response;
|
||||||
assertTrue(flavorCount >= 0);
|
long flavorCount = response.size();
|
||||||
for (Flavor flavor : response) {
|
assertTrue(flavorCount >= 0);
|
||||||
Flavor newDetails = client.getFlavor(flavor.getId());
|
for (Flavor flavor : response) {
|
||||||
assertEquals(flavor, newDetails);
|
Flavor newDetails = client.getFlavor(flavor.getId());
|
||||||
}
|
assertEquals(flavor, newDetails);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFlavorDetailsNotFound() throws Exception {
|
public void testGetFlavorDetailsNotFound() throws Exception {
|
||||||
assert client.getFlavor(12312987) == null;
|
assert client.getFlavor(12312987) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String serverPrefix = System.getProperty("user.name") + ".cs";
|
@Test(enabled = true)
|
||||||
private int serverId;
|
public void testCreateServer() throws Exception {
|
||||||
private String adminPass;
|
String imageRef = client.getImage(13).getURI().toASCIIString();
|
||||||
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
|
String flavorRef = client.getFlavor(1).getURI().toASCIIString();
|
||||||
private String ip;
|
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
|
||||||
private int serverId2;
|
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",
|
||||||
private String adminPass2;
|
"rackspace".getBytes()).withMetadata(metadata));
|
||||||
private int imageId;
|
|
||||||
|
|
||||||
@Test(enabled = true)
|
assertNotNull(server.getAdminPass());
|
||||||
public void testCreateServer() throws Exception {
|
assertEquals(server.getStatus(), ServerStatus.BUILD);
|
||||||
String imageRef = "14362";
|
serverId = server.getId();
|
||||||
String flavorRef = "1";
|
adminPass = server.getAdminPass();
|
||||||
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
|
blockUntilServerActive(serverId);
|
||||||
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",
|
ip = client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next();
|
||||||
"rackspace".getBytes()).withMetadata(metadata));
|
}
|
||||||
|
|
||||||
assertNotNull(server.getAdminPass());
|
private void blockUntilServerActive(int serverId) throws InterruptedException {
|
||||||
serverId = server.getId();
|
Server currentDetails;
|
||||||
adminPass = server.getAdminPass();
|
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client
|
||||||
ip = server.getAddresses().getPublicAddresses().iterator().next().getAddress();
|
.getServer(serverId)) {
|
||||||
assertEquals(server.getStatus(), ServerStatus.BUILD);
|
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
||||||
blockUntilServerActive(serverId);
|
Thread.sleep(5 * 1000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void blockUntilServerActive(int serverId) throws InterruptedException {
|
private void blockUntilServerVerifyResize(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.VERIFY_RESIZE; currentDetails = client
|
||||||
.getServer(serverId)) {
|
.getServer(serverId)) {
|
||||||
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
System.out.printf("blocking on status verify resize%n%s%n", currentDetails);
|
||||||
Thread.sleep(5 * 1000);
|
Thread.sleep(5 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void blockUntilServerVerifyResize(int serverId) throws InterruptedException {
|
private void blockUntilImageActive(int imageId) throws InterruptedException {
|
||||||
Server currentDetails;
|
Image currentDetails;
|
||||||
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.VERIFY_RESIZE; currentDetails = client
|
for (currentDetails = client.getImage(imageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
|
||||||
.getServer(serverId)) {
|
.getImage(imageId)) {
|
||||||
System.out.printf("blocking on status verify resize%n%s%n", currentDetails);
|
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
||||||
Thread.sleep(5 * 1000);
|
Thread.sleep(5 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void blockUntilImageActive(int imageId) throws InterruptedException {
|
@Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
||||||
Image currentDetails;
|
public void testServerDetails() throws Exception {
|
||||||
for (currentDetails = client.getImage(imageId); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
|
Server server = client.getServer(serverId);
|
||||||
.getImage(imageId)) {
|
|
||||||
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
|
||||||
Thread.sleep(5 * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
assertNotNull(server.getHostId());
|
||||||
public void testServerDetails() throws Exception {
|
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||||
Server server = client.getServer(serverId);
|
|
||||||
|
|
||||||
assertNotNull(server.getHostId());
|
|
||||||
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());
|
|
||||||
// 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());
|
|
||||||
|
|
||||||
// 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 {
|
assertNotNull(server.getAddresses());
|
||||||
IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0).getAddress(), 22);
|
|
||||||
socketTester.apply(socket);
|
|
||||||
|
|
||||||
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
|
|
||||||
try {
|
|
||||||
client.connect();
|
|
||||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
|
||||||
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
|
||||||
assertEquals("rackspace", etcPasswdContents.trim());
|
|
||||||
} finally {
|
|
||||||
if (client != null)
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
public void testRenameServer() throws Exception {
|
|
||||||
Server server = client.getServer(serverId);
|
|
||||||
String oldName = server.getName();
|
|
||||||
client.renameServer(serverId, oldName + "new");
|
|
||||||
blockUntilServerActive(serverId);
|
|
||||||
assertEquals(oldName + "new", client.getServer(serverId).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
|
||||||
public void testChangePassword() throws Exception {
|
|
||||||
client.changeAdminPass(serverId, "elmo");
|
|
||||||
blockUntilServerActive(serverId);
|
|
||||||
checkPassOk(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")
|
// check metadata
|
||||||
public void testCreateImage() throws Exception {
|
assertEquals(server.getMetadata(), metadata);
|
||||||
Image image = client.createImageFromServer("hoofie", serverId);
|
assertPassword(server, adminPass);
|
||||||
assertEquals("hoofie", image.getName());
|
assertEquals(server.getFlavorRef(), endpoint + "/flavors/1");
|
||||||
assertEquals(new Integer(serverId), image.getServerId());
|
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||||
imageId = image.getId();
|
assertEquals(server.getImageRef(), endpoint + "/images/13");
|
||||||
blockUntilImageActive(imageId);
|
// 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());
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
|
}
|
||||||
public void testRebuildServer() throws Exception {
|
|
||||||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
|
||||||
blockUntilServerActive(serverId);
|
|
||||||
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
|
||||||
assertEquals(new Integer(imageId), client.getServer(serverId).getImageRef());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
|
||||||
public void testRebootHard() throws Exception {
|
|
||||||
client.rebootServer(serverId, RebootType.HARD);
|
|
||||||
blockUntilServerActive(serverId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
|
private void assertPassword(Server server, String pass) throws IOException {
|
||||||
public void testRebootSoft() throws Exception {
|
IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0), 22);
|
||||||
client.rebootServer(serverId, RebootType.SOFT);
|
socketTester.apply(socket);
|
||||||
blockUntilServerActive(serverId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
|
||||||
public void testRevertResize() throws Exception {
|
try {
|
||||||
client.resizeServer(serverId, 2);
|
client.connect();
|
||||||
blockUntilServerVerifyResize(serverId);
|
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||||
client.revertResizeServer(serverId);
|
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
||||||
blockUntilServerActive(serverId);
|
assertEquals("rackspace", etcPasswdContents.trim());
|
||||||
assertEquals(new Integer(1), client.getServer(serverId).getFlavorRef());
|
} finally {
|
||||||
}
|
if (client != null)
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
private ExecResponse exec(Server details, String pass, String command) throws IOException {
|
||||||
public void testConfirmResize() throws Exception {
|
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22);
|
||||||
client.resizeServer(serverId2, 2);
|
socketTester.apply(socket);
|
||||||
blockUntilServerVerifyResize(serverId2);
|
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
|
||||||
client.confirmResizeServer(serverId2);
|
try {
|
||||||
blockUntilServerActive(serverId2);
|
client.connect();
|
||||||
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorRef());
|
return client.exec(command);
|
||||||
}
|
} finally {
|
||||||
|
if (client != null)
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = {"testRebootSoft", "testRevertResize",
|
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
||||||
"testConfirmResize"})
|
public void testRenameServer() throws Exception {
|
||||||
void deleteServer2() {
|
Server server = client.getServer(serverId);
|
||||||
if (serverId2 > 0) {
|
String oldName = server.getName();
|
||||||
client.deleteServer(serverId2);
|
client.renameServer(serverId, oldName + "new");
|
||||||
assert client.getServer(serverId2) == null;
|
blockUntilServerActive(serverId);
|
||||||
}
|
assertEquals(oldName + "new", client.getServer(serverId).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2")
|
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
|
||||||
void testDeleteImage() {
|
public void testChangePassword() throws Exception {
|
||||||
if (imageId > 0) {
|
client.changeAdminPass(serverId, "elmo");
|
||||||
client.deleteImage(imageId);
|
blockUntilServerActive(serverId);
|
||||||
assert client.getImage(imageId) == null;
|
assertPassword(client.getServer(serverId), "elmo");
|
||||||
}
|
this.adminPass = "elmo";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage")
|
private void assertIpConfigured(Server server, String password) {
|
||||||
void deleteServer1() {
|
try {
|
||||||
if (serverId > 0) {
|
ExecResponse response = exec(server, password, "ifconfig -a");
|
||||||
client.deleteServer(serverId);
|
assert response.getOutput().indexOf(ip) > 0 : String.format("server %s didn't get ip %s%n%s", server, ip,
|
||||||
assert client.getServer(serverId) == null;
|
response);
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@AfterTest
|
private void assertIpNotConfigured(Server server, String password) throws IOException {
|
||||||
void deleteServersOnEnd() {
|
ExecResponse response = exec(server, password, "ifconfig -a");
|
||||||
if (serverId > 0) {
|
assert response.getOutput().indexOf(ip) == -1 : String.format("server %s still has get ip %s%n%s", server, ip,
|
||||||
client.deleteServer(serverId);
|
response);
|
||||||
}
|
}
|
||||||
if (serverId2 > 0) {
|
|
||||||
client.deleteServer(serverId2);
|
|
||||||
}
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup")
|
||||||
}
|
public void testCreateImage() throws Exception {
|
||||||
|
Image image = client.createImageFromServer("hoofie", serverId);
|
||||||
|
assertEquals("hoofie", image.getName());
|
||||||
|
assertEquals(new Integer(serverId), image.getServerId());
|
||||||
|
imageId = image.getId();
|
||||||
|
blockUntilImageActive(imageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
|
||||||
|
public void testRebuildServer() throws Exception {
|
||||||
|
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
||||||
|
blockUntilServerActive(serverId);
|
||||||
|
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
||||||
|
assertEquals(imageId, client.getServer(serverId).getImageRef());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
||||||
|
public void testRebootHard() throws Exception {
|
||||||
|
client.rebootServer(serverId, RebootType.HARD);
|
||||||
|
blockUntilServerActive(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
|
||||||
|
public void testRebootSoft() throws Exception {
|
||||||
|
client.rebootServer(serverId, RebootType.SOFT);
|
||||||
|
blockUntilServerActive(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
|
public void testRevertResize() throws Exception {
|
||||||
|
client.resizeServer(serverId, 2);
|
||||||
|
blockUntilServerVerifyResize(serverId);
|
||||||
|
client.revertResizeServer(serverId);
|
||||||
|
blockUntilServerActive(serverId);
|
||||||
|
assertEquals(new Integer(1), client.getServer(serverId).getFlavorRef());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
|
public void testConfirmResize() throws Exception {
|
||||||
|
client.resizeServer(serverId2, 2);
|
||||||
|
blockUntilServerVerifyResize(serverId2);
|
||||||
|
client.confirmResizeServer(serverId2);
|
||||||
|
blockUntilServerActive(serverId2);
|
||||||
|
assertEquals(new Integer(2), client.getServer(serverId2).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 = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2")
|
||||||
|
void testDeleteImage() {
|
||||||
|
if (imageId > 0) {
|
||||||
|
client.deleteImage(imageId);
|
||||||
|
assert client.getImage(imageId) == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage")
|
||||||
|
void deleteServer1() {
|
||||||
|
if (serverId > 0) {
|
||||||
|
client.deleteServer(serverId);
|
||||||
|
assert client.getServer(serverId) == null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterTest
|
||||||
|
void deleteServersOnEnd() {
|
||||||
|
if (serverId > 0) {
|
||||||
|
//client.deleteServer(serverId);
|
||||||
|
}
|
||||||
|
if (serverId2 > 0) {
|
||||||
|
client.deleteServer(serverId2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue