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 0f0207a045
commit f52a264b87
9 changed files with 88 additions and 16 deletions

View File

@ -270,8 +270,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
@ -279,8 +280,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");
}
}

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;
@ -306,7 +307,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")
@ -316,7 +317,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();
@ -331,15 +332,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();

View File

@ -79,7 +79,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

@ -59,7 +59,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

@ -43,7 +43,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);
@ -68,7 +68,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);
@ -90,7 +90,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",