mirror of https://github.com/apache/jclouds.git
fixed live tests
This commit is contained in:
parent
20b46f6757
commit
5b16a80d2d
|
@ -70,6 +70,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
try {
|
try {
|
||||||
AWSError error = null;
|
AWSError error = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
|
if (response.getPayload() != null) {
|
||||||
if (response.getPayload().getContentType() != null
|
if (response.getPayload().getContentType() != null
|
||||||
&& (response.getPayload().getContentType().indexOf("xml") != -1 || response.getPayload()
|
&& (response.getPayload().getContentType().indexOf("xml") != -1 || response.getPayload()
|
||||||
.getContentType().indexOf("unknown") != -1)) {
|
.getContentType().indexOf("unknown") != -1)) {
|
||||||
|
@ -84,6 +85,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
||||||
.getStatusLine());
|
.getStatusLine());
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
|
|
|
@ -54,4 +54,29 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (!super.equals(obj))
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ComputeMetadataImpl other = (ComputeMetadataImpl) obj;
|
||||||
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,9 @@ import static com.google.common.base.Throwables.getRootCause;
|
||||||
import static com.google.common.collect.Iterables.concat;
|
import static com.google.common.collect.Iterables.concat;
|
||||||
import static com.google.common.collect.Iterables.get;
|
import static com.google.common.collect.Iterables.get;
|
||||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
|
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||||
|
import static com.google.common.collect.Maps.uniqueIndex;
|
||||||
import static com.google.common.collect.Sets.filter;
|
import static com.google.common.collect.Sets.filter;
|
||||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
import static com.google.common.collect.Sets.newTreeSet;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.overrideCredentialsWith;
|
||||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||||
|
@ -42,6 +43,7 @@ import static org.testng.Assert.assertNotNull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -81,6 +83,7 @@ import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
@ -197,19 +200,37 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
// wait up to 5 seconds for an auth exception
|
// wait up to 5 seconds for an auth exception
|
||||||
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
||||||
public void testCorrectAuthException() throws Exception {
|
public void testCorrectAuthException() throws Exception {
|
||||||
|
synchronized (ComputeServiceContext.class) {
|
||||||
ComputeServiceContext context = null;
|
ComputeServiceContext context = null;
|
||||||
|
// system properties override crendentials passed
|
||||||
|
// if in the form provider.identity, provider.credential
|
||||||
|
// we want this to fail, so we save off old state and reset those
|
||||||
|
// properties to garbage.
|
||||||
|
String oldIdentity = System.getProperty(provider + ".identity");
|
||||||
|
String oldCredential = System.getProperty(provider + ".credential");
|
||||||
try {
|
try {
|
||||||
|
System.setProperty(provider + ".identity", "MOMMA");
|
||||||
|
System.setProperty(provider + ".credential", "MIA");
|
||||||
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
|
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
|
||||||
.<Module> of(new Log4JLoggingModule()));
|
.<Module> of(new Log4JLoggingModule()));
|
||||||
context.getComputeService().listNodes();
|
context.getComputeService().listNodes();
|
||||||
|
} catch (AuthorizationException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
if (oldIdentity != null)
|
||||||
|
System.setProperty(provider + ".identity", oldIdentity);
|
||||||
|
if (oldCredential != null)
|
||||||
|
System.setProperty(provider + ".credential", oldCredential);
|
||||||
if (context != null)
|
if (context != null)
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
@Test(enabled = true)
|
||||||
public void testImagesCache() throws Exception {
|
public void testImagesCache() throws Exception {
|
||||||
client.listImages();
|
client.listImages();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
@ -374,10 +395,18 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
Set<? extends NodeMetadata> nodes = client.listNodesDetailsMatching(all());
|
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client
|
||||||
Set<? extends NodeMetadata> metadataSet = newLinkedHashSet(filter(nodes, and(withTag(tag), not(TERMINATED))));
|
.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))),
|
||||||
|
new Function<NodeMetadata, String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(NodeMetadata from) {
|
||||||
|
return from.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}));
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
metadataSet.remove(node);
|
metadataMap.remove(node.getId());
|
||||||
NodeMetadata metadata = client.getNodeMetadata(node.getId());
|
NodeMetadata metadata = client.getNodeMetadata(node.getId());
|
||||||
assertEquals(metadata.getProviderId(), node.getProviderId());
|
assertEquals(metadata.getProviderId(), node.getProviderId());
|
||||||
assertEquals(metadata.getTag(), node.getTag());
|
assertEquals(metadata.getTag(), node.getTag());
|
||||||
|
@ -388,10 +417,10 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
|
assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
|
||||||
assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses());
|
assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses());
|
||||||
}
|
}
|
||||||
assertNodeZero(metadataSet);
|
assertNodeZero(metadataMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertNodeZero(Set<? extends NodeMetadata> metadataSet) {
|
protected void assertNodeZero(Collection<? extends NodeMetadata> metadataSet) {
|
||||||
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]",
|
assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]",
|
||||||
metadataSet, nodes);
|
metadataSet, nodes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import static com.google.common.collect.Iterables.transform;
|
||||||
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
|
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -67,7 +68,7 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
|
||||||
public Hardware apply(VCloudExpressVApp from) {
|
public Hardware apply(VCloudExpressVApp from) {
|
||||||
checkNotNull(from, "VApp");
|
checkNotNull(from, "VApp");
|
||||||
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
|
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
|
||||||
|
try {
|
||||||
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
|
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
|
||||||
|
|
||||||
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
|
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
|
||||||
|
@ -80,8 +81,12 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
|
||||||
|
|
||||||
}));
|
}));
|
||||||
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
|
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
|
||||||
return new HardwareImpl(from.getHref().toASCIIString(), from.getName(), from.getHref().toASCIIString(), location,
|
return new HardwareImpl(from.getHref().toASCIIString(), from.getName(), from.getHref().toASCIIString(),
|
||||||
null, ImmutableMap.<String, String> of(), processors, ram, volumes, ImagePredicates.idEquals(from
|
location, null, ImmutableMap.<String, String> of(), processors, ram, volumes, ImagePredicates
|
||||||
.getHref().toASCIIString()));
|
.idEquals(from.getHref().toASCIIString()));
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
logger.debug("incomplete data to form vApp %s", from.getHref());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue