Renamed getPasswordData to getPasswordDataInRegion & fixed broken unit tests

This commit is contained in:
Andrei Savu 2012-02-04 20:18:50 +02:00
parent 27aaafe139
commit 4ed8f8f85e
4 changed files with 59 additions and 40 deletions

View File

@ -99,7 +99,7 @@ public interface WindowsAsyncClient {
@BinderParam(BindBundleIdsToIndexedFormParams.class) String... bundleTaskIds);
/**
* @see WindowsClient#getPasswordData
* @see WindowsClient#getPasswordDataInRegion
*/
@POST
@Path("/")

View File

@ -18,15 +18,14 @@
*/
package org.jclouds.ec2.services;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.domain.BundleTask;
import org.jclouds.ec2.domain.PasswordData;
import org.jclouds.ec2.options.BundleInstanceS3StorageOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.ec2.domain.BundleTask;
import org.jclouds.ec2.options.BundleInstanceS3StorageOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides windows services for EC2. For more information, refer to the Amazon
@ -119,5 +118,5 @@ public interface WindowsClient {
* @param instanceId The ID of the instance to query
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-GetPasswordData.html" />
*/
PasswordData getPasswordData(@Nullable String region, String instanceId);
PasswordData getPasswordDataInRegion(@Nullable String region, String instanceId);
}

View File

@ -27,7 +27,6 @@ import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
@ -43,7 +42,6 @@ import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.PasswordData;
import org.jclouds.ec2.reference.EC2Constants;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.Logger;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext;
@ -51,12 +49,6 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import javax.annotation.Nullable;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -95,7 +87,7 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest {
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
overrides.put(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "206029621532");
overrides.put(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "206029621532"); /* Amazon Owner ID */
ComputeServiceContext serviceContext = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module>of(new Log4JLoggingModule(), new BouncyCastleCryptoModule()), overrides);
computeService = serviceContext.getComputeService();
@ -128,7 +120,7 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest {
}
@Test
public void testGetPasswordData() throws Exception {
public void testGetPasswordDataInRegion() throws Exception {
// Spin up a new node. Make sure to open the RDP port 3389
Template template = computeService.templateBuilder()
@ -150,7 +142,7 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest {
@Override
public boolean apply(@Nullable String s) {
if (Strings.isNullOrEmpty(s)) return false;
PasswordData data = client.getPasswordData(null, s);
PasswordData data = client.getPasswordDataInRegion(null, s);
if (data == null) return false;
return !Strings.isNullOrEmpty(data.getPasswordData());
}
@ -160,7 +152,7 @@ public class WindowsClientLiveTest extends BaseVersionedServiceLiveTest {
// Now pull together Amazon's encrypted password blob, and the private key that jclouds generated
PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(
client.getPasswordData(null, node.getProviderId()),
client.getPasswordDataInRegion(null, node.getProviderId()),
node.getCredentials().getPrivateKey());
// And apply it to the decryption function

View File

@ -18,11 +18,14 @@
*/
package org.jclouds.aws.ec2.compute.strategy;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.inject.Guice;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
@ -40,14 +43,10 @@ import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.inject.Guice;
import java.util.Map;
import java.util.Set;
import static org.testng.Assert.assertEquals;
/**
* @author Adrian Cole
@ -68,7 +67,12 @@ public class AWSEC2ImageParserTest {
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml")
.defaultCredentials(new LoginCredentials("ubuntu", false)).id("us-east-1/ami-7e28ca17")
.providerId("ami-7e28ca17").location(defaultLocation).version("20091130")
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build());
.userMetadata(ImmutableMap.of(
"owner", "099720109477",
"rootDeviceType", "instance-store",
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.build());
assertEquals(
Iterables.get(result, 4),
@ -84,6 +88,7 @@ public class AWSEC2ImageParserTest {
assertEquals(
Iterables.get(result, 6),
new ImageBuilder()
.name("ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04")
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
@ -91,7 +96,12 @@ public class AWSEC2ImageParserTest {
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
.defaultCredentials(new LoginCredentials("ubuntu", false)).id("us-east-1/ami-10f3a255")
.providerId("ami-10f3a255").location(defaultLocation).version("20100827")
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build());
.userMetadata(ImmutableMap.of(
"owner", "099720109477",
"rootDeviceType", "ebs",
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.build());
}
@ -120,13 +130,19 @@ public class AWSEC2ImageParserTest {
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.name("EC2 CentOS 5.4 HVM AMI")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).arch("hvm").version("5.4")
.description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build())
.description("EC2 CentOS 5.4 HVM AMI")
.defaultCredentials(new LoginCredentials("root", false)).id("us-east-1/ami-7ea24a17")
.providerId("ami-7ea24a17").location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build());
.userMetadata(ImmutableMap.of(
"owner", "206029621532",
"rootDeviceType", "ebs",
"virtualizationType", "hvm",
"hypervisor", "xen"))
.build());
}
@ -147,11 +163,11 @@ public class AWSEC2ImageParserTest {
assertEquals(
new Gson().toJson(Iterables.get(result, 1)),
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 2)),
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");
}
public void testParseAmznImage() {
@ -161,17 +177,24 @@ public class AWSEC2ImageParserTest {
assertEquals(
Iterables.get(result, 0),
new ImageBuilder()
.name("amzn-ami-0.9.7-beta.i386-ebs")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
.version("0.9.7-beta").description("137112412989/amzn-ami-0.9.7-beta.i386-ebs")
.is64Bit(false).build()).description("Amazon")
.defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7")
.providerId("ami-82e4b5c7").location(defaultLocation).version("0.9.7-beta")
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
.userMetadata(ImmutableMap.of(
"owner", "137112412989",
"rootDeviceType", "ebs",
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.build());
assertEquals(
Iterables.get(result, 3),
new ImageBuilder()
.name("amzn-ami-0.9.7-beta.x86_64-S3")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
.version("0.9.7-beta")
@ -179,7 +202,12 @@ public class AWSEC2ImageParserTest {
.build()).description("Amazon Linux AMI x86_64 S3")
.defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-f2e4b5b7")
.providerId("ami-f2e4b5b7").location(defaultLocation).version("0.9.7-beta")
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
.userMetadata(ImmutableMap.of(
"owner", "137112412989",
"rootDeviceType", "ebs",
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.build());
}
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")