mirror of https://github.com/apache/jclouds.git
Issue 1051: added unit test to show what's wrong
This commit is contained in:
parent
513fe2ee3e
commit
391c61c852
|
@ -155,20 +155,6 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
|||
return Functions.compose(addElasticIpsToNodemetadata, baseConverter);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideSuffix() {
|
||||
return new Supplier<String>() {
|
||||
final SecureRandom random = new SecureRandom();
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return random.nextInt(100) + "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
|
||||
|
|
|
@ -203,7 +203,7 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static class Builder extends TemplateOptions.Builder {
|
||||
/**
|
||||
* @see EC2TemplateOptions#blockDeviceMappings
|
||||
*/
|
||||
|
@ -352,6 +352,45 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable {
|
|||
return options.overrideLoginCredentials(credentials);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions nameTask(String name) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.nameTask(name);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions runAsRoot(boolean value) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.runAsRoot(value);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions tags(Iterable<String> tags) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.tags(tags);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.blockUntilRunning(blockUntilRunning);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions runScript(Statement script) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.runScript(script);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions runScript(String script) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.runScript(script);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions userMetadata(String key, String value) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.userMetadata(key, value);
|
||||
}
|
||||
|
||||
public static EC2TemplateOptions blockOnComplete(boolean value) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.blockOnComplete(value);
|
||||
}
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
|
@ -484,6 +523,38 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable {
|
|||
return EC2TemplateOptions.class.cast(super.userMetadata(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EC2TemplateOptions runScript(String script) {
|
||||
return EC2TemplateOptions.class.cast(super.runScript(script));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EC2TemplateOptions tags(Iterable<String> tags) {
|
||||
return EC2TemplateOptions.class.cast(super.tags(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EC2TemplateOptions wrapInInitScript(boolean wrapInInitScript) {
|
||||
return EC2TemplateOptions.class.cast(super.wrapInInitScript(wrapInInitScript));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EC2TemplateOptions blockOnComplete(boolean blockOnComplete) {
|
||||
return EC2TemplateOptions.class.cast(super.blockOnComplete(blockOnComplete));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return groupNames the user specified to run instances with, or zero
|
||||
* length set to create an implicit group
|
||||
|
@ -520,4 +591,5 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable {
|
|||
public Set<BlockDeviceMapping> getBlockDeviceMappings() {
|
||||
return blockDeviceMappings.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,235 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.ec2.compute;
|
||||
import static org.jclouds.ec2.compute.options.EC2TemplateOptions.Builder.blockUntilRunning;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.ec2.compute.internal.BaseEC2ComputeServiceExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests the compute service abstraction of the EC2 api.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EC2ComputeServiceExpectTest")
|
||||
public class EC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest {
|
||||
|
||||
static String region = "us-east-1";
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties properties = super.setupProperties();
|
||||
properties.setProperty(PROPERTY_REGIONS, region);
|
||||
properties.setProperty(provider + ".template", "osDescriptionMatches=.*fedora.*");
|
||||
return properties;
|
||||
}
|
||||
|
||||
private HttpRequest describeAvailabilityZonesRequest;
|
||||
private HttpResponse describeAvailabilityZonesResponse;
|
||||
private HttpRequest describeImagesRequest;
|
||||
private HttpResponse describeImagesResponse;
|
||||
private HttpRequest createKeyPairRequest;
|
||||
private HttpResponse createKeyPairResponse;
|
||||
private HttpRequest createSecurityGroupRequest;
|
||||
private HttpResponse createSecurityGroupResponse;
|
||||
private HttpRequest describeSecurityGroupRequest;
|
||||
private HttpResponse describeSecurityGroupResponse;
|
||||
private HttpRequest authorizeSecurityGroupIngressRequest22;
|
||||
private HttpResponse authorizeSecurityGroupIngressResponse;
|
||||
private HttpRequest authorizeSecurityGroupIngressRequestGroup;
|
||||
private HttpRequest runInstancesRequest;
|
||||
private HttpResponse runInstancesResponse;
|
||||
private HttpRequest describeInstanceRequest;
|
||||
private HttpResponse describeInstanceResponse;
|
||||
private HttpRequest describeImageRequest;
|
||||
|
||||
public EC2ComputeServiceExpectTest() {
|
||||
describeAvailabilityZonesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeAvailabilityZones").build());
|
||||
|
||||
describeAvailabilityZonesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/availabilityZones-" + region + ".xml", MediaType.APPLICATION_XML)).build();
|
||||
describeImagesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
|
||||
describeImagesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_images.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createKeyPairRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateKeyPair")
|
||||
.addFormParam("KeyName", "jclouds#test#0").build());
|
||||
|
||||
createKeyPairResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/create_keypair.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
createSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "CreateSecurityGroup")
|
||||
.addFormParam("GroupDescription", "jclouds#test")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
createSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/created_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeSecurityGroupRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeSecurityGroups")
|
||||
.addFormParam("GroupName.1", "jclouds#test").build());
|
||||
|
||||
describeSecurityGroupResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_securitygroup.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
authorizeSecurityGroupIngressRequest22 =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("CidrIp", "0.0.0.0/0")
|
||||
.addFormParam("FromPort", "22")
|
||||
.addFormParam("ToPort", "22")
|
||||
.addFormParam("GroupName", "jclouds#test")
|
||||
.addFormParam("IpProtocol", "tcp").build());
|
||||
|
||||
authorizeSecurityGroupIngressRequestGroup =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "AuthorizeSecurityGroupIngress")
|
||||
.addFormParam("SourceSecurityGroupName", "jclouds#test")
|
||||
.addFormParam("SourceSecurityGroupOwnerId", "993194456877")
|
||||
.addFormParam("GroupName", "jclouds#test").build());
|
||||
|
||||
authorizeSecurityGroupIngressResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/authorize_securitygroup_ingress_response.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
|
||||
runInstancesRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "RunInstances")
|
||||
.addFormParam("ImageId", "ami-be3adfd7")
|
||||
.addFormParam("InstanceType", "m1.small")
|
||||
.addFormParam("KeyName", "jclouds#test#0")
|
||||
.addFormParam("MaxCount", "1")
|
||||
.addFormParam("MinCount", "1")
|
||||
.addFormParam("SecurityGroup.1", "jclouds#test").build());
|
||||
|
||||
runInstancesResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/new_instance.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
describeInstanceRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("Action", "DescribeInstances")
|
||||
.addFormParam("InstanceId.1", "i-2baa5550").build());
|
||||
|
||||
describeInstanceResponse =
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/describe_instances_running-1.xml", MediaType.APPLICATION_XML)).build();
|
||||
|
||||
//TODO: duplicate.. shouldn't need this
|
||||
describeImageRequest =
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2." + region + ".amazonaws.com/")
|
||||
.addHeader("Host", "ec2." + region + ".amazonaws.com")
|
||||
.addFormParam("ImageId.1", "ami-aecd60c7")
|
||||
.addFormParam("Action", "DescribeImages").build());
|
||||
}
|
||||
|
||||
//TODO: FIXME!!
|
||||
@Test(enabled = false)
|
||||
public void testCreateNodeWithGeneratedKeyPairAndOverriddenLoginUser() throws Exception {
|
||||
Builder<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
requestResponseMap.put(describeRegionsRequest, describeRegionsResponse);
|
||||
requestResponseMap.put(describeAvailabilityZonesRequest, describeAvailabilityZonesResponse);
|
||||
requestResponseMap.put(describeImagesRequest, describeImagesResponse);
|
||||
requestResponseMap.put(createKeyPairRequest, createKeyPairResponse);
|
||||
requestResponseMap.put(createSecurityGroupRequest, createSecurityGroupResponse);
|
||||
requestResponseMap.put(describeSecurityGroupRequest, describeSecurityGroupResponse);
|
||||
requestResponseMap.put(authorizeSecurityGroupIngressRequest22, authorizeSecurityGroupIngressResponse);
|
||||
requestResponseMap.put(authorizeSecurityGroupIngressRequestGroup, authorizeSecurityGroupIngressResponse);
|
||||
requestResponseMap.put(runInstancesRequest, runInstancesResponse);
|
||||
requestResponseMap.put(describeInstanceRequest, describeInstanceResponse);
|
||||
requestResponseMap.put(describeImageRequest, describeImagesResponse);
|
||||
|
||||
ComputeService apiThatCreatesNode = requestsSendResponses(requestResponseMap.build());
|
||||
|
||||
NodeMetadata node = Iterables.getOnlyElement(apiThatCreatesNode.createNodesInGroup("test", 1,
|
||||
blockUntilRunning(false).overrideLoginUser("ec2-user")));
|
||||
assertEquals(node.getCredentials().getUser(), "ec2-user");
|
||||
assertNotNull(node.getCredentials().getPrivateKey());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -17,50 +17,21 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.ec2.compute;
|
||||
package org.jclouds.ec2.compute.internal;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.ec2.EC2ApiMetadata;
|
||||
import org.jclouds.ec2.EC2AsyncClient;
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.config.EC2RestClientModule;
|
||||
import org.jclouds.ec2.internal.BaseEC2ExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David Alves
|
||||
*/
|
||||
public abstract class BaseEC2ComputeServiceExpectTest<T> extends BaseRestClientExpectTest<T> implements
|
||||
public abstract class BaseEC2ComputeServiceContextExpectTest<T> extends BaseEC2ExpectTest<T> implements
|
||||
Function<ComputeServiceContext, T> {
|
||||
|
||||
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
|
||||
protected DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
public BaseEC2ComputeServiceExpectTest() {
|
||||
provider = "ec2";
|
||||
}
|
||||
|
||||
@ConfiguresRestClient
|
||||
private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
||||
@Override
|
||||
@Provides
|
||||
protected String provideTimeStamp(DateService dateService) {
|
||||
return CONSTANT_DATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
|
||||
return apply(createComputeServiceContext(fn, module, props));
|
||||
|
@ -71,14 +42,5 @@ public abstract class BaseEC2ComputeServiceExpectTest<T> extends BaseRestClientE
|
|||
return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestEC2RestClientModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApiMetadata createApiMetadata() {
|
||||
return new EC2ApiMetadata();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.ec2.compute.internal;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
|
||||
public class BaseEC2ComputeServiceExpectTest extends BaseEC2ComputeServiceContextExpectTest<ComputeService> {
|
||||
|
||||
@Override
|
||||
public ComputeService apply(ComputeServiceContext input) {
|
||||
return input.getComputeService();
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.ec2.compute.BaseEC2ComputeServiceExpectTest;
|
||||
import org.jclouds.ec2.compute.internal.BaseEC2ComputeServiceContextExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.predicates.PredicateWithResult;
|
||||
|
@ -42,7 +42,7 @@ import com.google.inject.Injector;
|
|||
* @author David Alves
|
||||
*/
|
||||
@Test(groups = "unit", testName = "GetImageWhenStatusAvailablePredicateWithResultExpectTest")
|
||||
public class GetImageWhenStatusAvailablePredicateWithResultExpectTest extends BaseEC2ComputeServiceExpectTest<Injector> {
|
||||
public class GetImageWhenStatusAvailablePredicateWithResultExpectTest extends BaseEC2ComputeServiceContextExpectTest<Injector> {
|
||||
|
||||
protected HttpRequest describeRegionsRequest = HttpRequest.builder()
|
||||
.method("POST")
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.ec2.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
@ -34,17 +35,21 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
||||
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
|
||||
|
||||
protected DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
protected FormSigner formSigner;
|
||||
|
||||
protected HttpRequest describeRegionsRequest = HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://ec2.us-east-1.amazonaws.com/")
|
||||
|
@ -52,15 +57,17 @@ public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
|||
.payload(payloadFromStringWithContentType(
|
||||
"Action=DescribeRegions&Signature=s5OXKqaaeKhJW5FVrRntuMsUL4Ed5fjzgUWeukU96ko%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
MediaType.APPLICATION_FORM_URLENCODED)).build();
|
||||
|
||||
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/regionEndpoints-all.xml", MediaType.APPLICATION_XML))
|
||||
.build();
|
||||
|
||||
protected final Map<HttpRequest, HttpResponse> describeAvailabilityZonesRequestResponse;
|
||||
|
||||
|
||||
public BaseEC2ExpectTest() {
|
||||
provider = "ec2";
|
||||
FormSigner formSigner = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
|
||||
formSigner = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
|
||||
createModule(), setupProperties()).getInstance(FormSigner.class);
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
for (String region : ImmutableSet.of("ap-northeast-1", "ap-southeast-1", "eu-west-1", "sa-east-1", "us-east-1", "us-west-1", "us-west-2")){
|
||||
|
@ -81,7 +88,24 @@ public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
|||
}
|
||||
|
||||
@ConfiguresRestClient
|
||||
private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
||||
protected static class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
// predicatable node names
|
||||
final AtomicInteger suffix = new AtomicInteger();
|
||||
bind(new TypeLiteral<Supplier<String>>() {
|
||||
}).toInstance(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return suffix.getAndIncrement() + "";
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Provides
|
||||
protected String provideTimeStamp(DateService dateService) {
|
||||
|
|
|
@ -46,7 +46,7 @@ public class KeyPairResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
|
||||
InputStream is = getClass().getResourceAsStream("/create_keypair.xml");
|
||||
|
||||
KeyPair expected = KeyPair.builder().region(defaultRegion).keyName("adriancole-ec21").sha1OfPrivateKey(
|
||||
KeyPair expected = KeyPair.builder().region(defaultRegion).keyName("jclouds#test#0").sha1OfPrivateKey(
|
||||
"13:36:74:b9:56:bb:07:96:c0:19:ab:00:7f:9f:06:d2:16:a0:45:32").keyMaterial(
|
||||
"-----BEGIN RSA PRIVATE KEY-----\n"
|
||||
+ "MIIEowIBAAKCAQEA0CbFlhSdbMdad2ux2BVqk6Ut5fLKb0CdbqubGcEBfwsSz9Rp4Ile76P90MpV\n"
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<AuthorizeSecurityGroupIngressResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>9b6a9df1-bc19-4e56-9d11-7f8382538667</requestId>
|
||||
<return>true</return>
|
||||
</AuthorizeSecurityGroupIngressResponse>
|
|
@ -1,6 +1,6 @@
|
|||
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>bb5e3a3c-e254-454d-ba29-d607cdf6357a</requestId>
|
||||
<keyName>adriancole-ec21</keyName>
|
||||
<keyName>jclouds#test#0</keyName>
|
||||
<keyFingerprint>13:36:74:b9:56:bb:07:96:c0:19:ab:00:7f:9f:06:d2:16:a0:45:32</keyFingerprint>
|
||||
<keyMaterial>-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEA0CbFlhSdbMdad2ux2BVqk6Ut5fLKb0CdbqubGcEBfwsSz9Rp4Ile76P90MpV
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CreateSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>8bf8a888-33af-459a-8424-13d4da0c2341</requestId>
|
||||
<return>true</return>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
</CreateSecurityGroupResponse>
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>f6d3252e-35e5-4ef5-b2c5-62da95dd829b</requestId>
|
||||
<reservationSet>
|
||||
<item>
|
||||
<reservationId>r-205ad944</reservationId>
|
||||
<ownerId>993194456877</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
<groupName>jclouds#mygroup2</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<instanceId>i-2baa5550</instanceId>
|
||||
<imageId>ami-aecd60c7</imageId>
|
||||
<instanceState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</instanceState>
|
||||
<privateDnsName>ip-10-28-89-195.ec2.internal</privateDnsName>
|
||||
<dnsName>ec2-50-16-1-166.compute-1.amazonaws.com</dnsName>
|
||||
<reason/>
|
||||
<keyName>jclouds#mygroup2#81</keyName>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<productCodes/>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
<launchTime>2012-08-02T04:28:30.000Z</launchTime>
|
||||
<placement>
|
||||
<availabilityZone>us-east-1e</availabilityZone>
|
||||
<groupName/>
|
||||
<tenancy>default</tenancy>
|
||||
</placement>
|
||||
<kernelId>aki-88aa75e1</kernelId>
|
||||
<monitoring>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
<privateIpAddress>10.28.89.195</privateIpAddress>
|
||||
<ipAddress>50.16.1.166</ipAddress>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
<groupName>jclouds#mygroup2</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<architecture>x86_64</architecture>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/sda1</deviceName>
|
||||
<ebs>
|
||||
<volumeId>vol-f2d7c993</volumeId>
|
||||
<status>attached</status>
|
||||
<attachTime>2012-08-02T04:28:56.000Z</attachTime>
|
||||
<deleteOnTermination>true</deleteOnTermination>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
<clientToken/>
|
||||
<tagSet>
|
||||
<item>
|
||||
<key>Name</key>
|
||||
<value>mygroup2-2baa5550</value>
|
||||
</item>
|
||||
</tagSet>
|
||||
<hypervisor>xen</hypervisor>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</item>
|
||||
</reservationSet>
|
||||
</DescribeInstancesResponse>
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>99260d2b-1bdc-4473-b386-48d22e96900a</requestId>
|
||||
<reservationId>r-205ad944</reservationId>
|
||||
<ownerId>993194456877</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
<groupName>jclouds#test</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<instanceId>i-2baa5550</instanceId>
|
||||
<imageId>ami-aecd60c7</imageId>
|
||||
<instanceState>
|
||||
<code>0</code>
|
||||
<name>pending</name>
|
||||
</instanceState>
|
||||
<privateDnsName/>
|
||||
<dnsName/>
|
||||
<reason/>
|
||||
<keyName>jclouds#test#1</keyName>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<productCodes/>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
<launchTime>2012-08-02T04:28:30.000Z</launchTime>
|
||||
<placement>
|
||||
<availabilityZone>us-east-1e</availabilityZone>
|
||||
<groupName/>
|
||||
<tenancy>default</tenancy>
|
||||
</placement>
|
||||
<kernelId>aki-88aa75e1</kernelId>
|
||||
<monitoring>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
<groupName>jclouds#test</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<stateReason>
|
||||
<code>pending</code>
|
||||
<message>pending</message>
|
||||
</stateReason>
|
||||
<architecture>x86_64</architecture>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping/>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
<clientToken/>
|
||||
<hypervisor>xen</hypervisor>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</RunInstancesResponse>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DescribeSecurityGroupsResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>6df3e2a6-76c0-414b-89ff-9318144e0bbe</requestId>
|
||||
<securityGroupInfo>
|
||||
<item>
|
||||
<ownerId>993194456877</ownerId>
|
||||
<groupId>sg-3c6ef654</groupId>
|
||||
<groupName>jclouds#test</groupName>
|
||||
<groupDescription>jclouds#test</groupDescription>
|
||||
<ipPermissions/>
|
||||
<ipPermissionsEgress/>
|
||||
</item>
|
||||
</securityGroupInfo>
|
||||
</DescribeSecurityGroupsResponse>
|
Loading…
Reference in New Issue