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,8 +268,9 @@ public class NovaComputeServiceAdapter implements
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) { if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId()); 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 @Override
@ -277,8 +278,9 @@ public class NovaComputeServiceAdapter implements
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) { if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId()); 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.Map;
import java.util.Properties; import java.util.Properties;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Template; 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. * inject, then you simply cannot log in to the server.
*/ */
public void testNoKeyPairOrAdminPass() throws Exception { public void testNoKeyPairOrAdminPass() throws Exception {
HttpRequest createServer = HttpRequest HttpRequest createServer = HttpRequest
.builder() .builder()
.method("POST") .method("POST")
@ -314,7 +315,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
.payload(payloadFromStringWithContentType( .payload(payloadFromStringWithContentType(
"{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\"}}", "application/json")) "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\"}}", "application/json"))
.build(); .build();
HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted") 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(); .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); Injector forSecurityGroups = requestsSendResponses(requestResponseMap);
Template template = forSecurityGroups.getInstance(TemplateBuilder.class).build(); Template template = forSecurityGroups.getInstance(TemplateBuilder.class).build();
NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class); NovaComputeServiceAdapter adapter = forSecurityGroups.getInstance(NovaComputeServiceAdapter.class);
NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92", NodeAndInitialCredentials<ServerInZone> server = adapter.createNodeWithGroupEncodedIntoName("test", "test-e92",
template); template);
assertNotNull(server); assertNotNull(server);
assertNull(server.getCredentials()); 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 @Override
public Injector apply(ComputeServiceContext input) { public Injector apply(ComputeServiceContext input) {
return input.utils().injector(); return input.utils().injector();

View File

@ -77,7 +77,7 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe
assertNotNull(apiWhenServersExist.listNodes()); assertNotNull(apiWhenServersExist.listNodes());
assertEquals(apiWhenServersExist.listNodes().size(), 1); assertEquals(apiWhenServersExist.listNodes().size(), 1);
assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), 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"); assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "sample-server");
} }

View File

@ -56,7 +56,7 @@ public class ParseServerTest extends BaseItemParserTest<Server> {
public Server expected() { public Server expected() {
return Server return Server
.builder() .builder()
.id("52415800-8b69-11e0-9b19-734f000004d2") .id("71752")
.tenantId("1234") .tenantId("1234")
.userId("5678") .userId("5678")
.name("sample-f352") .name("sample-f352")

View File

@ -54,7 +54,7 @@ public class ParseServerWithoutImageTest extends BaseItemParserTest<Server> {
public Server expected() { public Server expected() {
return Server return Server
.builder() .builder()
.id("52415800-8b69-11e0-9b19-734f000004d2") .id("71752")
.tenantId("1234") .tenantId("1234")
.userId("5678") .userId("5678")
.name("sample-f352") .name("sample-f352")

View File

@ -47,7 +47,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne"); ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
boolean result = awaitActive(serverApi).apply("52415800-8b69-11e0-9b19-734f000004d2"); boolean result = awaitActive(serverApi).apply("71752");
assertTrue(result); assertTrue(result);
assertEquals(server.getRequestCount(), 5); assertEquals(server.getRequestCount(), 5);
@ -72,7 +72,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne"); ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
boolean result = awaitShutoff(serverApi).apply("52415800-8b69-11e0-9b19-734f000004d2"); boolean result = awaitShutoff(serverApi).apply("71752");
assertTrue(result); assertTrue(result);
assertEquals(server.getRequestCount(), 7); assertEquals(server.getRequestCount(), 7);
@ -94,7 +94,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne"); 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); assertFalse(result);
assertAuthentication(server); assertAuthentication(server);

View File

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

View File

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

View File

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