gpu: add log messages for not found cards

Let a user know the plugin can't find any Intel GPU if that's
the case. It might be cumbersome to realize that the plugin runs
on a host which doesn't have any Intel GPUs.

Also make the code less nested for better readability.
This commit is contained in:
Dmitry Rozhkov 2019-05-24 11:08:06 +03:00
parent b504c6b30e
commit 44ff734be6
2 changed files with 60 additions and 40 deletions

View File

@ -85,15 +85,23 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
devTree := dpapi.NewDeviceTree()
for _, f := range files {
if dp.gpuDeviceReg.MatchString(f.Name()) {
var nodes []pluginapi.DeviceSpec
if !dp.gpuDeviceReg.MatchString(f.Name()) {
debug.Print("Not compatible device", f.Name())
continue
}
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
if err != nil {
fmt.Println("WARNING: Skipping. Can't read vendor file: ", err)
continue
}
if strings.TrimSpace(string(dat)) == vendorString {
var nodes []pluginapi.DeviceSpec
if strings.TrimSpace(string(dat)) != vendorString {
debug.Print("Non-Intel GPU", f.Name())
continue
}
drmFiles, err := ioutil.ReadDir(path.Join(dp.sysfsDir, f.Name(), "device/drm"))
if err != nil {
@ -130,8 +138,6 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
}
}
}
}
}
return devTree, nil
}

View File

@ -79,6 +79,20 @@ func TestScan(t *testing.T) {
expectedDevs: 1,
expectedErr: false,
},
{
sysfsdirs: []string{"card0/device/drm/card0"},
sysfsfiles: map[string][]byte{
"card0/device/vendor": []byte("0xbeef"),
},
devfsdirs: []string{"card0"},
expectedDevs: 0,
expectedErr: false,
},
{
sysfsdirs: []string{"non_gpu_card"},
expectedDevs: 0,
expectedErr: false,
},
}
testPlugin := newDevicePlugin(sysfs, devfs, 1)