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. * Provides synchronous access to Server Admin Actions features.
*/ */
@Delegate @Delegate
Optional<? extends ServerAdminApi> getAdminActionsExtensionForZone( Optional<? extends ServerAdminApi> getServerAdminExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/** /**

View File

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

View File

@ -249,8 +249,8 @@ public class NovaComputeServiceAdapter implements
@Override @Override
public void resumeNode(String id) { public void resumeNode(String id) {
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId()); novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().resume(zoneAndId.getId());
} }
throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension"); throw new UnsupportedOperationException("resume requires installation of the Admin Actions extension");
} }
@ -258,8 +258,8 @@ public class NovaComputeServiceAdapter implements
@Override @Override
public void suspendNode(String id) { public void suspendNode(String id) {
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
if (novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).isPresent()) { if (novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).isPresent()) {
novaApi.getAdminActionsExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId()); novaApi.getServerAdminExtensionForZone(zoneAndId.getZone()).get().suspend(zoneAndId.getId());
} }
throw new UnsupportedOperationException("suspend requires installation of the Admin Actions extension"); 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, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.suspend("1"));
} }
@ -64,7 +64,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.suspend("1"));
} }
@ -77,7 +77,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(), standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
HttpResponse.builder().statusCode(403).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"); api.suspend("1");
} }
@ -89,7 +89,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.resume("1"));
} }
@ -101,7 +101,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.resume("1"));
} }
@ -114,7 +114,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resume").build(), standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
HttpResponse.builder().statusCode(403).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"); api.resume("1");
} }
@ -126,7 +126,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.lock("1"));
} }
@ -138,7 +138,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "lock").build(), standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.lock("1"));
} }
@ -150,7 +150,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.unlock("1"));
} }
@ -162,7 +162,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(), standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.unlock("1"));
} }
@ -174,7 +174,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.pause("1"));
} }
@ -186,7 +186,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "pause").build(), standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.pause("1"));
} }
@ -198,7 +198,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.unpause("1"));
} }
@ -210,7 +210,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(), standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.unpause("1"));
} }
@ -222,7 +222,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.migrate("1"));
} }
@ -235,7 +235,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(), standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.migrate("1"));
} }
@ -247,7 +247,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.resetNetwork("1"));
} }
@ -259,7 +259,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(), standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
HttpResponse.builder().statusCode(404).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")); assertFalse(api.resetNetwork("1"));
} }
@ -271,7 +271,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
HttpResponse.builder().statusCode(202).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")); assertTrue(api.injectNetworkInfo("1"));
} }
@ -283,7 +283,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(), standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
HttpResponse.builder().statusCode(404).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")); 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") 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(), .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() 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"))); 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"); assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46");
@ -310,7 +310,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
authenticatedGET().endpoint(endpoint).method("POST") authenticatedGET().endpoint(endpoint).method("POST")
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(), .payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).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"))); 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") standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(), .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(202).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)); assertTrue(api.liveMigrate("1", "bighost", true, false));
} }
@ -336,7 +336,7 @@ public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(), .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).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)); 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.internal.BaseNovaApiLiveTest;
import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions; import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions;
import org.jclouds.openstack.v2_0.features.ExtensionApi; import org.jclouds.openstack.v2_0.features.ExtensionApi;
import org.testng.SkipException;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
@ -59,7 +60,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
private String testServerId; private String testServerId;
private String backupImageId; private String backupImageId;
@BeforeGroups(groups = {"integration", "live"}) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
public void setupContext() { public void setupContext() {
super.setupContext(); super.setupContext();
@ -67,7 +68,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
serverApi = novaContext.getApi().getServerApiForZone(zone); serverApi = novaContext.getApi().getServerApiForZone(zone);
extensionApi = novaContext.getApi().getExtensionApiForZone(zone); extensionApi = novaContext.getApi().getExtensionApiForZone(zone);
imageApi = novaContext.getApi().getImageApiForZone(zone); imageApi = novaContext.getApi().getImageApiForZone(zone);
apiOption = novaContext.getApi().getAdminActionsExtensionForZone(zone); apiOption = novaContext.getApi().getServerAdminExtensionForZone(zone);
if (apiOption.isPresent()) { if (apiOption.isPresent()) {
testServerId = createServerInZone(zone).getId(); testServerId = createServerInZone(zone).getId();
} }
@ -87,13 +88,20 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
super.tearDown(); super.tearDown();
} }
protected void skipOnAdminExtensionAbsent() {
if (!apiOption.isPresent()) {
throw new SkipException("Test depends on ServerAdminApi extension");
}
}
@AfterMethod(alwaysRun = true) @AfterMethod(alwaysRun = true)
public void ensureServerIsActiveAgain() { public void ensureServerIsActiveAgain() {
if (apiOption.isPresent())
blockUntilServerInState(testServerId, serverApi, Status.ACTIVE); blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
} }
public void testSuspendAndResume() { public void testSuspendAndResume() {
if (apiOption.isPresent()) { skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get(); ServerAdminApi api = apiOption.get();
// Suspend-resume // Suspend-resume
@ -116,11 +124,11 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
fail("Resumed an already resumed server!"); fail("Resumed an already resumed server!");
} catch (HttpResponseException e) { } catch (HttpResponseException e) {
} }
}
} }
public void testLockAndUnlock() { public void testLockAndUnlock() {
if (apiOption.isPresent()) { skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get(); ServerAdminApi api = apiOption.get();
// TODO should we be able to double-lock (as it were) // TODO should we be able to double-lock (as it were)
@ -130,20 +138,19 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
assertTrue(api.lock(testServerId)); assertTrue(api.lock(testServerId));
assertTrue(api.unlock(testServerId)); assertTrue(api.unlock(testServerId));
assertTrue(api.unlock(testServerId)); assertTrue(api.unlock(testServerId));
}
} }
public void testResetNetworkAndInjectNetworkInfo() { public void testResetNetworkAndInjectNetworkInfo() {
if (apiOption.isPresent()) { skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get(); ServerAdminApi api = apiOption.get();
assertTrue(api.resetNetwork(testServerId)); assertTrue(api.resetNetwork(testServerId));
assertTrue(api.injectNetworkInfo(testServerId)); assertTrue(api.injectNetworkInfo(testServerId));
} }
}
@Test @Test
public void testPauseAndUnpause() { public void testPauseAndUnpause() {
if (apiOption.isPresent()) { skipOnAdminExtensionAbsent();
ServerAdminApi api = apiOption.get(); ServerAdminApi api = apiOption.get();
// Unlock and lock (double-checking error contitions too) // Unlock and lock (double-checking error contitions too)
@ -166,12 +173,12 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
fail("Unpaused a server we just unpaused!"); fail("Unpaused a server we just unpaused!");
} catch (HttpResponseException e) { } catch (HttpResponseException e) {
} }
}
} }
@Test @Test
public void testCreateBackupOfServer() throws InterruptedException { public void testCreateBackupOfServer() throws InterruptedException {
if (apiOption.isPresent()) { skipOnAdminExtensionAbsent();
backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0, backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0,
CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata"))); CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata")));
@ -187,5 +194,4 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
Image backupImage = imageApi.get(backupImageId); Image backupImage = imageApi.get(backupImageId);
assertEquals(backupImage.getId(), backupImageId); assertEquals(backupImage.getId(), backupImageId);
} }
}
} }