straightened out AdminActionsApi test

This commit is contained in:
Adrian Cole 2012-09-16 12:36:41 -07:00
parent 09065a32ca
commit fae9ec1228
5 changed files with 116 additions and 110 deletions

View File

@ -156,7 +156,7 @@ public interface NovaApi {
* Provides synchronous access to Server Admin Actions features.
*/
@Delegate
Optional<? extends ServerAdminApi> getAdminActionsExtensionForZone(
Optional<? extends ServerAdminApi> getServerAdminExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**

View File

@ -155,7 +155,7 @@ public interface NovaAsyncApi {
* Provides asynchronous access to Server Admin Actions features.
*/
@Delegate
Optional<? extends ServerAdminAsyncApi> getAdminActionsExtensionForZone(
Optional<? extends ServerAdminAsyncApi> getServerAdminExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**

View File

@ -249,8 +249,8 @@ public class NovaComputeServiceAdapter implements
@Override
public void resumeNode(String id) {
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId());
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId());
}
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
}
@ -258,8 +258,8 @@ public class NovaComputeServiceAdapter implements
@Override
public void suspendNode(String id) {
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId());
if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId());
}
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension");
}

View File

@ -52,7 +52,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.suspend("1"));
}
@ -64,7 +64,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.suspend("1"));
}
@ -77,7 +77,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(403).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
api.suspend("1");
}
@ -89,7 +89,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.resume("1"));
}
@ -101,7 +101,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.resume("1"));
}
@ -114,7 +114,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(403).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
api.resume("1");
}
@ -126,7 +126,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.lock("1"));
}
@ -138,7 +138,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.lock("1"));
}
@ -150,7 +150,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.unlock("1"));
}
@ -162,7 +162,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.unlock("1"));
}
@ -174,7 +174,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.pause("1"));
}
@ -186,7 +186,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.pause("1"));
}
@ -198,7 +198,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.unpause("1"));
}
@ -210,7 +210,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.unpause("1"));
}
@ -222,7 +222,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.migrate("1"));
}
@ -235,7 +235,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.migrate("1"));
}
@ -247,7 +247,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.resetNetwork("1"));
}
@ -259,7 +259,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.resetNetwork("1"));
}
@ -271,7 +271,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.injectNetworkInfo("1"));
}
@ -283,7 +283,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.injectNetworkInfo("1"));
}
@ -295,7 +295,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
authenticatedGET().endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action").method("POST")
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(202).addHeader("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46").build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
String imageId = api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46");
@ -310,7 +310,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
authenticatedGET().endpoint(endpoint).method("POST")
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
}
@ -323,7 +323,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertTrue(api.liveMigrate("1", "bighost", true, false));
}
@ -336,7 +336,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
assertFalse(api.liveMigrate("1", "bighost", true, false));
}

View File

@ -32,6 +32,7 @@ import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions;
import org.jclouds.openstack.v2_0.features.ExtensionApi;
import org.testng.SkipException;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeGroups;
@ -45,7 +46,7 @@ import com.google.common.collect.Iterables;
* Tests behavior of HostAdministrationApi
*
* TODO test migration methods
*
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "AdminActionsApiLiveTest", singleThreaded = true)
@ -59,7 +60,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
private String testServerId;
private String backupImageId;
@BeforeGroups(groups = {"integration", "live"})
@BeforeGroups(groups = { "integration", "live" })
@Override
public void setupContext() {
super.setupContext();
@ -67,7 +68,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
serverApi = novaContext.getApi().getServerApiForZone(zone);
extensionApi = novaContext.getApi().getExtensionApiForZone(zone);
imageApi = novaContext.getApi().getImageApiForZone(zone);
apiOption = novaContext.getApi().getAdminActionsExtensionForZone(zone);
apiOption = novaContext.getApi().getServerAdminExtensionForZone(zone);
if (apiOption.isPresent()) {
testServerId = createServerInZone(zone).getId();
}
@ -87,105 +88,110 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
super.tearDown();
}
protected void skipOnAdminExtensionAbsent() {
if (!apiOption.isPresent()) {
throw new SkipException("Test depends on ServerAdminApi extension");
}
}
@AfterMethod(alwaysRun = true)
public void ensureServerIsActiveAgain() {
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
}
public void testSuspendAndResume() {
if (apiOption.isPresent()) {
ServerAdminApi api = apiOption.get();
// Suspend-resume
try {
api.resume(testServerId);
fail("Resumed an active server!");
} catch (HttpResponseException e) {
}
assertTrue(api.suspend(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED);
try {
api.suspend(testServerId);
fail("Suspended an already suspended server!");
} catch (HttpResponseException e) {
}
assertTrue(api.resume(testServerId));
if (apiOption.isPresent())
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
try {
api.resume(testServerId);
fail("Resumed an already resumed server!");
} catch (HttpResponseException e) {
}
}
public void testSuspendAndResume() {
skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get();
// Suspend-resume
try {
api.resume(testServerId);
fail("Resumed an active server!");
} catch (HttpResponseException e) {
}
assertTrue(api.suspend(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED);
try {
api.suspend(testServerId);
fail("Suspended an already suspended server!");
} catch (HttpResponseException e) {
}
assertTrue(api.resume(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
try {
api.resume(testServerId);
fail("Resumed an already resumed server!");
} catch (HttpResponseException e) {
}
}
public void testLockAndUnlock() {
if (apiOption.isPresent()) {
ServerAdminApi api = apiOption.get();
skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get();
// TODO should we be able to double-lock (as it were)
assertTrue(api.unlock(testServerId));
assertTrue(api.unlock(testServerId));
assertTrue(api.lock(testServerId));
assertTrue(api.lock(testServerId));
assertTrue(api.unlock(testServerId));
assertTrue(api.unlock(testServerId));
// TODO should we be able to double-lock (as it were)
assertTrue(api.unlock(testServerId));
assertTrue(api.unlock(testServerId));
assertTrue(api.lock(testServerId));
assertTrue(api.lock(testServerId));
assertTrue(api.unlock(testServerId));
assertTrue(api.unlock(testServerId));
}
}
public void testResetNetworkAndInjectNetworkInfo() {
if (apiOption.isPresent()) {
ServerAdminApi api = apiOption.get();
assertTrue(api.resetNetwork(testServerId));
assertTrue(api.injectNetworkInfo(testServerId));
}
skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get();
assertTrue(api.resetNetwork(testServerId));
assertTrue(api.injectNetworkInfo(testServerId));
}
@Test
public void testPauseAndUnpause() {
if (apiOption.isPresent()) {
ServerAdminApi api = apiOption.get();
skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get();
// Unlock and lock (double-checking error contitions too)
try {
api.unpause(testServerId);
fail("Unpaused active server!");
} catch (HttpResponseException e) {
}
assertTrue(api.pause(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.PAUSED);
try {
api.pause(testServerId);
fail("paused a paused server!");
} catch (HttpResponseException e) {
}
assertTrue(api.unpause(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
try {
api.unpause(testServerId);
fail("Unpaused a server we just unpaused!");
} catch (HttpResponseException e) {
}
// Unlock and lock (double-checking error contitions too)
try {
api.unpause(testServerId);
fail("Unpaused active server!");
} catch (HttpResponseException e) {
}
assertTrue(api.pause(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.PAUSED);
try {
api.pause(testServerId);
fail("paused a paused server!");
} catch (HttpResponseException e) {
}
assertTrue(api.unpause(testServerId));
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
try {
api.unpause(testServerId);
fail("Unpaused a server we just unpaused!");
} catch (HttpResponseException e) {
}
}
@Test
public void testCreateBackupOfServer() throws InterruptedException {
if (apiOption.isPresent()) {
backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0,
skipOnAdminExtensionAbsent();
backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0,
CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata")));
assertNotNull(backupImageId);
// If we don't have extended task status, we'll have to wait here!
if (extensionApi.get("OS-EXT-STS") == null) {
Thread.sleep(30000);
}
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
Image backupImage = imageApi.get(backupImageId);
assertEquals(backupImage.getId(), backupImageId);
assertNotNull(backupImageId);
// If we don't have extended task status, we'll have to wait here!
if (extensionApi.get("OS-EXT-STS") == null) {
Thread.sleep(30000);
}
}
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
Image backupImage = imageApi.get(backupImageId);
assertEquals(backupImage.getId(), backupImageId);
}
}