Example #1
0
 public VirtualMachine(
     final String name,
     final Enterprise enterprise,
     final User user,
     final VirtualImage virtualImage,
     final UUID uuid,
     final Integer typeId) {
   setName(name);
   setEnterprise(enterprise);
   setUser(user);
   setVirtualImage(virtualImage);
   setUuid(uuid.toString());
   setIdType(typeId);
 }
Example #2
0
  @Test
  public void testDeleteMachineWithVirtualMachinesDeployed() {
    Hypervisor hypervisor = hypervisorGenerator.createUniqueInstance();
    Datacenter datacenter = hypervisor.getMachine().getDatacenter();
    VirtualDatacenter vdc = vdcGenerator.createInstance(datacenter);
    RemoteService rm =
        remoteServiceGenerator.createInstance(RemoteServiceType.VIRTUAL_SYSTEM_MONITOR, datacenter);

    VirtualImage image = virtualImageGenerator.createInstance(vdc.getEnterprise());
    VirtualAppliance vapp = virtualApplianceGenerator.createInstance(vdc);
    VirtualMachine vm =
        vmGenerator.createInstance(image, vdc.getEnterprise(), hypervisor, "vm_test");
    vm.setState(VirtualMachineState.RUNNING);
    vm.setIdType(VirtualMachine.MANAGED);

    NodeVirtualImage node = new NodeVirtualImage("node_test", vapp, image, vm);

    hypervisor.getMachine().setHypervisor(hypervisor);

    List<Object> entitiesToPersist = new ArrayList<Object>();
    entitiesToPersist.add(vdc.getEnterprise());
    entitiesToPersist.add(datacenter);
    entitiesToPersist.add(rm);
    entitiesToPersist.add(hypervisor.getMachine().getRack());
    entitiesToPersist.add(hypervisor.getMachine());
    entitiesToPersist.add(hypervisor);
    entitiesToPersist.add(vdc);
    entitiesToPersist.add(image);
    entitiesToPersist.add(vapp);
    for (Privilege p : vm.getUser().getRole().getPrivileges()) {
      entitiesToPersist.add(p);
    }
    entitiesToPersist.add(vm.getUser().getRole());
    entitiesToPersist.add(vm.getUser());
    entitiesToPersist.add(vm);
    entitiesToPersist.add(node);

    setup(entitiesToPersist.toArray());

    int machineId = hypervisor.getMachine().getId();

    EntityManager em = getEntityManager();
    EntityManagerHelper.beginReadWriteTransaction(em);

    MachineService service = new MachineService(em);
    service.setVsm(new VsmServiceStubMock()); // Must use the mocked VSM
    service.removeMachine(machineId);

    EntityManagerHelper.commit(em);

    EntityManagerHelper.beginRollbackTransaction(em);
    service = new MachineService(em);

    try {
      Machine m = service.getMachine(machineId);
    } catch (NotFoundException e) {
      org.testng.Assert.assertEquals(
          e.getErrors().iterator().next().getMessage(), "The requested machine does not exist");
    }

    VirtualMachineService vmService = new VirtualMachineService(em);

    VirtualMachine virtualMachine =
        vmService.getVirtualMachine(vdc.getId(), vapp.getId(), vm.getId());
    org.testng.Assert.assertNull(virtualMachine.getHypervisor());
    org.testng.Assert.assertNull(virtualMachine.getDatastore());
    org.testng.Assert.assertEquals(virtualMachine.getState(), VirtualMachineState.NOT_DEPLOYED);
  }