mirror of https://github.com/apache/jclouds.git
JCLOUDS-594: ComputeService.suspendNodesMatching throwing UnsupportedOperationException but call still succeeds
This commit is contained in:
parent
1db5d38a09
commit
4d5f57a303
|
@ -268,8 +268,9 @@ public class NovaComputeServiceAdapter implements
|
|||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
|
||||
}
|
||||
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -277,8 +278,9 @@ public class NovaComputeServiceAdapter implements
|
|||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension");
|
||||
}
|
||||
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertNull;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
|
@ -304,7 +305,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
* inject, then you simply cannot log in to the server.
|
||||
*/
|
||||
public void testNoKeyPairOrAdminPass() throws Exception {
|
||||
|
||||
|
||||
HttpRequest createServer = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
|
@ -314,7 +315,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
.payload(payloadFromStringWithContentType(
|
||||
"{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\"}}", "application/json"))
|
||||
.build();
|
||||
|
||||
|
||||
HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")
|
||||
.payload(payloadFromResourceWithContentType("/new_server_no_adminpass.json", "application/json; charset=UTF-8")).build();
|
||||
|
||||
|
@ -329,15 +330,84 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
|
|||
Injector forSecurityGroups = requestsSendResponses(requestResponseMap);
|
||||
|
||||
Template template = forSecurityGroups.getInstance(TemplateBuilder.class).build();
|
||||
|
||||
|
||||
NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class);
|
||||
|
||||
|
||||
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
|
||||
template);
|
||||
assertNotNull(server);
|
||||
assertNull(server.getCredentials());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test successful suspend/resume via ComputeService which depends on
|
||||
* Admin extension being installed in OpenStack
|
||||
*/
|
||||
public void testSuspendWithAdminExtensionSucceeds() throws Exception {
|
||||
|
||||
HttpRequest suspendServer = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/71752/action")
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"{\"suspend\":null}", "application/json"))
|
||||
.build();
|
||||
|
||||
HttpResponse suspendServerResponse = HttpResponse.builder()
|
||||
.statusCode(202)
|
||||
.build();
|
||||
|
||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||
.put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess)
|
||||
.put(extensionsOfNovaRequest, extensionsOfNovaResponse)
|
||||
.put(listDetail, listDetailResponse)
|
||||
.put(listFlavorsDetail, listFlavorsDetailResponse)
|
||||
.put(suspendServer, suspendServerResponse)
|
||||
.put(serverDetail, serverDetailResponse).build();
|
||||
|
||||
Injector forAdminExtension = requestsSendResponses(requestResponseMap);
|
||||
|
||||
ComputeService computeService = forAdminExtension.getInstance(ComputeService.class);
|
||||
|
||||
computeService.suspendNode("az-1.region-a.geo-1/71752");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test failed suspend/resume via ComputeService which depends on
|
||||
* Admin extension being installed in OpenStack. Throws UOE if extension is missing.
|
||||
*/
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void testSuspendWithoutAdminExtensionThrowsUOE() throws Exception {
|
||||
|
||||
HttpRequest suspendServer = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/71752/action")
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"{\"suspend\":null}", "application/json"))
|
||||
.build();
|
||||
|
||||
HttpResponse suspendServerResponse = HttpResponse.builder()
|
||||
.statusCode(202)
|
||||
.build();
|
||||
|
||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||
.put(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess)
|
||||
.put(extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse)
|
||||
.put(listDetail, listDetailResponse)
|
||||
.put(listFlavorsDetail, listFlavorsDetailResponse)
|
||||
.put(suspendServer, suspendServerResponse)
|
||||
.put(serverDetail, serverDetailResponse).build();
|
||||
|
||||
Injector forAdminExtension = requestsSendResponses(requestResponseMap);
|
||||
|
||||
ComputeService compute = forAdminExtension.getInstance(ComputeService.class);
|
||||
|
||||
compute.suspendNode("az-1.region-a.geo-1/71752");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injector apply(ComputeServiceContext input) {
|
||||
return input.utils().injector();
|
||||
|
|
|
@ -77,7 +77,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe
|
|||
assertNotNull(apiWhenServersExist.listNodes());
|
||||
assertEquals(apiWhenServersExist.listNodes().size(), 1);
|
||||
assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(),
|
||||
"az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f000004d2");
|
||||
"az-1.region-a.geo-1/71752");
|
||||
assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "sample-server");
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ParseServerTest extends BaseItemParserTest<Server> {
|
|||
public Server expected() {
|
||||
return Server
|
||||
.builder()
|
||||
.id("52415800-8b69-11e0-9b19-734f000004d2")
|
||||
.id("71752")
|
||||
.tenantId("1234")
|
||||
.userId("5678")
|
||||
.name("sample-f352")
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ParseServerWithoutImageTest extends BaseItemParserTest<Server> {
|
|||
public Server expected() {
|
||||
return Server
|
||||
.builder()
|
||||
.id("52415800-8b69-11e0-9b19-734f000004d2")
|
||||
.id("71752")
|
||||
.tenantId("1234")
|
||||
.userId("5678")
|
||||
.name("sample-f352")
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
|
|||
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
|
||||
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
|
||||
|
||||
boolean result = awaitActive(serverApi).apply("52415800-8b69-11e0-9b19-734f000004d2");
|
||||
boolean result = awaitActive(serverApi).apply("71752");
|
||||
|
||||
assertTrue(result);
|
||||
assertEquals(server.getRequestCount(), 5);
|
||||
|
@ -72,7 +72,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
|
|||
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
|
||||
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
|
||||
|
||||
boolean result = awaitShutoff(serverApi).apply("52415800-8b69-11e0-9b19-734f000004d2");
|
||||
boolean result = awaitShutoff(serverApi).apply("71752");
|
||||
|
||||
assertTrue(result);
|
||||
assertEquals(server.getRequestCount(), 7);
|
||||
|
@ -94,7 +94,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
|
|||
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
|
||||
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
|
||||
|
||||
boolean result = awaitStatus(serverApi, ACTIVE, 3, 1).apply("52415800-8b69-11e0-9b19-734f000004d2");
|
||||
boolean result = awaitStatus(serverApi, ACTIVE, 3, 1).apply("71752");
|
||||
|
||||
assertFalse(result);
|
||||
assertAuthentication(server);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"server": {
|
||||
"id": "52415800-8b69-11e0-9b19-734f000004d2",
|
||||
"id": "71752",
|
||||
"tenant_id": "1234",
|
||||
"user_id": "5678",
|
||||
"name": "sample-f352",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"server": {
|
||||
"id": "52415800-8b69-11e0-9b19-734f000004d2",
|
||||
"id": "71752",
|
||||
"tenant_id": "1234",
|
||||
"user_id": "5678",
|
||||
"name": "sample-f352",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"servers": [
|
||||
{
|
||||
"id": "52415800-8b69-11e0-9b19-734f000004d2",
|
||||
"id": "71752",
|
||||
"tenant_id": "1234",
|
||||
"user_id": "5678",
|
||||
"name": "sample-server",
|
||||
|
|
Loading…
Reference in New Issue