mirror of https://github.com/apache/jclouds.git
Tidyup the AfterClass methods for VApp test groups to ensure environment always cleaned up
This commit is contained in:
parent
a13e63c0ef
commit
b09f35fa9d
|
@ -39,8 +39,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Represents a media.
|
||||
* <p/>
|
||||
* Represents removable media, such as a CD-ROM, DVD or Floppy disk.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="Media" />
|
||||
* </pre>
|
||||
|
@ -53,7 +53,7 @@ public class Media extends ResourceEntity {
|
|||
public static enum ImageType {
|
||||
@XmlEnumValue("iso") ISO("iso"),
|
||||
@XmlEnumValue("floppy") FLOPPY("floppy"),
|
||||
UNRECOGNIZED("unrecognized");
|
||||
@XmlEnumValue("") UNRECOGNIZED("unrecognized");
|
||||
|
||||
public static final List<ImageType> ALL = ImmutableList.of(ISO, FLOPPY);
|
||||
|
||||
|
|
|
@ -189,8 +189,9 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
}
|
||||
|
||||
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
|
||||
protected void cleanUp() {
|
||||
protected void cleanUpEnvironment() {
|
||||
vdc = vdcClient.getVdc(vdcURI); // Refresh
|
||||
|
||||
// Find references in the Vdc with the VApp type and in the list of instantiated VApp names
|
||||
Iterable<Reference> vApps = Iterables.filter(vdc.getResourceEntities(),
|
||||
Predicates.and(ReferencePredicates.<Reference> typeEquals(VCloudDirectorMediaType.VAPP), ReferencePredicates.<Reference> nameIn(vAppNames)));
|
||||
|
|
|
@ -116,10 +116,10 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
Media sourceMedia = Media.builder()
|
||||
.type(VCloudDirectorMediaType.MEDIA)
|
||||
.name("Test media "+random.nextInt())
|
||||
.name(name("media"))
|
||||
.size(iso.length)
|
||||
.imageType(Media.ImageType.ISO)
|
||||
.description("Test media generated by vAppClientLiveTest")
|
||||
.description("Test media generated by VAppClientLiveTest")
|
||||
.build();
|
||||
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
|
||||
|
||||
|
@ -149,22 +149,21 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@AfterClass(alwaysRun = true)
|
||||
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||
public void cleanUp() {
|
||||
if (adminContext != null && mediaCreated && mediaURI != null) {
|
||||
try {
|
||||
Task delete = context.getApi().getMediaClient().deleteMedia(mediaURI);
|
||||
taskDoneEventually(delete);
|
||||
Task delete = context.getApi().getMediaClient().deleteMedia(mediaURI);
|
||||
taskDoneEventually(delete);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error when deleting media: %s", e.getMessage());
|
||||
logger.warn(e, "Error when deleting media");
|
||||
}
|
||||
}
|
||||
if (adminContext != null && testUserCreated && testUserURI != null) {
|
||||
try {
|
||||
adminContext.getApi().getUserClient().deleteUser(testUserURI);
|
||||
adminContext.getApi().getUserClient().deleteUser(testUserURI);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error when deleting user: %s", e.getMessage());
|
||||
logger.warn(e, "Error when deleting user");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
@Test(description = "POST /vApp/{id}/action/deploy", dependsOnMethods = { "testGetVApp" })
|
||||
public void testDeployVApp() {
|
||||
DeployVAppParams params = DeployVAppParams.builder()
|
||||
.deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
|
||||
.deploymentLeaseSeconds((int)TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
|
||||
.notForceCustomization()
|
||||
.notPowerOn()
|
||||
.build();
|
||||
|
|
|
@ -90,7 +90,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
private String key;
|
||||
private String val;
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||
protected void tidyUp() {
|
||||
if (key != null) {
|
||||
try {
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.jclouds.vcloud.director.v1_5.domain.RasdItemsList;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ScreenTicket;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswer;
|
||||
|
@ -41,7 +40,6 @@ import org.jclouds.vcloud.director.v1_5.domain.dmtf.RasdItem;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.MediaInsertOrEjectParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.RecomposeVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.RelocateParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection;
|
||||
|
|
|
@ -134,10 +134,10 @@ public class VmClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
Media sourceMedia = Media.builder()
|
||||
.type(VCloudDirectorMediaType.MEDIA)
|
||||
.name("Test media "+random.nextInt())
|
||||
.name(name("media"))
|
||||
.size(iso.length)
|
||||
.imageType(Media.ImageType.ISO)
|
||||
.description("Test media generated by vmClient.iveTest")
|
||||
.description("Test media generated by VmClientLiveTest")
|
||||
.build();
|
||||
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
|
||||
|
||||
|
@ -167,8 +167,7 @@ public class VmClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@AfterClass(alwaysRun = true)
|
||||
@AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
|
||||
public void cleanUp() {
|
||||
if (adminContext != null && mediaCreated && mediaURI != null) {
|
||||
try {
|
||||
|
|
|
@ -43,12 +43,13 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.RoleReferences;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
|
@ -56,8 +57,6 @@ import org.jclouds.vcloud.director.v1_5.domain.User;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vdc;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.Network;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
|
||||
|
@ -104,7 +103,7 @@ import com.google.inject.Guice;
|
|||
public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTest<VCloudDirectorContext> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.CONSOLE;
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected static final long TASK_TIMEOUT_SECONDS = 100L;
|
||||
protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L;
|
||||
|
@ -429,15 +428,12 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
protected void cleanUpVApp(URI vAppURI) {
|
||||
VAppClient vAppClient = context.getApi().getVAppClient();
|
||||
|
||||
VApp vApp;
|
||||
try {
|
||||
vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
logger.debug("Deleting VApp %s (%s)", vApp.getName(), vAppURI.getPath());
|
||||
} catch (VCloudDirectorException e) {
|
||||
// Presumably vApp has already been deleted. Ignore.
|
||||
VApp vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
if (vApp == null) {
|
||||
logger.info("Cannot find VApp at %s", vAppURI.getPath());
|
||||
return;
|
||||
return; // Presumably vApp has already been deleted. Ignore.
|
||||
}
|
||||
logger.debug("Deleting VApp %s (%s)", vApp.getName(), vAppURI.getPath());
|
||||
|
||||
// Wait for busy tasks to complete (don't care if it's failed or successful)
|
||||
// Otherwise, get error on delete "entity is busy completing an operation.
|
||||
|
@ -463,7 +459,9 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
// Undeploy the VApp if necessary
|
||||
if (vApp.isDeployed()) {
|
||||
try {
|
||||
UndeployVAppParams params = UndeployVAppParams.builder().build();
|
||||
UndeployVAppParams params = UndeployVAppParams.builder()
|
||||
.undeployPowerAction(UndeployVAppParams.PowerAction.SHUTDOWN)
|
||||
.build();
|
||||
Task undeployTask = vAppClient.undeploy(vAppURI, params);
|
||||
taskDoneEventually(undeployTask);
|
||||
} catch (Exception e) {
|
||||
|
@ -478,12 +476,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
vAppNames.remove(vApp.getName());
|
||||
logger.info("Deleted VApp %s", vApp.getName());
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
} catch (Exception e2) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
vApp = vAppClient.getVApp(vAppURI); // Refresh
|
||||
logger.warn(e, "Deleting VApp %s failed (%s)", vApp.getName(), vAppURI.getPath());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue