mirror of https://github.com/apache/jclouds.git
TemplateClientLiveTest was not properly cleaning up the VMs and templates it created
This commit is contained in:
parent
da56c047a1
commit
1d60c0d819
|
@ -45,7 +45,8 @@ import static org.testng.Assert.*;
|
|||
public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
private static final String IMPORT_VHD_URL = "http://www.frontiertown.co.uk/jclouds/empty.vhd";
|
||||
private VirtualMachine vm;
|
||||
private VirtualMachine vmForCreation;
|
||||
private VirtualMachine vmForRegistration;
|
||||
private Template createdTemplate;
|
||||
private Template registeredTemplate;
|
||||
|
||||
|
@ -98,20 +99,20 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
// Create a VM and stop it
|
||||
Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
|
||||
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, templateId, client, jobComplete, virtualMachineRunning);
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vm.getId())) : vm;
|
||||
vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, templateId, client, jobComplete, virtualMachineRunning);
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())) : vmForCreation;
|
||||
|
||||
// Work out the VM's volume
|
||||
Set<Volume> volumes = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.virtualMachineId(vm.getId()));
|
||||
Set<Volume> volumes = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId()));
|
||||
assertEquals(volumes.size(), 1);
|
||||
Volume volume = Iterables.getOnlyElement(volumes);
|
||||
|
||||
// Create a template
|
||||
String tmplName = "jclouds-" + Integer.toHexString(new Random().nextInt());
|
||||
CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
|
||||
AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(tmplName).osTypeId(vm.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options);
|
||||
assert jobComplete.apply(response.getJobId()) : vm;
|
||||
createdTemplate = client.getTemplateClient().getTemplateInZone(response.getId(), vm.getZoneId());
|
||||
AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(tmplName).osTypeId(vmForCreation.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options);
|
||||
assert jobComplete.apply(response.getJobId()) : vmForCreation;
|
||||
createdTemplate = client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId());
|
||||
|
||||
// Assertions
|
||||
assertNotNull(createdTemplate);
|
||||
|
@ -174,25 +175,30 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assertTrue(new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(registeredTemplate));
|
||||
|
||||
// Create a VM that uses this template
|
||||
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, registeredTemplate.getId(), client, jobComplete, virtualMachineRunning);
|
||||
assertNotNull(vm);
|
||||
vmForRegistration = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, registeredTemplate.getId(), client, jobComplete, virtualMachineRunning);
|
||||
assertNotNull(vmForRegistration);
|
||||
}
|
||||
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (vm != null) {
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vm.getId())) : vm;
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())) : vm;
|
||||
assert virtualMachineDestroyed.apply(vm);
|
||||
if (vmForCreation != null) {
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())) : vmForCreation;
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vmForCreation.getId())) : vmForCreation;
|
||||
assert virtualMachineDestroyed.apply(vmForCreation);
|
||||
}
|
||||
if (vmForRegistration != null) {
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForRegistration.getId())) : vmForRegistration;
|
||||
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vmForRegistration.getId())) : vmForRegistration;
|
||||
assert virtualMachineDestroyed.apply(vmForRegistration);
|
||||
}
|
||||
if (createdTemplate != null) {
|
||||
AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(createdTemplate.getId());
|
||||
assertTrue(jobComplete.apply(deleteJob.getJobId()));
|
||||
client.getTemplateClient().deleteTemplate(createdTemplate.getId());
|
||||
}
|
||||
if (registeredTemplate != null) {
|
||||
client.getTemplateClient().deleteTemplate(registeredTemplate.getId());
|
||||
AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(registeredTemplate.getId());
|
||||
assertTrue(jobComplete.apply(deleteJob.getJobId()));
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue