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 ());
@@ -6421,4 +6433,49 @@ public void testGetDiskModelFromVMDetailVirtioBlk() {
64216433 DiskDef .DiskBus diskBus = libvirtComputingResourceSpy .getDiskModelFromVMDetail (virtualMachineTO );
64226434 assertEquals (DiskDef .DiskBus .VIRTIOBLK , diskBus );
64236435 }
6436+
6437+ @ Test
6438+ public void defineDiskForDefaultPoolTypeSkipsForceDiskController () {
6439+ Map <String , String > details = new HashMap <>();
6440+ details .put (VmDetailConstants .KVM_SKIP_FORCE_DISK_CONTROLLER , "true" );
6441+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6442+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6443+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6444+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6445+ }
6446+
6447+ @ Test
6448+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeDataForDataDiskWithoutWindowsAndUefi () {
6449+ Map <String , String > details = new HashMap <>();
6450+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6451+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6452+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6453+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6454+ }
6455+
6456+ @ Test
6457+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeForRootDisk () {
6458+ Map <String , String > details = new HashMap <>();
6459+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
6460+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6461+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6462+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE , DiskDef .DiskFmtType .QCOW2 );
6463+ }
6464+
6465+ @ Test
6466+ public void defineDiskForDefaultPoolTypeUsesSecureBootConfiguration () {
6467+ Map <String , String > details = new HashMap <>();
6468+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
6469+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6470+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , true , true , true , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6471+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DiskDef .DiskFmtType .QCOW2 , true );
6472+ }
6473+
6474+ @ Test
6475+ public void defineDiskForDefaultPoolTypeHandlesNullDetails () {
6476+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6477+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6478+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , null );
6479+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6480+ }
64246481}
0 commit comments