Merge pull request #826 from elezar/fix-test
Some checks failed
CodeQL / Analyze Go code with CodeQL (push) Has been cancelled
Golang / check (push) Has been cancelled
Golang / Unit test (push) Has been cancelled
Golang / Build (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos7-aarch64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos7-x86_64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos8-ppc64le) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-amd64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-arm64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-ppc64le) (push) Has been cancelled
image / image (packaging, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled
image / image (ubi8, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled
image / image (ubuntu20.04, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled

Fix create-device-node test when devices exist
This commit is contained in:
Evan Lezar 2024-12-06 14:07:59 +01:00 committed by GitHub
commit aac0a62528
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 10 deletions

View File

@ -19,7 +19,6 @@ package nvdevices
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@ -66,7 +65,7 @@ func New(opts ...Option) (*Interface, error) {
if i.dryRun {
i.mknoder = &mknodLogger{i.logger}
} else {
i.mknoder = &mknodUnix{}
i.mknoder = &mknodUnix{i.logger}
}
return i, nil
}
@ -107,13 +106,6 @@ func (m *Interface) CreateNVIDIADevice(node string) error {
// If a devRoot is configured, this is prepended to the path.
func (m *Interface) createDeviceNode(path string, major int, minor int) error {
path = filepath.Join(m.devRoot, path)
if _, err := os.Stat(path); err == nil {
m.logger.Infof("Skipping: %s already exists", path)
return nil
} else if !os.IsNotExist(err) {
return fmt.Errorf("failed to stat %s: %v", path, err)
}
return m.Mknode(path, major, minor)
}

View File

@ -17,6 +17,9 @@
package nvdevices
import (
"fmt"
"os"
"golang.org/x/sys/unix"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@ -36,9 +39,19 @@ func (m *mknodLogger) Mknode(path string, major, minor int) error {
return nil
}
type mknodUnix struct{}
type mknodUnix struct {
logger logger.Interface
}
func (m *mknodUnix) Mknode(path string, major, minor int) error {
// TODO: Ensure that the existing device node has the correct properties.
if _, err := os.Stat(path); err == nil {
m.logger.Infof("Skipping: %s already exists", path)
return nil
} else if !os.IsNotExist(err) {
return fmt.Errorf("failed to stat %s: %v", path, err)
}
err := unix.Mknod(path, unix.S_IFCHR, int(unix.Mkdev(uint32(major), uint32(minor))))
if err != nil {
return err