예제 #1
0
  @Test
  public void testIscsiLunDiskWithNoPortCantBeAdded() {
    LunDisk disk = createISCSILunDisk();
    AddDiskParameters parameters = createParameters();
    parameters.setDiskInfo(disk);
    initializeCommand(Guid.newGuid(), parameters);
    disk.getLun().getLunConnections().get(0).setPort(null);
    assertFalse(
        "checkIfLunDiskCanBeAdded() succeded for ISCSI lun which LUNs has storage_server_connection with a null port",
        command.checkIfLunDiskCanBeAdded(spyDiskValidator(disk)));
    assertTrue(
        "checkIfLunDiskCanBeAdded() failed but correct can do action hasn't been added to the return response",
        verifyCanDoActionMessagesContainMessage(
            EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS));

    clearCanDoActionMessages();

    disk.getLun().getLunConnections().get(0).setPort("");
    assertFalse(
        "checkIfLunDiskCanBeAdded() succeded for ISCSI lun which LUNs has storage_server_connection with a empty port",
        command.checkIfLunDiskCanBeAdded(spyDiskValidator(disk)));
    assertTrue(
        "checkIfLunDiskCanBeAdded() failed but correct can do action hasn't been added to the return response",
        verifyCanDoActionMessagesContainMessage(
            EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS));
  }
예제 #2
0
  @Test
  public void testGetLunDiskSucceeds() {
    VDS vds = mockVds();
    LunDisk disk = createISCSILunDisk();
    List<LUNs> luns = Collections.singletonList(disk.getLun());
    initializeCommand(Guid.newGuid());

    doReturn(luns)
        .when(command)
        .executeGetDeviceList(any(Guid.class), any(StorageType.class), any(String.class));
    assertEquals(disk.getLun(), command.getLunDisk(disk.getLun(), vds));
  }
예제 #3
0
 @Test
 public void testIscsiLunCanBeAdded() {
   LunDisk disk = createISCSILunDisk();
   AddDiskParameters parameters = createParameters();
   parameters.setDiskInfo(disk);
   initializeCommand(Guid.newGuid(), parameters);
   when(diskLunMapDao.getDiskIdByLunId(disk.getLun().getLUNId())).thenReturn(null);
   assertTrue(
       "checkIfLunDiskCanBeAdded() failed for valid iscsi lun",
       command.checkIfLunDiskCanBeAdded(spyDiskValidator(disk)));
 }
예제 #4
0
 @Test
 public void testUnknownTypeLunCantBeAdded() {
   LunDisk disk = createISCSILunDisk();
   AddDiskParameters parameters = createParameters();
   parameters.setDiskInfo(disk);
   initializeCommand(Guid.newGuid(), parameters);
   disk.getLun().setLunType(StorageType.UNKNOWN);
   assertFalse(
       "checkIfLunDiskCanBeAdded() succeded for LUN with UNKNOWN type",
       command.checkIfLunDiskCanBeAdded(spyDiskValidator(disk)));
   assertTrue(
       "checkIfLunDiskCanBeAdded() failed but correct can do action hasn't been added to the return response",
       verifyCanDoActionMessagesContainMessage(
           EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_HAS_NO_VALID_TYPE));
 }
예제 #5
0
  @Test
  public void testAddingPCILunExceedsSlotLimit() {
    mockInterfaceList();
    LunDisk disk = createISCSILunDisk();
    disk.setDiskInterface(DiskInterface.VirtIO);
    AddDiskParameters parameters = createParameters();
    parameters.setDiskInfo(disk);
    initializeCommand(Guid.newGuid(), parameters);
    when(diskLunMapDao.getDiskIdByLunId(disk.getLun().getLUNId())).thenReturn(null);
    VM vm = mockVm();
    mockMaxPciSlots();

    // use maximum slots for PCI. canDo expected to succeed.
    fillDiskMap(disk, vm, MAX_PCI_SLOTS - 2);
    CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command);

    vm.getDiskMap().put(Guid.newGuid(), disk);
    CanDoActionTestUtils.runAndAssertCanDoActionFailure(
        command, EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS);
  }
  public static void removeLunDisk(LunDisk lunDisk) {
    DbFacade.getInstance().getVmDeviceDao().remove(new VmDeviceId(lunDisk.getId(), null));
    LUNs lun = lunDisk.getLun();
    DbFacade.getInstance()
        .getDiskLunMapDao()
        .remove(new DiskLunMapId(lunDisk.getId(), lun.getLUNId()));
    DbFacade.getInstance().getBaseDiskDao().remove(lunDisk.getId());

    lun.setLunConnections(
        new ArrayList<>(
            DbFacade.getInstance().getStorageServerConnectionDao().getAllForLun(lun.getLUNId())));

    if (!lun.getLunConnections().isEmpty()) {
      StorageHelperDirector.getInstance()
          .getItem(lun.getLunConnections().get(0).getStorageType())
          .removeLun(lun);
    } else {
      // if there are no connections then the lun is fcp.
      StorageHelperDirector.getInstance().getItem(StorageType.FCP).removeLun(lun);
    }
  }
예제 #7
0
  @Test
  public void testLunDiskValid() {
    VDS vds = mockVds();
    LunDisk disk = createISCSILunDisk();
    disk.setDiskInterface(DiskInterface.VirtIO);

    AddDiskParameters parameters = createParameters();
    parameters.setDiskInfo(disk);
    parameters.setVdsId(vds.getId());
    initializeCommand(Guid.newGuid(), parameters);
    command.setVds(vds);

    mockVm();
    mockMaxPciSlots();
    mockInterfaceList();

    List<LUNs> luns = Collections.singletonList(disk.getLun());
    doReturn(luns)
        .when(command)
        .executeGetDeviceList(any(Guid.class), any(StorageType.class), (any(String.class)));
    CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command);
  }