private void mockGetVmsListForDisk(List<VM> vms) {
    List<Pair<VM, VmDevice>> vmsWithVmDevice = new ArrayList<>();
    if (vms != null) {
      for (VM vm : vms) {
        VmDevice device = createVmDevice(diskImageGuid, vm.getId());
        vmsWithVmDevice.add(new Pair<>(vm, device));
      }
    } else {
      vms = Collections.emptyList();
    }

    when(vmDao.getVmsWithPlugInfo(diskImageGuid)).thenReturn(vmsWithVmDevice);
    when(vmDao.getVmsListForDisk(diskImageGuid, true)).thenReturn(vms);
  }
Exemplo n.º 2
0
  /** Mock a VM. */
  private VM mockVm() {
    VM vm = new VM();
    vm.setStatus(VMStatus.Down);
    vm.setStoragePoolId(Guid.newGuid());
    when(vmDao.get(command.getParameters().getVmId())).thenReturn(vm);

    return vm;
  }
Exemplo n.º 3
0
  private void clusterHasVMs() {
    VM vm = new VM();
    vm.setClusterId(DEFAULT_CLUSTER_ID);
    List<VM> vmList = new ArrayList<>();
    vmList.add(vm);

    when(vmDao.getAllForCluster(any(Guid.class))).thenReturn(vmList);
  }
 private void mockToUpdateDiskVm(List<VM> vms) {
   for (VM vm : vms) {
     if (vm.getId().equals(command.getParameters().getVmId())) {
       when(vmDao.get(command.getParameters().getVmId())).thenReturn(vm);
       break;
     }
   }
 }
 /** Mock a VM in status Up */
 protected VM mockVmStatusUp() {
   vm.setStatus(VMStatus.Up);
   vm.setVmOs(8);
   vm.setId(vmId);
   vm.setRunOnVds(Guid.newGuid());
   when(vmDao.get(command.getParameters().getVmId())).thenReturn(vm);
   return vm;
 }
Exemplo n.º 6
0
  @Before
  public void setUp() {
    vmId = Guid.newGuid();
    diskId = Guid.newGuid();
    poolId = Guid.newGuid();
    storageDomainId = Guid.newGuid();
    groupId = Guid.newGuid();
    vdsId = Guid.newGuid();

    disk = new DiskImage();
    disk.setId(diskId);
    disk.setVmEntityType(VmEntityType.VM);
    disk.setImageStatus(ImageStatus.OK);
    disk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));

    vm = new VM();
    vm.setId(vmId);
    vm.setStatus(VMStatus.Down);
    vm.setStoragePoolId(poolId);
    vm.setClusterId(groupId);

    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);

    cluster = new Cluster();
    cluster.setId(groupId);

    vds = new VDS();
    vds.setId(vdsId);

    storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);

    storageDomain = new StorageDomain();
    storageDomain.setStorageType(StorageType.ISCSI);

    when(vmDao.getVmsListForDisk(diskId, Boolean.FALSE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);
    when(vdsDao.getAllForClusterWithStatus(groupId, VDSStatus.Up))
        .thenReturn(Collections.singletonList(vds));
    when(spDao.get(poolId)).thenReturn(storagePool);
    when(clusterDao.get(groupId)).thenReturn(cluster);
    when(storageDomainStaticDao.get(storageDomainId))
        .thenReturn(storageDomain.getStorageStaticData());

    cmd = spy(new GetDiskAlignmentCommand<>(new GetDiskAlignmentParameters(diskId), null));

    doReturn(disk).when(cmd).getDisk();
    doReturn(vdsDao).when(cmd).getVdsDao();
    doReturn(vmDao).when(cmd).getVmDao();
    doReturn(spDao).when(cmd).getStoragePoolDao();
    doReturn(clusterDao).when(cmd).getClusterDao();
    doReturn(storageDomainStaticDao).when(cmd).getStorageDomainStaticDao();
  }
Exemplo n.º 7
0
  @Before
  public void setUp() {
    disk = new DiskImage();
    setupDisk();

    Guid vmId = Guid.newGuid();
    vm = new VM();
    vm.setId(vmId);

    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);
    vmDevice.setIsPlugged(true);

    when(vmDao.getVmsListForDisk(diskId, Boolean.TRUE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);

    doReturn(disk).when(cmd).getDisk();
  }
 private void mockGetForDisk(List<VM> vms) {
   Map<Boolean, List<VM>> vmsMap = new HashMap<>();
   vmsMap.put(Boolean.TRUE, vms);
   when(vmDao.getForDisk(diskImageGuid, true)).thenReturn(vmsMap);
 }
 private void mockNullVm() {
   mockGetForDisk((VM) null);
   mockGetVmsListForDisk(null);
   when(vmDao.get(command.getParameters().getVmId())).thenReturn(null);
 }
 private void mockDaos(boolean pluggedInterface) {
   VM vm = createVM(VM_NAME, NETWORK_NAME, pluggedInterface);
   when(vmDao.getAllRunningForVds(any(Guid.class))).thenReturn(Arrays.asList(vm));
   when(vmNetworkInterfaceDao.getAllForVm(vm.getId())).thenReturn(vm.getInterfaces());
 }
Exemplo n.º 11
0
 private void allQueriesForVms() {
   when(vmDao.getAllForCluster(any(Guid.class))).thenReturn(Collections.<VM>emptyList());
 }
Exemplo n.º 12
0
 @Test
 public void testValidateFloatingDisk() {
   when(vmDao.getVmsListForDisk(diskId, Boolean.FALSE)).thenReturn(Collections.<VM>emptyList());
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_DISK_IS_NOT_VM_DISK);
 }
Exemplo n.º 13
0
 private void initializeVmDaoMock(VM vm) {
   when(vmDao.get(any(Guid.class))).thenReturn(vm);
 }