Examples of VirtualBoxManager


Examples of org.virtualbox_4_2.VirtualBoxManager

   private static final String VM_ID = "test";

   @Test
   public void testConvert() throws Exception {

      VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
      IStorageController iStorageController = createNiceMock(IStorageController.class);
      IMediumAttachment iMediumAttachment = createNiceMock(IMediumAttachment.class);
      IMedium hd = createNiceMock(IMedium.class);
      IMedium dvd = createNiceMock(IMedium.class);
      IMachine vm = createNiceMock(IMachine.class);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   public void testLaunchIfNotStarted() throws Exception {

      final String type = "gui";
      final String environment = "";
      ISession session = createMock(ISession.class);
      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IProgress progress = createMock(IProgress.class);

      expect(manager.getSessionObject()).andReturn(session).anyTimes();
      expect(machine.launchVMProcess(session, type, environment)).andReturn(progress);
      progress.waitForCompletion(-1);
      expect(session.getState()).andReturn(SessionState.Locked);
      session.unlockMachine();
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test
   public void testCreateMediumWhenDiskDoesNotExists() throws Exception {

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      StringBuilder errorBuilder = new StringBuilder();
      errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
      errorBuilder.append("Could not find file for the medium ");
      errorBuilder.append("'/Users/johndoe/jclouds-virtualbox-test/testadmin.vdi' (0x80BB0001)");
      String errorMessage = errorBuilder.toString();
      expect(manager.getVBox()).andReturn(vBox).anyTimes();

      VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException);
      expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
      expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test
   public void testDeleteAndCreateNewStorageWhenMediumExistsAndUsingOverwrite() throws Exception {
      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);

      expect(medium.deleteStorage()).andReturn(progress);
      expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk);
      expect(newHardDisk.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test(enabled = false)
   public void testDeleteAndCreateNewStorageWhenMediumExistsAndUsingOverwriteAndStillAttachedDetachesOldThing()
            throws Exception {
      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);

      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);

      String oldMachineId = "a1e03931-29f3-4370-ada3-9547b1009212";
      String oldMachineName = "oldMachine";
      IMachine oldMachine = createMock(IMachine.class);
      IMediumAttachment oldAttachment = createMock(IMediumAttachment.class);
      String oldAttachmentController = "oldAttachmentController";
      int oldAttachmentDevice = 1;
      int oldAttachmentPort = 2;
      IMedium oldMedium = createMock(IMedium.class);
      String oldMediumId = "oldMediumId";
      ISession detachSession = createNiceMock(ISession.class);

      StringBuilder errorBuilder = new StringBuilder();
      errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
      errorBuilder.append("Cannot delete storage: medium '/Users/adriancole/jclouds-virtualbox-test/testadmin.vdi ");
      errorBuilder.append("is still attached to the following 1 virtual machine(s): ");
      errorBuilder.append(oldMachineId + " (0x80BB000C)");
      String errorMessage = errorBuilder.toString();

      VBoxException stillAttached = new VBoxException(createNiceMock(Throwable.class), errorMessage);
      expect(medium.deleteStorage()).andThrow(stillAttached);

      expect(vBox.findMachine(oldMachineId)).andReturn(oldMachine);
      expect(oldMachine.getMediumAttachments()).andReturn(ImmutableList.of(oldAttachment));
      expect(oldAttachment.getMedium()).andReturn(oldMedium);
      expect(oldMedium.getId()).andReturn(oldMediumId);
      // in this case, they are the same medium, so safe to detach
      expect(medium.getId()).andReturn(oldMediumId);
      expect(oldMachine.getName()).andReturn(oldMachineName);
      expect(oldAttachment.getController()).andReturn(oldAttachmentController);
      expect(oldAttachment.getDevice()).andReturn(oldAttachmentDevice);
      expect(oldAttachment.getPort()).andReturn(oldAttachmentPort);
      // TODO: is this ok that we searched by ID last time?
      expect(vBox.findMachine(oldMachineName)).andReturn(oldMachine);
      expect(manager.getSessionObject()).andReturn(detachSession);
      oldMachine.lockMachine(detachSession, LockType.Write);
      expect(detachSession.getMachine()).andReturn(oldMachine);
      oldMachine.detachDevice(oldAttachmentController, oldAttachmentPort, oldAttachmentDevice);
      oldMachine.saveSettings();
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test(expectedExceptions = IllegalStateException.class)
   public void testFailWhenMediumExistsAndNotUsingOverwrite() throws Exception {
      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);

      replay(manager, machine, vBox, medium, newHardDisk, progress, machineUtils);

      new CreateMediumIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, false).apply(hardDisk);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test(expectedExceptions = VBoxException.class)
   public void testFailOnOtherVBoxException() throws Exception {

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      String errorMessage = "VirtualBox error: Some other VBox error";

      expect(manager.getVBox()).andReturn(vBox).anyTimes();

      VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException);
      expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
      expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   private String vmId = "jclouds-image-iso-unregister";
   private String osTypeId = "";

   @Test
   public void testUnregisterExistingMachine() throws Exception {
      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMachine registeredMachine = createMock(IMachine.class);
      IProgress progress = createNiceMock(IProgress.class);
      List<IMedium> media = Lists.newArrayList();
      List<IMedium> mediums = Collections.unmodifiableList(media);

      StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
            .attachISO(0, 0, "/tmp/ubuntu-11.04-server-i386.iso")
            .attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build())
            .attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build();
      VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
            .controller(ideController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.findMachine(vmName)).andReturn(registeredMachine);

      expect(registeredMachine.unregister(mode)).andReturn(mediums);
      expectLastCall().anyTimes();
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

public class StartVBoxIfNotAlreadyRunningLiveTest {

   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Test
   public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception {
      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      Factory runScriptOnNodeFactory = createMock(Factory.class);
      RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class);
      RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
      HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata = createMock(HardcodedHostToHostNodeMetadata.class);
      NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build();
      URI provider = URI.create("http://localhost:18083/");
      expect(client.seconds(3)).andReturn(client);
      expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes();
      manager.connect(provider.toASCIIString(), "", "");
      expectLastCall().anyTimes();
      replay(manager, runScriptOnNodeFactory, runScriptOnNode, client);
      new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client,
               Suppliers.ofInstance(host), Suppliers.ofInstance(provider), hardcodedHostToHostNodeMetadata).start();
      verify(manager, runScriptOnNodeFactory, client);
View Full Code Here

Examples of org.virtualbox_4_2.VirtualBoxManager

   @Test(enabled = false)
   public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {

      MachineUtils machineUtils = createMock(MachineUtils.class);
      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      String vmName = "jclouds-image-my-ubuntu-image";
      StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build();
      VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController)
            .cleanUpMode(CleanupMode.Full).build();
      MasterSpec machineSpec = MasterSpec.builder()
            .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()).vm(vmSpec)
            .network(NetworkSpec.builder().build()).build();
      IMachine createdMachine = createMock(IMachine.class);
      ISession session = createMock(ISession.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      String flags = "";
      List<String> groups = Lists.newArrayList();
      String group = "";
      expect(vBox.composeMachineFilename(vmName, group, flags, "/tmp/workingDir")).andReturn("settingsFile");

      StringBuilder errorMessageBuilder = new StringBuilder();
      errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
      errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
      String errorMessage = errorMessageBuilder.toString();
      VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);

      expect(vBox.findMachine(vmName)).andThrow(vBoxException);

      expect(vBox.createMachine(anyString(), eq(vmName), groups, anyString(), anyString())).andReturn(createdMachine)
            .anyTimes();
      vBox.registerMachine(createdMachine);

      expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
      expect(manager.getSessionObject()).andReturn(session);
      expect(session.getMachine()).andReturn(createdMachine);
      createdMachine.lockMachine(session, LockType.Write);
      createdMachine.setMemorySize(1024l);
      createdMachine.saveSettings();
      session.unlockMachine();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.