Fixes in live tests

This commit is contained in:
vicglarson 2011-04-21 20:12:31 +04:00 committed by Dmitri Babaev
parent d065f61b92
commit 78db8f1bfc
7 changed files with 118 additions and 154 deletions

View File

@ -18,12 +18,7 @@
*/
package org.jclouds.openstack.nova.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import com.google.inject.Guice;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
@ -36,7 +31,11 @@ import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.functions.ParseImageFromJsonResponseTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import static org.testng.Assert.assertEquals;
/**
* @author Adrian Cole

View File

@ -18,25 +18,11 @@
*/
package org.jclouds.openstack.nova.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.jclouds.compute.domain.*;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
@ -47,10 +33,13 @@ import org.jclouds.openstack.nova.domain.ServerStatus;
import org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest;
import org.testng.annotations.Test;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import static org.testng.Assert.assertEquals;
/**
* @author Adrian Cole

View File

@ -19,18 +19,17 @@
package org.jclouds.openstack.nova.domain;
import static junit.framework.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import static junit.framework.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
/**
* Tests behavior of {@code CreateImageBinder}

View File

@ -18,17 +18,13 @@
*/
package org.jclouds.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.io.Payloads;
@ -39,13 +35,16 @@ import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code ParseServerFromJsonResponse}
@ -99,7 +98,8 @@ public class ParseServerFromJsonResponseTest {
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {}));
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
return (Server) parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
}

View File

@ -21,7 +21,6 @@ package org.jclouds.openstack.nova.live;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import org.jclouds.http.HttpResponseException;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.domain.Server;
@ -32,8 +31,6 @@ import org.testng.annotations.Test;
import java.util.Map;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
/**
* @author Victor Galkin
*/
@ -53,26 +50,6 @@ public class DeleteServersInVariousStatesLiveTest {
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
Server server = null;
@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());

View File

@ -64,6 +64,7 @@ import static org.testng.Assert.*;
@Test(groups = "live", sequential = true)
public class NovaClientLiveTest {
private int testImageId = 95;
protected NovaClient client;
protected SshClient.Factory sshFactory;
private Predicate<IPSocket> socketTester;
@ -75,6 +76,7 @@ public class NovaClientLiveTest {
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private int createdImageId;
@BeforeTest
public void setupClient() throws IOException {
Properties properties = setupOverrides(setupProperties(this.getClass()));
@ -228,7 +230,7 @@ public class NovaClientLiveTest {
@Test(enabled = true)
public void testCreateServer() throws Exception {
String imageRef = client.getImage(95).getURI().toASCIIString();
String imageRef = client.getImage(testImageId).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",
@ -290,7 +292,7 @@ public class NovaClientLiveTest {
assertEquals(server.getMetadata(), metadata);
assertEquals(server.getImageRef(), "endpoint" + "/v1.1/images/95");
assertTrue(server.getImageRef().endsWith(String.valueOf(testImageId)));
// listAddresses tests..
assertEquals(client.getAddresses(serverId), server.getAddresses());
assertEquals(server.getAddresses().getPublicAddresses().size(), 1);
@ -298,7 +300,7 @@ public class NovaClientLiveTest {
assertEquals(server.getAddresses().getPrivateAddresses().size(), 1);
assertEquals(client.listPrivateAddresses(serverId), server.getAddresses().getPrivateAddresses());
assertPassword(server, adminPass);
assertEquals(server.getFlavorRef(), "endpoint" + "/v1.1/flavors/1");
assertTrue(server.getFlavorRef().endsWith("1"));
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
}

View File

@ -92,7 +92,7 @@ public class NovaComputeServiceLiveTest {
protected ComputeServiceContext context;
protected ComputeService computeService;
protected Template template;
protected Map<String, String> keyPair;
protected String provider;
@ -218,10 +218,13 @@ public class NovaComputeServiceLiveTest {
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
public void testCorrectAuthException() throws Exception {
Properties properties = new Properties();
properties.putAll(overrides);
properties.remove(provider + ".identity");
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, "MOMMA", "MIA", ImmutableSet
.<Module>of(new SLF4JLoggingModule()), overrides);
.<Module>of(new SLF4JLoggingModule()), properties);
context.getComputeService().listNodes();
} finally {
if (context != null)
@ -328,16 +331,16 @@ public class NovaComputeServiceLiveTest {
}
}
@Test(enabled = true, dependsOnMethods = {"testImagesCache"})
@Test(enabled = true)
public void testTemplateMatch() throws Exception {
template = buildTemplate(computeService.templateBuilder());
Template template = buildTemplate(getDefaultTemplateBuilder());
Template toMatch = computeService.templateBuilder().imageId(template.getImage().getId()).build();
assertEquals(toMatch.getImage(), template.getImage());
}
protected void checkHttpGet(NodeMetadata node) {
ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080);
}
// protected void checkHttpGet(NodeMetadata node) {
// ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080);
// }
@Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testCreateTwoNodesWithRunScript() throws Exception {
@ -346,9 +349,9 @@ public class NovaComputeServiceLiveTest {
} catch (NoSuchElementException e) {
}
refreshTemplate();
try {
nodes = newTreeSet(computeService.createNodesInGroup(group, 2, template));
nodes = newTreeSet(computeService.createNodesInGroup(group, 2, getDefaultTemplateBuilder().build()));
} catch (RunNodesException e) {
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
throw e;
@ -360,30 +363,23 @@ public class NovaComputeServiceLiveTest {
// credentials aren't always the same
// assertEquals(node1.getCredentials(), node2.getCredentials());
assertLocationSameOrChild(node1.getLocation(), template.getLocation());
assertLocationSameOrChild(node2.getLocation(), template.getLocation());
assertLocationSameOrChild(node1.getLocation(), getDefaultTemplateBuilder().build().getLocation());
assertLocationSameOrChild(node2.getLocation(), getDefaultTemplateBuilder().build().getLocation());
checkImageIdMatchesTemplate(node1);
checkImageIdMatchesTemplate(node2);
checkOsMatchesTemplate(node1);
checkOsMatchesTemplate(node2);
}
private void refreshTemplate() {
template = buildTemplate(computeService.templateBuilder());
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
.runScript(buildScript(template.getImage().getOperatingSystem()));
}
protected void checkImageIdMatchesTemplate(NodeMetadata node) {
if (node.getImageId() != null)
assertEquals(node.getImageId(), template.getImage().getId());
assertEquals(node.getImageId(), getDefaultTemplateBuilder().build().getImage().getId());
}
protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node
assert node.getOperatingSystem().getFamily().equals(getDefaultTemplateBuilder().build().getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", getDefaultTemplateBuilder().build().getImage().getOperatingSystem().getFamily(), node
.getOperatingSystem());
}
@ -395,16 +391,17 @@ public class NovaComputeServiceLiveTest {
}
}
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript")
@Test(enabled = true)
public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception {
testCreateTwoNodesWithRunScript();
initializeContextAndClient(overrides);
refreshTemplate();
TreeSet<NodeMetadata> nodes = newTreeSet(computeService.createNodesInGroup(group, 1, template));
TreeSet<NodeMetadata> nodes = newTreeSet(computeService.createNodesInGroup(group, 1, getDefaultTemplateBuilder().build()));
checkNodes(nodes, group);
NodeMetadata node = nodes.first();
this.nodes.add(node);
assertEquals(nodes.size(), 1);
assertLocationSameOrChild(node.getLocation(), template.getLocation());
assertLocationSameOrChild(node.getLocation(), getDefaultTemplateBuilder().build().getLocation());
checkOsMatchesTemplate(node);
}
@ -444,7 +441,7 @@ public class NovaComputeServiceLiveTest {
NodeMetadata metadata = computeService.getNodeMetadata(node.getId());
assertEquals(metadata.getProviderId(), node.getProviderId());
assertEquals(metadata.getGroup(), node.getGroup());
assertLocationSameOrChild(metadata.getLocation(), template.getLocation());
assertLocationSameOrChild(metadata.getLocation(), getDefaultTemplateBuilder().build().getLocation());
checkImageIdMatchesTemplate(metadata);
checkOsMatchesTemplate(metadata);
assert (metadata.getState() == NodeState.RUNNING) : metadata;
@ -544,24 +541,25 @@ public class NovaComputeServiceLiveTest {
}
template = getDefaultTemplateBuilder().options(blockOnComplete(false).inboundPorts(22, 8080))
Template template = getDefaultTemplateBuilder().options(blockOnComplete(false).inboundPorts(22, 8080))
.build();
// note this is a dependency on the template resolution
template.getOptions().runScript(
RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage()
.getOperatingSystem()));
// template.getOptions().runScript(
// RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage()
// .getOperatingSystem()));
try {
NodeMetadata node = getOnlyElement(computeService.createNodesInGroup(group, 1, template));
checkHttpGet(node);
//checkHttpGet(node);
} finally {
computeService.destroyNodesMatching(inGroup(group));
}
}
@Test(enabled = true/* , dependsOnMethods = "testCompareSizes" */)
@Test(enabled = true)
public void testTemplateOptions() throws Exception {
TemplateOptions options = new TemplateOptions().withMetadata();
Template t = computeService.templateBuilder().smallest().options(options).build();