コード例 #1
0
  @Test(dependsOnMethods = "testStartAndValidateVirtualMachines")
  public void testStopVirtualMachines() {
    for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
      String instanceName = vmName + "_" + i;
      IMachine machine = manager.getVBox().findMachine(instanceName);

      try {
        ISession machineSession = manager.openMachineSession(machine);
        IProgress progress = machineSession.getConsole().powerDown();
        progress.waitForCompletion(-1);
        machineSession.unlockMachine();

        while (!machine.getSessionState().equals(SessionState.Unlocked)) {
          try {
            System.out.println(
                "waiting for unlocking session - session state: " + machine.getSessionState());
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        assertEquals(machine.getState(), MachineState.PoweredOff);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
  private void createAndLaunchVirtualMachine(int i) throws InterruptedException {
    String instanceName = vmName + "_" + i;
    IMachine adminNode = manager.getVBox().findMachine(adminNodeName);

    IMachine clonedVM =
        manager.getVBox().createMachine(settingsFile, instanceName, osTypeId, vmId, forceOverwrite);
    List<CloneOptions> options = new ArrayList<CloneOptions>();
    options.add(CloneOptions.Link);
    IProgress progress =
        adminNode
            .getCurrentSnapshot()
            .getMachine()
            .cloneTo(clonedVM, CloneMode.MachineState, options);
    if (progress.getCompleted()) logger().debug("clone done");

    manager.getVBox().registerMachine(clonedVM);

    System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
    launchVMProcess(clonedVM, manager.getSessionObject());
    String ipAddress = null;
    while (ipAddress == null || ipAddress.equals("")) {
      try {
        ipAddress = clonedVM.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP");
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    System.out.println(ipAddress + " is the IP address of " + clonedVM.getName());

    // TODO
    // IPSocket socket = new IPSocket(ipAddress, 22);
    // checkSSH(IPSocket socket)

  }
コード例 #3
0
 private void launchVMProcess(IMachine machine, ISession session) {
   IProgress prog = machine.launchVMProcess(session, "gui", "");
   prog.waitForCompletion(-1);
   session.unlockMachine();
 }