Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions infrastructure/devicepathresolver/mapped_device_path_resolver.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package devicepathresolver

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -58,17 +57,16 @@ func (dpr mappedDevicePathResolver) findPossibleDevice(devicePath string) (strin
needsMapping := strings.HasPrefix(devicePath, "/dev/sd")

if needsMapping { //nolint:nestif
pathLetterSuffix := strings.Split(devicePath, "/dev/sd")[1]
pathNumberSuffix := fmt.Sprintf("%d", pathLetterSuffix[0]-97) // a=0, b=1

possiblePaths := []string{
"/dev/xvd" + pathLetterSuffix, // Xen
"/dev/vd" + pathLetterSuffix, // KVM
"/dev/sd" + pathLetterSuffix,
"/dev/nvme" + pathNumberSuffix + "n1", // Nitro instances with Noble
pathSuffix := strings.Split(devicePath, "/dev/sd")[1]

possiblePrefixes := []string{
"/dev/xvd", // Xen
"/dev/vd", // KVM
"/dev/sd",
}

for _, path := range possiblePaths {
for _, prefix := range possiblePrefixes {
path := prefix + pathSuffix
if dpr.fs.FileExists(path) {
return path, true, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ var _ = Describe("mappedDevicePathResolver", func() {
})
})

Context("when a matching /dev/nvmeXn1 device is found", func() {
BeforeEach(func() {
err := fs.WriteFile("/dev/nvme0n1", []byte{})
Expect(err).NotTo(HaveOccurred())
})

It("returns the match", func() {
realPath, timedOut, err := resolver.GetRealDevicePath(diskSettings)
Expect(err).NotTo(HaveOccurred())
Expect(timedOut).To(BeFalse())
Expect(realPath).To(Equal("/dev/nvme0n1"))
})
})

Context("when no matching device is found the first time", func() {
Context("when the timeout has not expired", func() {
BeforeEach(func() {
Expand Down