From f52a264b87253cbfdff4e66d43f3e1d53c0dc579 Mon Sep 17 00:00:00 2001 From: Chris Custine Date: Thu, 12 Jun 2014 03:22:59 -0600 Subject: [PATCH] JCLOUDS-594: ComputeService.suspendNodesMatching throwing UnsupportedOperationException but call still succeeds --- .../compute/NovaComputeServiceAdapter.java | 6 +- .../NovaComputeServiceAdapterExpectTest.java | 80 +++++++++++++++++-- .../compute/NovaComputeServiceExpectTest.java | 2 +- .../nova/v2_0/parse/ParseServerTest.java | 2 +- .../parse/ParseServerWithoutImageTest.java | 2 +- .../predicates/ServerPredicatesMockTest.java | 6 +- .../src/test/resources/server_details.json | 2 +- .../server_details_without_image.json | 2 +- .../test/resources/server_list_details.json | 2 +- 9 files changed, 88 insertions(+), 16 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index e4ceade1bc..5575e251b0 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -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"); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java index a9dce036e3..4d117411cf 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java @@ -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 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 requestResponseMap = ImmutableMap. 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 requestResponseMap = ImmutableMap. 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(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java index 188896390e..aba7a895d9 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceExpectTest.java @@ -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"); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerTest.java index 1b53135933..e287c01a94 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerTest.java @@ -59,7 +59,7 @@ public class ParseServerTest extends BaseItemParserTest { public Server expected() { return Server .builder() - .id("52415800-8b69-11e0-9b19-734f000004d2") + .id("71752") .tenantId("1234") .userId("5678") .name("sample-f352") diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithoutImageTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithoutImageTest.java index d58d8d0ec4..fa2d7a045e 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithoutImageTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithoutImageTest.java @@ -54,7 +54,7 @@ public class ParseServerWithoutImageTest extends BaseItemParserTest { public Server expected() { return Server .builder() - .id("52415800-8b69-11e0-9b19-734f000004d2") + .id("71752") .tenantId("1234") .userId("5678") .name("sample-f352") diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/ServerPredicatesMockTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/ServerPredicatesMockTest.java index 4498c7c43f..a8479ab508 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/ServerPredicatesMockTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/ServerPredicatesMockTest.java @@ -43,7 +43,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest { 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 = 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 = 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); diff --git a/apis/openstack-nova/src/test/resources/server_details.json b/apis/openstack-nova/src/test/resources/server_details.json index b5936c58c5..158d7793d3 100644 --- a/apis/openstack-nova/src/test/resources/server_details.json +++ b/apis/openstack-nova/src/test/resources/server_details.json @@ -1,6 +1,6 @@ { "server": { - "id": "52415800-8b69-11e0-9b19-734f000004d2", + "id": "71752", "tenant_id": "1234", "user_id": "5678", "name": "sample-f352", diff --git a/apis/openstack-nova/src/test/resources/server_details_without_image.json b/apis/openstack-nova/src/test/resources/server_details_without_image.json index 94487338bf..036a5d126f 100644 --- a/apis/openstack-nova/src/test/resources/server_details_without_image.json +++ b/apis/openstack-nova/src/test/resources/server_details_without_image.json @@ -1,6 +1,6 @@ { "server": { - "id": "52415800-8b69-11e0-9b19-734f000004d2", + "id": "71752", "tenant_id": "1234", "user_id": "5678", "name": "sample-f352", diff --git a/apis/openstack-nova/src/test/resources/server_list_details.json b/apis/openstack-nova/src/test/resources/server_list_details.json index 7ad6a75554..7624eaf9d4 100644 --- a/apis/openstack-nova/src/test/resources/server_list_details.json +++ b/apis/openstack-nova/src/test/resources/server_list_details.json @@ -1,7 +1,7 @@ { "servers": [ { - "id": "52415800-8b69-11e0-9b19-734f000004d2", + "id": "71752", "tenant_id": "1234", "user_id": "5678", "name": "sample-server",