JCLOUDS-594: ComputeService.suspendNodesMatching throwing UnsupportedOperationException but call still succeeds

This commit is contained in:
Chris Custine 2014-06-12 03:22:59 -06:00 committed by Andrew Phillips
parent 1db5d38a09
commit 4d5f57a303
9 changed files with 88 additions and 16 deletions

View File

@ -268,17 +268,19 @@ 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");
}
}
@Override
public void suspendNode(String id) {
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");
}
}
}

View File

@ -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;
@ -338,6 +339,75 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
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();

View File

@ -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");
}

View File

@ -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")

View File

@ -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")

View File

@ -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);

View File

@ -1,6 +1,6 @@
{
"server": {
"id": "52415800-8b69-11e0-9b19-734f000004d2",
"id": "71752",
"tenant_id": "1234",
"user_id": "5678",
"name": "sample-f352",

View File

@ -1,6 +1,6 @@
{
"server": {
"id": "52415800-8b69-11e0-9b19-734f000004d2",
"id": "71752",
"tenant_id": "1234",
"user_id": "5678",
"name": "sample-f352",

View File

@ -1,7 +1,7 @@
{
"servers": [
{
"id": "52415800-8b69-11e0-9b19-734f000004d2",
"id": "71752",
"tenant_id": "1234",
"user_id": "5678",
"name": "sample-server",