Tidyup the AfterClass methods for VApp test groups to ensure environment always cleaned up

This commit is contained in:
Andrew Donald Kennedy 2012-04-26 12:21:54 +01:00
parent a13e63c0ef
commit b09f35fa9d
7 changed files with 29 additions and 39 deletions

View File

@ -39,8 +39,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
/** /**
* Represents a media. * Represents removable media, such as a CD-ROM, DVD or Floppy disk.
* <p/> *
* <pre> * <pre>
* &lt;complexType name="Media" /&gt; * &lt;complexType name="Media" /&gt;
* </pre> * </pre>
@ -53,7 +53,7 @@ public class Media extends ResourceEntity {
public static enum ImageType { public static enum ImageType {
@XmlEnumValue("iso") ISO("iso"), @XmlEnumValue("iso") ISO("iso"),
@XmlEnumValue("floppy") FLOPPY("floppy"), @XmlEnumValue("floppy") FLOPPY("floppy"),
UNRECOGNIZED("unrecognized"); @XmlEnumValue("") UNRECOGNIZED("unrecognized");
public static final List<ImageType> ALL = ImmutableList.of(ISO, FLOPPY); public static final List<ImageType> ALL = ImmutableList.of(ISO, FLOPPY);

View File

@ -189,8 +189,9 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
} }
@AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps") @AfterClass(alwaysRun = true, description = "Cleans up the environment by deleting created VApps")
protected void cleanUp() { protected void cleanUpEnvironment() {
vdc = vdcClient.getVdc(vdcURI); // Refresh vdc = vdcClient.getVdc(vdcURI); // Refresh
// Find references in the Vdc with the VApp type and in the list of instantiated VApp names // Find references in the Vdc with the VApp type and in the list of instantiated VApp names
Iterable<Reference> vApps = Iterables.filter(vdc.getResourceEntities(), Iterable<Reference> vApps = Iterables.filter(vdc.getResourceEntities(),
Predicates.and(ReferencePredicates.<Reference> typeEquals(VCloudDirectorMediaType.VAPP), ReferencePredicates.<Reference> nameIn(vAppNames))); Predicates.and(ReferencePredicates.<Reference> typeEquals(VCloudDirectorMediaType.VAPP), ReferencePredicates.<Reference> nameIn(vAppNames)));

View File

@ -116,10 +116,10 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
Media sourceMedia = Media.builder() Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA) .type(VCloudDirectorMediaType.MEDIA)
.name("Test media "+random.nextInt()) .name(name("media"))
.size(iso.length) .size(iso.length)
.imageType(Media.ImageType.ISO) .imageType(Media.ImageType.ISO)
.description("Test media generated by vAppClientLiveTest") .description("Test media generated by VAppClientLiveTest")
.build(); .build();
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia); Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
@ -149,22 +149,21 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
} }
} }
@Override @AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
@AfterClass(alwaysRun = true)
public void cleanUp() { public void cleanUp() {
if (adminContext != null && mediaCreated && mediaURI != null) { if (adminContext != null && mediaCreated && mediaURI != null) {
try { try {
Task delete = context.getApi().getMediaClient().deleteMedia(mediaURI); Task delete = context.getApi().getMediaClient().deleteMedia(mediaURI);
taskDoneEventually(delete); taskDoneEventually(delete);
} catch (Exception e) { } 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) { if (adminContext != null && testUserCreated && testUserURI != null) {
try { try {
adminContext.getApi().getUserClient().deleteUser(testUserURI); adminContext.getApi().getUserClient().deleteUser(testUserURI);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error when deleting user: %s", e.getMessage()); logger.warn(e, "Error when deleting user");
} }
} }
} }

View File

@ -90,7 +90,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
private String key; private String key;
private String val; private String val;
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
protected void tidyUp() { protected void tidyUp() {
if (key != null) { if (key != null) {
try { try {

View File

@ -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.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ScreenTicket; 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.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.Vm;
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion; import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswer; 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.ControlAccessParams;
import org.jclouds.vcloud.director.v1_5.domain.params.DeployVAppParams; 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.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.RelocateParams;
import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams; import org.jclouds.vcloud.director.v1_5.domain.params.UndeployVAppParams;
import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection; import org.jclouds.vcloud.director.v1_5.domain.section.GuestCustomizationSection;

View File

@ -134,10 +134,10 @@ public class VmClientLiveTest extends AbstractVAppClientLiveTest {
Media sourceMedia = Media.builder() Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA) .type(VCloudDirectorMediaType.MEDIA)
.name("Test media "+random.nextInt()) .name(name("media"))
.size(iso.length) .size(iso.length)
.imageType(Media.ImageType.ISO) .imageType(Media.ImageType.ISO)
.description("Test media generated by vmClient.iveTest") .description("Test media generated by VmClientLiveTest")
.build(); .build();
Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia); Media media = context.getApi().getMediaClient().createMedia(addMedia.getHref(), sourceMedia);
@ -167,8 +167,7 @@ public class VmClientLiveTest extends AbstractVAppClientLiveTest {
} }
} }
@Override @AfterClass(alwaysRun = true, dependsOnMethods = { "cleanUpEnvironment" })
@AfterClass(alwaysRun = true)
public void cleanUp() { public void cleanUp() {
if (adminContext != null && mediaCreated && mediaURI != null) { if (adminContext != null && mediaCreated && mediaURI != null) {
try { try {

View File

@ -43,12 +43,13 @@ import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.testng.FormatApiResultsListener; import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata; import org.jclouds.vcloud.director.v1_5.VCloudDirectorApiMetadata;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext; 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.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient; 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.admin.VCloudDirectorAdminClient;
import org.jclouds.vcloud.director.v1_5.domain.Link; 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.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.RoleReferences;
import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Session;
import org.jclouds.vcloud.director.v1_5.domain.Task; 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.VApp;
import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; 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.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.Network;
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConfiguration;
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration; 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> { public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTest<VCloudDirectorContext> {
@Resource @Resource
protected Logger logger = Logger.CONSOLE; protected Logger logger = Logger.NULL;
protected static final long TASK_TIMEOUT_SECONDS = 100L; protected static final long TASK_TIMEOUT_SECONDS = 100L;
protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L; protected static final long LONG_TASK_TIMEOUT_SECONDS = 300L;
@ -429,15 +428,12 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
protected void cleanUpVApp(URI vAppURI) { protected void cleanUpVApp(URI vAppURI) {
VAppClient vAppClient = context.getApi().getVAppClient(); VAppClient vAppClient = context.getApi().getVAppClient();
VApp vApp; VApp vApp = vAppClient.getVApp(vAppURI); // Refresh
try { if (vApp == null) {
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.
logger.info("Cannot find VApp at %s", vAppURI.getPath()); 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) // 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. // 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 // Undeploy the VApp if necessary
if (vApp.isDeployed()) { if (vApp.isDeployed()) {
try { try {
UndeployVAppParams params = UndeployVAppParams.builder().build(); UndeployVAppParams params = UndeployVAppParams.builder()
.undeployPowerAction(UndeployVAppParams.PowerAction.SHUTDOWN)
.build();
Task undeployTask = vAppClient.undeploy(vAppURI, params); Task undeployTask = vAppClient.undeploy(vAppURI, params);
taskDoneEventually(undeployTask); taskDoneEventually(undeployTask);
} catch (Exception e) { } catch (Exception e) {
@ -478,12 +476,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
vAppNames.remove(vApp.getName()); vAppNames.remove(vApp.getName());
logger.info("Deleted VApp %s", vApp.getName()); logger.info("Deleted VApp %s", vApp.getName());
} catch (Exception e) { } catch (Exception e) {
try {
vApp = vAppClient.getVApp(vAppURI); // Refresh vApp = vAppClient.getVApp(vAppURI); // Refresh
} catch (Exception e2) {
// Ignore
}
logger.warn(e, "Deleting VApp %s failed (%s)", vApp.getName(), vAppURI.getPath()); logger.warn(e, "Deleting VApp %s failed (%s)", vApp.getName(), vAppURI.getPath());
} }
} }