issue 384: small fixes to UnregisterMachine to destroy all the media attached, removed lzma lib, add memory to CreateAndInstallVmLiveTest

This commit is contained in:
andreaturli 2011-12-18 19:14:12 +00:00
parent 4e834c146d
commit f3e8c617ec
3 changed files with 24 additions and 13 deletions

View File

@ -59,12 +59,6 @@
<artifactId>byon</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.jponge</groupId>
<artifactId>lzma-java</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>

View File

@ -20,18 +20,23 @@
package org.jclouds.virtualbox.functions.admin;
import com.google.common.base.Function;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import com.google.common.base.Function;
public class UnregisterMachineIfExists implements Function<String, Void> {
@ -49,9 +54,11 @@ public class UnregisterMachineIfExists implements Function<String, Void> {
@Override
public Void apply(@Nullable String vmName) {
List<IMedium> mediaToBeDeleted = null;
IMachine machine = null;
try {
IMachine machine = manager.getVBox().findMachine(vmName);
machine.unregister(mode);
machine = manager.getVBox().findMachine(vmName);
mediaToBeDeleted = machine.unregister(mode);
} catch (VBoxException e) {
ErrorCode errorCode = ErrorCode.valueOf(e);
switch (errorCode) {
@ -62,6 +69,16 @@ public class UnregisterMachineIfExists implements Function<String, Void> {
throw e;
}
}
/**
* deletion of all files is currently disabled on Windows/x64 to
prevent a crash
*/
try {
IProgress deletion = machine.delete(mediaToBeDeleted);
deletion.waitForCompletion(-1);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -90,7 +90,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi")
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId)
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
.controller(ideController)
.forceOverwrite(true)
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();