228228import com .cloud .template .VirtualMachineTemplate .BootloaderType ;
229229import com .cloud .utils .Pair ;
230230import com .cloud .utils .exception .CloudRuntimeException ;
231- import com .cloud .utils .script . Script ;
231+ import com .cloud .utils .net . NetUtils ;
232232import com .cloud .utils .script .OutputInterpreter .OneLineParser ;
233+ import com .cloud .utils .script .Script ;
233234import com .cloud .utils .ssh .SshHelper ;
234235import com .cloud .vm .DiskProfile ;
235236import com .cloud .vm .VirtualMachine ;
236237import com .cloud .vm .VirtualMachine .PowerState ;
237238import com .cloud .vm .VirtualMachine .Type ;
239+ import com .cloud .vm .VmDetailConstants ;
238240
239241@ RunWith (MockitoJUnitRunner .class )
240242public class LibvirtComputingResourceTest {
@@ -251,6 +253,19 @@ public class LibvirtComputingResourceTest {
251253 Connect connMock ;
252254 @ Mock
253255 LibvirtDomainXMLParser parserMock ;
256+ @ Mock
257+ private DiskDef diskDef ;
258+ @ Mock
259+ private DiskTO volume ;
260+ @ Mock
261+ private KVMPhysicalDisk physicalDisk ;
262+ @ Mock
263+ private Map <String , String > details ;
264+
265+ private static final String PHYSICAL_DISK_PATH = "/path/to/disk" ;
266+ private static final int DEV_ID = 1 ;
267+ private static final DiskDef .DiskBus DISK_BUS_TYPE = DiskDef .DiskBus .VIRTIO ;
268+ private static final DiskDef .DiskBus DISK_BUS_TYPE_DATA = DiskDef .DiskBus .SCSI ;
254269
255270 @ Mock
256271 DiskTO diskToMock ;
@@ -7145,4 +7160,49 @@ public void parseCpuFeaturesTestReturnListOfCpuFeaturesAndIgnoreMultipleWhitespa
71457160 Assert .assertEquals ("-mmx" , cpuFeatures .get (2 ));
71467161 Assert .assertEquals ("hle" , cpuFeatures .get (3 ));
71477162 }
7163+
7164+ @ Test
7165+ public void defineDiskForDefaultPoolTypeSkipsForceDiskController () {
7166+ Map <String , String > details = new HashMap <>();
7167+ details .put (VmDetailConstants .KVM_SKIP_FORCE_DISK_CONTROLLER , "true" );
7168+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7169+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7170+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7171+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7172+ }
7173+
7174+ @ Test
7175+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeDataForDataDiskWithoutWindowsAndUefi () {
7176+ Map <String , String > details = new HashMap <>();
7177+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7178+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7179+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7180+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7181+ }
7182+
7183+ @ Test
7184+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeForRootDisk () {
7185+ Map <String , String > details = new HashMap <>();
7186+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
7187+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7188+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7189+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE , DiskDef .DiskFmtType .QCOW2 );
7190+ }
7191+
7192+ @ Test
7193+ public void defineDiskForDefaultPoolTypeUsesSecureBootConfiguration () {
7194+ Map <String , String > details = new HashMap <>();
7195+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
7196+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7197+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , true , true , true , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7198+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DiskDef .DiskFmtType .QCOW2 , true );
7199+ }
7200+
7201+ @ Test
7202+ public void defineDiskForDefaultPoolTypeHandlesNullDetails () {
7203+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7204+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7205+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , null );
7206+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7207+ }
71487208}
0 commit comments