Skip to content

Commit 230e536

Browse files
committed
Bus type auto-detection of the VMware importer does not work correct
Related to: harvester/harvester#7987 Signed-off-by: Volker Theile <[email protected]>
1 parent 5288366 commit 230e536

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

pkg/source/vmware/client.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,34 @@ func mapNetworkCards(networkCards []networkInfo, mapping []migration.NetworkMapp
492492
return retNetwork
493493
}
494494

495-
// adapterType tries to identify the disk bus type from vmware
496-
// to attempt and set correct bus types in kubevirt
495+
// adapterType tries to identify the disk bus type from VMware to attempt and
496+
// set correct bus types in kubevirt.
497+
// Examples:
498+
// .-----------------------------------------------.
499+
// | Bus | Device ID |
500+
// |------|----------------------------------------|
501+
// | SCSI | /vm-13010/ParaVirtualSCSIController0:0 |
502+
// | SATA | /vm-13767/VirtualAHCIController0:1 |
503+
// | IDE | /vm-5678/VirtualIDEController1:0 |
504+
// | NVMe | /vm-2468/VirtualNVMEController0:0 |
505+
// | USB | /vm-54321/VirtualUSBController0:0 |
506+
// '-----------------------------------------------'
497507
// default is to switch to SATA to ensure device boots
498508
func adapterType(deviceID string) kubevirt.DiskBus {
499-
if strings.Contains(deviceID, "SCSI") {
509+
deviceID = strings.ToLower(deviceID)
510+
// https://kubevirt.io/api-reference/v1.1.0/definitions.html#_v1_disktarget
511+
switch {
512+
case strings.Contains(deviceID, "scsi"):
500513
return kubevirt.DiskBusSCSI
514+
case strings.Contains(deviceID, "ahci"), strings.Contains(deviceID, "sata"):
515+
return kubevirt.DiskBusSATA
516+
case strings.Contains(deviceID, "nvme"):
517+
return kubevirt.DiskBusVirtio
518+
case strings.Contains(deviceID, "usb"):
519+
return kubevirt.DiskBusUSB
520+
default:
521+
return kubevirt.DiskBusVirtio
501522
}
502-
return kubevirt.DiskBusSATA
503523
}
504524

505525
// SanitizeVirtualMachineImport is used to sanitize the VirtualMachineImport object.

pkg/source/vmware/client_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/vmware/govmomi/vim25/mo"
1414
corev1 "k8s.io/api/core/v1"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
kubevirt "kubevirt.io/api/core/v1"
1617

1718
migration "github.com/harvester/vm-import-controller/pkg/apis/migration.harvesterhci.io/v1beta1"
1819
"github.com/harvester/vm-import-controller/pkg/server"
@@ -304,3 +305,48 @@ func Test_identifyNetworkCards(t *testing.T) {
304305
noMappedInfo := mapNetworkCards(networkInfo, noNetworkMapping)
305306
assert.Len(noMappedInfo, 0, "expected to find no item in the mapped networkinfo")
306307
}
308+
309+
func Test_adapterType(t *testing.T) {
310+
assert := require.New(t)
311+
testCases := []struct {
312+
desc string
313+
deviceID string
314+
expected kubevirt.DiskBus
315+
}{
316+
{
317+
desc: "SCSI disk",
318+
deviceID: "/vm-13010/ParaVirtualSCSIController0:0",
319+
expected: kubevirt.DiskBusSCSI,
320+
},
321+
{
322+
desc: "NVMe disk",
323+
deviceID: "/vm-2468/VirtualNVMEController0:0",
324+
expected: kubevirt.DiskBusVirtio,
325+
},
326+
{
327+
desc: "USB disk",
328+
deviceID: "/vm-54321/VirtualUSBController0:0",
329+
expected: kubevirt.DiskBusUSB,
330+
},
331+
{
332+
desc: "SATA disk",
333+
deviceID: "/vm-13767/VirtualAHCIController0:1",
334+
expected: kubevirt.DiskBusSATA,
335+
},
336+
{
337+
desc: "IDE disk",
338+
deviceID: "/vm-5678/VirtualIDEController1:0",
339+
expected: kubevirt.DiskBusVirtio,
340+
},
341+
{
342+
desc: "Unknown disk",
343+
deviceID: "foo",
344+
expected: kubevirt.DiskBusVirtio,
345+
},
346+
}
347+
348+
for _, tc := range testCases {
349+
busType := adapterType(tc.deviceID)
350+
assert.Equal(tc.expected, busType)
351+
}
352+
}

0 commit comments

Comments
 (0)