コード例 #1
0
  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);
  }
コード例 #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;
  }
コード例 #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);
  }
コード例 #4
0
 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;
     }
   }
 }
コード例 #5
0
 /** 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;
 }
コード例 #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();
  }
コード例 #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();
  }
コード例 #8
0
 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);
 }
コード例 #9
0
 private void mockNullVm() {
   mockGetForDisk((VM) null);
   mockGetVmsListForDisk(null);
   when(vmDao.get(command.getParameters().getVmId())).thenReturn(null);
 }
コード例 #10
0
 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());
 }
コード例 #11
0
 private void allQueriesForVms() {
   when(vmDao.getAllForCluster(any(Guid.class))).thenReturn(Collections.<VM>emptyList());
 }
コード例 #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);
 }
コード例 #13
0
 private void initializeVmDaoMock(VM vm) {
   when(vmDao.get(any(Guid.class))).thenReturn(vm);
 }