5656import javax .xml .xpath .XPathExpressionException ;
5757import javax .xml .xpath .XPathFactory ;
5858
59- import com .cloud .utils .net .NetUtils ;
60-
61- import com .cloud .vm .VmDetailConstants ;
6259import org .apache .cloudstack .api .ApiConstants .IoDriverPolicy ;
6360import org .apache .cloudstack .storage .command .AttachAnswer ;
6461import org .apache .cloudstack .storage .command .AttachCommand ;
217214import com .cloud .template .VirtualMachineTemplate .BootloaderType ;
218215import com .cloud .utils .Pair ;
219216import com .cloud .utils .exception .CloudRuntimeException ;
220- import com .cloud .utils .script . Script ;
217+ import com .cloud .utils .net . NetUtils ;
221218import com .cloud .utils .script .OutputInterpreter .OneLineParser ;
219+ import com .cloud .utils .script .Script ;
222220import com .cloud .utils .ssh .SshHelper ;
223221import com .cloud .vm .DiskProfile ;
224222import com .cloud .vm .VirtualMachine ;
225223import com .cloud .vm .VirtualMachine .PowerState ;
226224import com .cloud .vm .VirtualMachine .Type ;
225+ import com .cloud .vm .VmDetailConstants ;
227226
228227@ RunWith (MockitoJUnitRunner .class )
229228public class LibvirtComputingResourceTest {
@@ -240,6 +239,19 @@ public class LibvirtComputingResourceTest {
240239 Connect connMock ;
241240 @ Mock
242241 LibvirtDomainXMLParser parserMock ;
242+ @ Mock
243+ private DiskDef diskDef ;
244+ @ Mock
245+ private DiskTO volume ;
246+ @ Mock
247+ private KVMPhysicalDisk physicalDisk ;
248+ @ Mock
249+ private Map <String , String > details ;
250+
251+ private static final String PHYSICAL_DISK_PATH = "/path/to/disk" ;
252+ private static final int DEV_ID = 1 ;
253+ private static final DiskDef .DiskBus DISK_BUS_TYPE = DiskDef .DiskBus .VIRTIO ;
254+ private static final DiskDef .DiskBus DISK_BUS_TYPE_DATA = DiskDef .DiskBus .SCSI ;
243255
244256 @ Spy
245257 private LibvirtComputingResource libvirtComputingResourceSpy = Mockito .spy (new LibvirtComputingResource ());
@@ -6408,4 +6420,68 @@ public void createLinstorVdb() throws LibvirtException, InternalErrorException,
64086420 assertEquals (DiskDef .DiscardType .UNMAP , rootDisk .getDiscard ());
64096421 }
64106422 }
6423+
6424+ @ Test
6425+ public void testDefineDiskForDefaultPoolType_DataDiskNonWinSkipForceController () {
6426+ when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6427+ when (details .get (VmDetailConstants .KVM_WIN_SKIP_FORCE_DISK_CONTROLLER )).thenReturn ("true" );
6428+ when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6429+ boolean isWindowsTemplate = false ;
6430+ boolean isUefiEnabled = false ;
6431+ boolean isSecureBoot = false ;
6432+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
6433+ physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6434+ verify (diskDef , times (1 )).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6435+ }
6436+
6437+ @ Test
6438+ public void testDefineDiskForDefaultPoolType_DataDiskWinSecuredSkipForceController () {
6439+ when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6440+ when (details .get (VmDetailConstants .KVM_WIN_SKIP_FORCE_DISK_CONTROLLER )).thenReturn ("true" );
6441+ when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6442+ boolean isWindowsTemplate = true ;
6443+ boolean isUefiEnabled = true ;
6444+ boolean isSecureBoot = true ;
6445+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
6446+ physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6447+ verify (diskDef , times (1 )).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6448+ }
6449+
6450+ @ Test
6451+ public void testDefineDiskForDefaultPoolType_WinSecureBootEnabledForced () {
6452+ when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6453+ when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6454+ boolean isWindowsTemplate = true ;
6455+ boolean isUefiEnabled = true ;
6456+ boolean isSecureBoot = true ;
6457+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
6458+ physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6459+ verify (diskDef , times (1 )).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DiskDef .DiskFmtType .QCOW2 , isWindowsTemplate );
6460+ }
6461+
6462+ @ Test
6463+ public void testDefineDiskForDefaultPoolType_SecureBootDisabledForced () {
6464+ when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6465+ when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6466+ boolean isWindowsTemplate = true ;
6467+ boolean isUefiEnabled = false ;
6468+ boolean isSecureBoot = false ;
6469+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
6470+ physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6471+ verify (diskDef , times (1 )).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6472+ }
6473+
6474+ @ Test
6475+ public void testDefineDiskForDefaultPoolType_NotDataDisk () {
6476+ when (volume .getType ()).thenReturn (Volume .Type .ROOT );
6477+ when (details .get (VmDetailConstants .KVM_WIN_SKIP_FORCE_DISK_CONTROLLER )).thenReturn ("false" );
6478+ when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6479+ boolean isWindowsTemplate = false ;
6480+ boolean isUefiEnabled = false ;
6481+ boolean isSecureBoot = false ;
6482+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , isWindowsTemplate , isUefiEnabled , isSecureBoot ,
6483+ physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6484+ verify (diskDef , never ()).defFileBasedDisk (PHYSICAL_DISK_PATH , PHYSICAL_DISK_PATH , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6485+ verify (diskDef , times (1 )).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE , DiskDef .DiskFmtType .QCOW2 );
6486+ }
64116487}
0 commit comments