mirror of https://github.com/apache/jclouds.git
Merge pull request #769 from vijaykiran/issue-1051
Issue-1051 overrideLoginUser not working
This commit is contained in:
commit
f1ab4e466f
|
@ -20,7 +20,6 @@ package org.jclouds.ec2.compute.config;
|
|||
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -35,7 +34,6 @@ import org.jclouds.compute.domain.NodeMetadata.Status;
|
|||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.extensions.ImageExtension;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.compute.EC2ComputeService;
|
||||
import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
|
||||
|
@ -67,7 +65,6 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -120,7 +117,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
|||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
||||
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
|
||||
bind(ComputeService.class).to(EC2ComputeService.class);
|
||||
bind(new TypeLiteral<CacheLoader<RunningInstance, Credentials>>() {
|
||||
bind(new TypeLiteral<CacheLoader<RunningInstance, LoginCredentials>>() {
|
||||
}).to(CredentialsForInstance.class);
|
||||
bind(new TypeLiteral<Function<RegionAndName, KeyPair>>() {
|
||||
}).to(CreateUniqueKeyPair.class);
|
||||
|
@ -157,7 +154,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
|
||||
protected LoadingCache<RunningInstance, LoginCredentials> credentialsMap(CacheLoader<RunningInstance, LoginCredentials> in) {
|
||||
return CacheBuilder.newBuilder().build(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.domain.KeyPair;
|
||||
|
@ -44,7 +43,7 @@ import com.google.common.cache.LoadingCache;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CredentialsForInstance extends CacheLoader<RunningInstance, Credentials> {
|
||||
public class CredentialsForInstance extends CacheLoader<RunningInstance, LoginCredentials> {
|
||||
|
||||
private final ConcurrentMap<RegionAndName, KeyPair> credentialsMap;
|
||||
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap;
|
||||
|
@ -59,11 +58,11 @@ public class CredentialsForInstance extends CacheLoader<RunningInstance, Credent
|
|||
}
|
||||
|
||||
@Override
|
||||
public Credentials load(final RunningInstance instance) throws ExecutionException {
|
||||
public LoginCredentials load(final RunningInstance instance) throws ExecutionException {
|
||||
if ("windows".equals(instance.getPlatform())) {
|
||||
return passwordCredentialsFromWindowsInstance.apply(instance);
|
||||
} else if (instance.getKeyName() != null) {
|
||||
return new Credentials(getLoginAccountFor(instance), getPrivateKeyOrNull(instance));
|
||||
return LoginCredentials.builder().user(getLoginAccountFor(instance)).privateKey(getPrivateKeyOrNull(instance)).build();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -39,10 +39,13 @@ import org.jclouds.compute.config.CustomizationResponse;
|
|||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import static org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials.*;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.predicates.InstancePresent;
|
||||
|
@ -57,9 +60,9 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.base.Predicate;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
/**
|
||||
* creates futures that correlate to
|
||||
|
@ -91,12 +94,10 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
|
|||
@VisibleForTesting
|
||||
final ComputeUtils utils;
|
||||
final InstancePresent instancePresent;
|
||||
final LoadingCache<RunningInstance, Credentials> instanceToCredentials;
|
||||
final LoadingCache<RunningInstance, LoginCredentials> instanceToCredentials;
|
||||
final Map<String, Credentials> credentialStore;
|
||||
final Provider<TemplateBuilder> templateBuilderProvider;
|
||||
|
||||
|
||||
|
||||
@Inject
|
||||
protected EC2CreateNodesInGroupThenAddToSet(
|
||||
EC2Client client,
|
||||
|
@ -106,7 +107,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
|
|||
Provider<TemplateBuilder> templateBuilderProvider,
|
||||
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
|
||||
InstancePresent instancePresent, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
||||
LoadingCache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
|
||||
LoadingCache<RunningInstance, LoginCredentials> instanceToCredentials, Map<String, Credentials> credentialStore,
|
||||
ComputeUtils utils) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.elasticIpCache = checkNotNull(elasticIpCache, "elasticIpCache");
|
||||
|
@ -147,7 +148,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
|
|||
logger.debug("<< started instances(%s)", idsString);
|
||||
all(ids, instancePresent);
|
||||
logger.debug("<< present instances(%s)", idsString);
|
||||
populateCredentials(started);
|
||||
populateCredentials(started, template.getOptions());
|
||||
}
|
||||
|
||||
assignElasticIpsToInstances(ips, started);
|
||||
|
@ -156,13 +157,14 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
|
|||
runningInstanceToNodeMetadata), goodNodes, badNodes, customizationResponses);
|
||||
}
|
||||
|
||||
protected void populateCredentials(Iterable<? extends RunningInstance> started) {
|
||||
Credentials credentials = null;
|
||||
protected void populateCredentials(Iterable<? extends RunningInstance> started, TemplateOptions options) {
|
||||
LoginCredentials credentials = null;
|
||||
for (RunningInstance instance : started) {
|
||||
credentials = instanceToCredentials.apply(instance);
|
||||
if (credentials != null)
|
||||
break;
|
||||
}
|
||||
credentials = overrideDefaultCredentialsWithOptionsIfPresent(credentials, options);
|
||||
if (credentials != null)
|
||||
for (RunningInstance instance : started)
|
||||
credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), credentials);
|
||||
|
|
|
@ -207,8 +207,6 @@ public class EC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest
|
|||
.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);
|
||||
|
@ -228,6 +226,32 @@ public class EC2ComputeServiceExpectTest extends BaseEC2ComputeServiceExpectTest
|
|||
NodeMetadata node = Iterables.getOnlyElement(apiThatCreatesNode.createNodesInGroup("test", 1,
|
||||
blockUntilRunning(false).overrideLoginUser("ec2-user")));
|
||||
assertEquals(node.getCredentials().getUser(), "ec2-user");
|
||||
System.out.println(node.getImageId());
|
||||
assertNotNull(node.getCredentials().getPrivateKey());
|
||||
}
|
||||
|
||||
//FIXME - issue-1051
|
||||
@Test(enabled = false)
|
||||
public void testCreateNodeWithGeneratedKeyPairAndOverriddenLoginUserWithTemplateBuilder() 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,
|
||||
apiThatCreatesNode.templateBuilder().from("osDescriptionMatches=.*fedora.*,loginUser=ec2-user").build()));
|
||||
assertEquals(node.getCredentials().getUser(), "ec2-user");
|
||||
assertNotNull(node.getCredentials().getPrivateKey());
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.jclouds.compute.config.CustomizationResponse;
|
|||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||
import org.jclouds.compute.predicates.AtomicNodeRunning;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
|
@ -44,6 +44,7 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
|
@ -116,13 +117,17 @@ public class EC2CreateNodesInGroupThenAddToSetTest {
|
|||
Reservation.class.cast(reservation));
|
||||
expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
|
||||
// simulate a lazy credentials fetch
|
||||
Credentials creds = new Credentials("foo", "bar");
|
||||
LoginCredentials creds = LoginCredentials.builder().user("foo").privateKey("bar").build();
|
||||
expect(strategy.instanceToCredentials.apply(instance)).andReturn(creds);
|
||||
expect(instance.getRegion()).andReturn(region).atLeastOnce();
|
||||
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null);
|
||||
|
||||
expect(strategy.instancePresent.apply(new RegionAndName(region, instanceCreatedId))).andReturn(true);
|
||||
expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
|
||||
expect(input.options.getLoginUser()).andReturn(null);
|
||||
expect(input.options.getLoginPassword()).andReturn(null);
|
||||
expect(input.options.getLoginPrivateKey()).andReturn(null);
|
||||
expect(input.options.shouldAuthenticateSudo()).andReturn(null);
|
||||
|
||||
expect(
|
||||
strategy.utils.customizeNodesAndAddToGoodMapOrPutExceptionIntoBadMap(eq(input.options),
|
||||
|
@ -213,13 +218,18 @@ public class EC2CreateNodesInGroupThenAddToSetTest {
|
|||
Reservation.class.cast(reservation));
|
||||
expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
|
||||
// simulate a lazy credentials fetch
|
||||
Credentials creds = new Credentials("foo", "bar");
|
||||
LoginCredentials creds = LoginCredentials.builder().user("foo").privateKey("bar").build();
|
||||
expect(strategy.instanceToCredentials.apply(instance)).andReturn(creds);
|
||||
expect(instance.getRegion()).andReturn(region).atLeastOnce();
|
||||
expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null);
|
||||
|
||||
expect(strategy.instancePresent.apply(new RegionAndName(region, instanceCreatedId))).andReturn(true);
|
||||
expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
|
||||
expect(input.options.getLoginUser()).andReturn(null);
|
||||
expect(input.options.getLoginPassword()).andReturn(null);
|
||||
expect(input.options.getLoginPrivateKey()).andReturn(null);
|
||||
expect(input.options.shouldAuthenticateSudo()).andReturn(null);
|
||||
|
||||
|
||||
expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata);
|
||||
expect(
|
||||
|
@ -310,7 +320,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest {
|
|||
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize = createMock(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class);
|
||||
InstancePresent instancePresent = createMock(InstancePresent.class);
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata = createMock(RunningInstanceToNodeMetadata.class);
|
||||
LoadingCache<RunningInstance, Credentials> instanceToCredentials = createMock(LoadingCache.class);
|
||||
LoadingCache<RunningInstance, LoginCredentials> instanceToCredentials = createMock(LoadingCache.class);
|
||||
LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
|
||||
GetNodeMetadataStrategy nodeRunning = new GetNodeMetadataStrategy(){
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<privateDnsName/>
|
||||
<dnsName/>
|
||||
<reason/>
|
||||
<keyName>jclouds#test#1</keyName>
|
||||
<keyName>jclouds#test#0</keyName>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<productCodes/>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
|||
import org.jclouds.compute.extensions.ImageExtension;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
|
||||
import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
|
||||
|
@ -90,7 +89,7 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep
|
|||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
||||
bind(TemplateOptions.class).to(AWSEC2TemplateOptions.class);
|
||||
bind(ComputeService.class).to(AWSEC2ComputeService.class);
|
||||
bind(new TypeLiteral<CacheLoader<RunningInstance, Credentials>>() {
|
||||
bind(new TypeLiteral<CacheLoader<RunningInstance, LoginCredentials>>() {
|
||||
}).to(CredentialsForInstance.class);
|
||||
bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
|
||||
}).annotatedWith(Names.named("SECURITY")).to(CreateSecurityGroupIfNeeded.class);
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
|
||||
import org.jclouds.ec2.domain.RunningInstance;
|
||||
|
@ -88,7 +89,7 @@ public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupT
|
|||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
|
||||
AWSEC2InstancePresent instancePresent,
|
||||
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
||||
LoadingCache<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
|
||||
LoadingCache<RunningInstance, LoginCredentials> instanceToCredentials, Map<String, Credentials> credentialStore,
|
||||
ComputeUtils utils, SpotInstanceRequestToAWSRunningInstance spotConverter) {
|
||||
super(client, elasticIpCache, nodeRunning, templateBuilderProvider, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
|
||||
instancePresent, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
|
||||
|
|
Loading…
Reference in New Issue