@Test public void clearAddressOnInterfaceChange() { final UpdateVmDiskParameters parameters = createParameters(); // update new disk interface so it will be different than the old one parameters.getDiskInfo().setDiskInterface(DiskInterface.VirtIO_SCSI); // creating old disk with interface different than interface of disk from parameters // have to return original disk on each request to dao, // since the command updates retrieved instance of disk when(diskDao.get(diskImageGuid)) .thenAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { final DiskImage oldDisk = createDiskImage(); oldDisk.setDiskInterface(DiskInterface.VirtIO); assertNotSame( oldDisk.getDiskInterface(), parameters.getDiskInfo().getDiskInterface()); return oldDisk; } }); initializeCommand(parameters); mockVdsCommandSetVolumeDescription(); command.executeVmCommand(); // verify that device address was cleared exactly once verify(vmDeviceDao).clearDeviceAddress(diskImageGuid); }
@Test public void testDiskAliasAdnDescriptionMetaDataShouldNotBeUpdated() { // Disk should be updated as Read Only final UpdateVmDiskParameters parameters = createParameters(); when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage()); initializeCommand(parameters); mockVdsCommandSetVolumeDescription(); command.executeVmCommand(); }
@Test public void testDoNotUpdateDeviceWhenReadOnlyIsNotChanged() { final UpdateVmDiskParameters parameters = createParameters(); parameters.getDiskInfo().setReadOnly(false); when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage()); initializeCommand(parameters); mockVdsCommandSetVolumeDescription(); command.executeVmCommand(); verify(command, atLeast(1)).updateReadOnlyRequested(); assertFalse(command.updateReadOnlyRequested()); verify(vmDeviceDao, never()).update(any(VmDevice.class)); }
@Test public void testOnlyDiskAliasChangedMetaDataShouldBeUpdated() { // Disk should be updated as Read Only final UpdateVmDiskParameters parameters = createParameters(); when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage()); parameters.getDiskInfo().setDiskAlias("New Disk Alias"); initializeCommand(parameters); mockVdsCommandSetVolumeDescription(); command.executeVmCommand(); verify(command, times(1)) .runVdsCommand( eq(VDSCommandType.SetVolumeDescription), any(SetVolumeDescriptionVDSCommandParameters.class)); }
@Test public void testUpdateReadOnlyPropertyOnChange() { // Disk should be updated as Read Only final UpdateVmDiskParameters parameters = createParameters(); parameters.getDiskInfo().setReadOnly(true); when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage()); initializeCommand(parameters); stubVmDevice(diskImageGuid, vmId); mockVdsCommandSetVolumeDescription(); command.executeVmCommand(); verify(command, atLeast(1)).updateReadOnlyRequested(); assertTrue(command.updateReadOnlyRequested()); verify(vmDeviceDao).update(any(VmDevice.class)); }
@Test public void nullifiedSnapshotOnUpdateDiskToShareable() { UpdateVmDiskParameters parameters = createParameters(); DiskImage disk = createShareableDisk(VolumeFormat.RAW); parameters.setDiskInfo(disk); StorageDomain storage = addNewStorageDomainToDisk(disk, StorageType.NFS); parameters.setDiskInfo(disk); DiskImage oldDisk = createDiskImage(); oldDisk.setVmSnapshotId(Guid.newGuid()); when(diskDao.get(diskImageGuid)).thenReturn(oldDisk); when(storageDomainStaticDao.get(storage.getId())).thenReturn(storage.getStorageStaticData()); initializeCommand(parameters); mockVdsCommandSetVolumeDescription(); mockInterfaceList(); CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command); command.executeVmCommand(); assertTrue(oldDisk.getVmSnapshotId() == null); }