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 ());
@@ -6565,4 +6577,49 @@ public void testCreateTpmDefWithInvalidVersion() {
65656577 assertEquals (LibvirtVMDef .TpmDef .TpmModel .CRB , tpmDef .getModel ());
65666578 assertEquals (LibvirtVMDef .TpmDef .TpmVersion .V2_0 , tpmDef .getVersion ());
65676579 }
6580+
6581+ @ Test
6582+ public void defineDiskForDefaultPoolTypeSkipsForceDiskController () {
6583+ Map <String , String > details = new HashMap <>();
6584+ details .put (VmDetailConstants .KVM_SKIP_FORCE_DISK_CONTROLLER , "true" );
6585+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6586+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6587+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6588+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6589+ }
6590+
6591+ @ Test
6592+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeDataForDataDiskWithoutWindowsAndUefi () {
6593+ Map <String , String > details = new HashMap <>();
6594+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6595+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6596+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6597+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6598+ }
6599+
6600+ @ Test
6601+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeForRootDisk () {
6602+ Map <String , String > details = new HashMap <>();
6603+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
6604+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6605+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6606+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE , DiskDef .DiskFmtType .QCOW2 );
6607+ }
6608+
6609+ @ Test
6610+ public void defineDiskForDefaultPoolTypeUsesSecureBootConfiguration () {
6611+ Map <String , String > details = new HashMap <>();
6612+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
6613+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6614+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , true , true , true , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
6615+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DiskDef .DiskFmtType .QCOW2 , true );
6616+ }
6617+
6618+ @ Test
6619+ public void defineDiskForDefaultPoolTypeHandlesNullDetails () {
6620+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
6621+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
6622+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , null );
6623+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
6624+ }
65686625}
0 commit comments