private LunDisk createISCSILunDisk( ScsiGenericIO sgio, boolean isUsingScsiReservation, DiskInterface diskInterface) { LunDisk disk = createISCSILunDisk(); disk.setSgio(sgio); disk.setUsingScsiReservation(isUsingScsiReservation); disk.setDiskInterface(diskInterface); return disk; }
@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); }
@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); }
@Test public void testLunDiskInvalid() { 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.emptyList(); doReturn(luns) .when(command) .executeGetDeviceList(any(Guid.class), any(StorageType.class), any(String.class)); CanDoActionTestUtils.runAndAssertCanDoActionFailure( command, EngineMessage.ACTION_TYPE_FAILED_DISK_LUN_INVALID); }
@Test public void testLunDiskWithSgioCanBeAdded() { LunDisk disk = createISCSILunDisk(); disk.setDiskInterface(DiskInterface.VirtIO_SCSI); disk.setSgio(ScsiGenericIO.UNFILTERED); AddDiskParameters parameters = createParameters(); parameters.setDiskInfo(disk); initializeCommand(Guid.newGuid(), parameters); VM vm = mockVm(); vm.setVdsGroupCompatibilityVersion(Version.v3_3); mockMaxPciSlots(); when(osRepository.getDiskInterfaces(any(Integer.class), any(Version.class))) .thenReturn(new ArrayList<>(Arrays.asList("VirtIO_SCSI"))); DiskValidator diskValidator = spyDiskValidator(disk); doReturn(true).when(diskValidator).isVirtioScsiControllerAttached(any(Guid.class)); mockInterfaceList(); CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command); }