mirror of https://github.com/apache/jclouds.git
JCLOUDS-105. Short-term fix for keypairs being ignored if VM says it's password-enabled.
This commit is contained in:
parent
af0d1d3009
commit
f615eb11a3
|
@ -182,11 +182,11 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job);
|
VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job);
|
||||||
logger.debug("--- virtualmachine: %s", vm);
|
logger.debug("--- virtualmachine: %s", vm);
|
||||||
LoginCredentials credentials = null;
|
LoginCredentials credentials = null;
|
||||||
if (vm.isPasswordEnabled()) {
|
if (!vm.isPasswordEnabled() || templateOptions.getKeyPair() != null) {
|
||||||
|
credentials = LoginCredentials.fromCredentials(credentialStore.get("keypair#" + templateOptions.getKeyPair()));
|
||||||
|
} else {
|
||||||
assert vm.getPassword() != null : vm;
|
assert vm.getPassword() != null : vm;
|
||||||
credentials = LoginCredentials.builder().password(vm.getPassword()).build();
|
credentials = LoginCredentials.builder().password(vm.getPassword()).build();
|
||||||
} else {
|
|
||||||
credentials = LoginCredentials.fromCredentials(credentialStore.get("keypair#" + templateOptions.getKeyPair()));
|
|
||||||
}
|
}
|
||||||
if (templateOptions.shouldSetupStaticNat()) {
|
if (templateOptions.shouldSetupStaticNat()) {
|
||||||
Capabilities capabilities = client.getConfigurationClient().listCapabilities();
|
Capabilities capabilities = client.getConfigurationClient().listCapabilities();
|
||||||
|
|
|
@ -63,6 +63,57 @@ public class CloudStackComputeServiceAdapterExpectTest extends BaseCloudStackCom
|
||||||
.payload(payloadFromResource("/queryasyncjobresultresponse-virtualmachine.json"))
|
.payload(payloadFromResource("/queryasyncjobresultresponse-virtualmachine.json"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
HttpRequest listCapabilitiesNotListAll = HttpRequest.builder().method("GET")
|
||||||
|
.endpoint("http://localhost:8080/client/api")
|
||||||
|
.addQueryParam("response", "json")
|
||||||
|
.addQueryParam("command", "listCapabilities")
|
||||||
|
.addQueryParam("apiKey", "APIKEY")
|
||||||
|
.addQueryParam("signature", "l3PVoJnKK2G2gHk3HPHtpwWjlW4%3D")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public void testCreateNodeWithGroupEncodedIntoName() {
|
||||||
|
HttpRequest deployVM = HttpRequest.builder().method("GET")
|
||||||
|
.endpoint("http://localhost:8080/client/api")
|
||||||
|
.addQueryParam("response", "json")
|
||||||
|
.addQueryParam("command", "deployVirtualMachine")
|
||||||
|
.addQueryParam("zoneid", "1")
|
||||||
|
.addQueryParam("serviceofferingid", "1")
|
||||||
|
.addQueryParam("templateid", "4")
|
||||||
|
.addQueryParam("displayname", "test-e92")
|
||||||
|
.addQueryParam("name", "test-e92")
|
||||||
|
.addQueryParam("networkids", "204")
|
||||||
|
.addQueryParam("apiKey", "APIKEY")
|
||||||
|
.addQueryParam("signature", "wJ%2BiflOS3am5qcjQOd8Y/Pw8/Dc%3D")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||||
|
.put(listTemplates, listTemplatesResponse)
|
||||||
|
.put(listOsTypes, listOsTypesResponse)
|
||||||
|
.put(listOsCategories, listOsCategoriesResponse)
|
||||||
|
.put(listZones, listZonesResponse)
|
||||||
|
.put(listServiceOfferings, listServiceOfferingsResponse)
|
||||||
|
.put(listAccounts, listAccountsResponse)
|
||||||
|
.put(listNetworks, listNetworksResponse)
|
||||||
|
.put(getZone, getZoneResponse)
|
||||||
|
.put(deployVM, deployVMResponse)
|
||||||
|
.put(queryAsyncJobResult, queryAsyncJobResultResponse)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Injector forNode = requestsSendResponses(requestResponseMap);
|
||||||
|
|
||||||
|
Template template = forNode.getInstance(TemplateBuilder.class).osFamily(OsFamily.CENTOS).build();
|
||||||
|
template.getOptions().as(CloudStackTemplateOptions.class).setupStaticNat(false);
|
||||||
|
|
||||||
|
CloudStackComputeServiceAdapter adapter = forNode.getInstance(CloudStackComputeServiceAdapter.class);
|
||||||
|
|
||||||
|
NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||||
|
template);
|
||||||
|
assertNotNull(server);
|
||||||
|
assertEquals(server.getCredentials(), LoginCredentials.builder().password("dD7jwajkh").build());
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreateNodeWithGroupEncodedIntoNameWithKeyPair() {
|
public void testCreateNodeWithGroupEncodedIntoNameWithKeyPair() {
|
||||||
HttpRequest deployVM = HttpRequest.builder().method("GET")
|
HttpRequest deployVM = HttpRequest.builder().method("GET")
|
||||||
.endpoint("http://localhost:8080/client/api")
|
.endpoint("http://localhost:8080/client/api")
|
||||||
|
@ -99,11 +150,16 @@ public class CloudStackComputeServiceAdapterExpectTest extends BaseCloudStackCom
|
||||||
template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").setupStaticNat(false);
|
template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").setupStaticNat(false);
|
||||||
|
|
||||||
CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
|
CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
|
||||||
|
CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);
|
||||||
|
|
||||||
NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||||
template);
|
template);
|
||||||
assertNotNull(server);
|
assertNotNull(server);
|
||||||
assertEquals(server.getCredentials(), LoginCredentials.builder().password("dD7jwajkh").build());
|
assertEquals(server.getCredentials(),
|
||||||
|
LoginCredentials.fromCredentials(context.utils().getCredentialStore().get("keypair#" +
|
||||||
|
template.getOptions().
|
||||||
|
as(CloudStackTemplateOptions.class).
|
||||||
|
getKeyPair())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateNodeWithGroupEncodedIntoNameWithKeyPairAssignedToAccountAndDomain() {
|
public void testCreateNodeWithGroupEncodedIntoNameWithKeyPairAssignedToAccountAndDomain() {
|
||||||
|
@ -144,11 +200,16 @@ public class CloudStackComputeServiceAdapterExpectTest extends BaseCloudStackCom
|
||||||
template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").account("account").domainId("domainId").setupStaticNat(false);
|
template.getOptions().as(CloudStackTemplateOptions.class).keyPair("mykeypair").account("account").domainId("domainId").setupStaticNat(false);
|
||||||
|
|
||||||
CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
|
CloudStackComputeServiceAdapter adapter = forKeyPair.getInstance(CloudStackComputeServiceAdapter.class);
|
||||||
|
CloudStackContext context = forKeyPair.getInstance(CloudStackContext.class);
|
||||||
|
|
||||||
NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
NodeAndInitialCredentials<VirtualMachine> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||||
template);
|
template);
|
||||||
assertNotNull(server);
|
assertNotNull(server);
|
||||||
assertEquals(server.getCredentials(), LoginCredentials.builder().password("dD7jwajkh").build());
|
assertEquals(server.getCredentials(),
|
||||||
|
LoginCredentials.fromCredentials(context.utils().getCredentialStore().get("keypair#" +
|
||||||
|
template.getOptions().
|
||||||
|
as(CloudStackTemplateOptions.class).
|
||||||
|
getKeyPair())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue