6161import javax .xml .xpath .XPathExpressionException ;
6262import javax .xml .xpath .XPathFactory ;
6363
64- import com .cloud .cpu .CPU ;
65- import com .cloud .utils .net .NetUtils ;
66-
67- import com .cloud .vm .VmDetailConstants ;
6864import com .google .gson .JsonObject ;
6965import com .google .gson .JsonParser ;
66+
7067import org .apache .cloudstack .api .ApiConstants .IoDriverPolicy ;
7168import org .apache .cloudstack .storage .command .AttachAnswer ;
7269import org .apache .cloudstack .storage .command .AttachCommand ;
186183import com .cloud .agent .properties .AgentProperties ;
187184import com .cloud .agent .properties .AgentPropertiesFileHandler ;
188185import com .cloud .agent .resource .virtualnetwork .VirtualRoutingResource ;
186+ import com .cloud .cpu .CPU ;
189187import com .cloud .exception .InternalErrorException ;
190188import com .cloud .hypervisor .Hypervisor .HypervisorType ;
191189import com .cloud .hypervisor .kvm .resource .KVMHABase .HAStoragePool ;
228226import com .cloud .template .VirtualMachineTemplate .BootloaderType ;
229227import com .cloud .utils .Pair ;
230228import com .cloud .utils .exception .CloudRuntimeException ;
231- import com .cloud .utils .script . Script ;
229+ import com .cloud .utils .net . NetUtils ;
232230import com .cloud .utils .script .OutputInterpreter .OneLineParser ;
231+ import com .cloud .utils .script .Script ;
233232import com .cloud .utils .ssh .SshHelper ;
234233import com .cloud .vm .DiskProfile ;
235234import com .cloud .vm .VirtualMachine ;
236235import com .cloud .vm .VirtualMachine .PowerState ;
237236import com .cloud .vm .VirtualMachine .Type ;
237+ import com .cloud .vm .VmDetailConstants ;
238238
239239@ RunWith (MockitoJUnitRunner .class )
240240public class LibvirtComputingResourceTest {
@@ -251,6 +251,19 @@ public class LibvirtComputingResourceTest {
251251 Connect connMock ;
252252 @ Mock
253253 LibvirtDomainXMLParser parserMock ;
254+ @ Mock
255+ private DiskDef diskDef ;
256+ @ Mock
257+ private DiskTO volume ;
258+ @ Mock
259+ private KVMPhysicalDisk physicalDisk ;
260+ @ Mock
261+ private Map <String , String > details ;
262+
263+ private static final String PHYSICAL_DISK_PATH = "/path/to/disk" ;
264+ private static final int DEV_ID = 1 ;
265+ private static final DiskDef .DiskBus DISK_BUS_TYPE = DiskDef .DiskBus .VIRTIO ;
266+ private static final DiskDef .DiskBus DISK_BUS_TYPE_DATA = DiskDef .DiskBus .SCSI ;
254267
255268 @ Mock
256269 DiskTO diskToMock ;
@@ -7145,4 +7158,49 @@ public void parseCpuFeaturesTestReturnListOfCpuFeaturesAndIgnoreMultipleWhitespa
71457158 Assert .assertEquals ("-mmx" , cpuFeatures .get (2 ));
71467159 Assert .assertEquals ("hle" , cpuFeatures .get (3 ));
71477160 }
7161+
7162+ @ Test
7163+ public void defineDiskForDefaultPoolTypeSkipsForceDiskController () {
7164+ Map <String , String > details = new HashMap <>();
7165+ details .put (VmDetailConstants .KVM_SKIP_FORCE_DISK_CONTROLLER , "true" );
7166+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7167+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7168+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7169+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7170+ }
7171+
7172+ @ Test
7173+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeDataForDataDiskWithoutWindowsAndUefi () {
7174+ Map <String , String > details = new HashMap <>();
7175+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7176+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7177+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7178+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7179+ }
7180+
7181+ @ Test
7182+ public void defineDiskForDefaultPoolTypeUsesDiskBusTypeForRootDisk () {
7183+ Map <String , String > details = new HashMap <>();
7184+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
7185+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7186+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7187+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE , DiskDef .DiskFmtType .QCOW2 );
7188+ }
7189+
7190+ @ Test
7191+ public void defineDiskForDefaultPoolTypeUsesSecureBootConfiguration () {
7192+ Map <String , String > details = new HashMap <>();
7193+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .ROOT );
7194+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7195+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , true , true , true , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , details );
7196+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DiskDef .DiskFmtType .QCOW2 , true );
7197+ }
7198+
7199+ @ Test
7200+ public void defineDiskForDefaultPoolTypeHandlesNullDetails () {
7201+ Mockito .when (volume .getType ()).thenReturn (Volume .Type .DATADISK );
7202+ Mockito .when (physicalDisk .getPath ()).thenReturn (PHYSICAL_DISK_PATH );
7203+ libvirtComputingResourceSpy .defineDiskForDefaultPoolType (diskDef , volume , false , false , false , physicalDisk , DEV_ID , DISK_BUS_TYPE , DISK_BUS_TYPE_DATA , null );
7204+ Mockito .verify (diskDef ).defFileBasedDisk (PHYSICAL_DISK_PATH , DEV_ID , DISK_BUS_TYPE_DATA , DiskDef .DiskFmtType .QCOW2 );
7205+ }
71487206}
0 commit comments