Skip to content

Commit

Permalink
domainmgr: config.enable.usb for new usb type
Browse files Browse the repository at this point in the history
instead of IoUSB, now IoUSBController is used for the PCI controller

this means that if the model is created with a newer spec.sh,
config.enable.usb would not work

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
  • Loading branch information
christoph-zededa authored and eriknordmark committed Aug 7, 2024
1 parent b283541 commit 43adcc2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/pillar/cmd/domainmgr/domainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3117,7 +3117,7 @@ func updatePortAndPciBackIoBundle(ctx *domainContext, ib *types.IoBundle) (chang
// is assigned to an application, EVE will not be able to manage the state of the wireless device.
keepInHost = true
}
if ctx.usbAccess && ib.Type == types.IoUSB {
if ctx.usbAccess && (ib.Type == types.IoUSB || ib.Type == types.IoUSBController) {
keepInHost = true
}
if ctx.vgaAccess && ib.Type == types.IoHDMI {
Expand Down
79 changes: 79 additions & 0 deletions pkg/pillar/cmd/domainmgr/domainmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@ import (
"strings"
"testing"

"github.com/lf-edge/eve/pkg/pillar/agentlog"
"github.com/lf-edge/eve/pkg/pillar/base"
"github.com/lf-edge/eve/pkg/pillar/hypervisor"
"github.com/lf-edge/eve/pkg/pillar/types"
"github.com/lf-edge/eve/pkg/pillar/utils/cloudconfig"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func init() {
if logger == nil || log == nil {
logger, log = agentlog.Init(agentName)
}

if hyper == nil {
var err error
hyper, err = hypervisor.GetHypervisor("null")
if err != nil {
panic(err)
}
}
}

func TestFetchEnvVariablesFromCloudInit(t *testing.T) {
log = base.NewSourceLogObject(logrus.StandardLogger(), "domainmgr", 0)
type fetchEnvVar struct {
Expand Down Expand Up @@ -573,3 +589,66 @@ func TestUsbControllersNoImmediatePCIReserve(t *testing.T) {
t.Fatalf("expected all three controllers to be reserved for usb device, but got %+v", pciLongs)
}
}

func TestConfigEnableUsbUpdatePortAndPciBackIoBundle(t *testing.T) {
assignableAdapters := types.AssignableAdapters{
IoBundleList: []types.IoBundle{
{
Phylabel: "IoUSB",
Type: types.IoUSB,
KeepInHost: false,
AssignmentGroup: "1",
PciLong: "00:01",
},
{
Phylabel: "IoUSBController",
Type: types.IoUSBController,
KeepInHost: false,
AssignmentGroup: "1",
PciLong: "00:01",
},
{
Phylabel: "IoUSBDevice",
Type: types.IoUSBDevice,
KeepInHost: false,
AssignmentGroup: "2",
ParentAssignmentGroup: "3",
},
},
}
ctx := &domainContext{
assignableAdapters: &assignableAdapters,
usbAccess: true,
}
ib := &types.IoBundle{
AssignmentGroup: "1",
}

updatePortAndPciBackIoBundle(ctx, ib)

for _, ib := range ctx.assignableAdapters.IoBundleList {
if (ib.Phylabel == "IoUSB" || ib.Phylabel == "IoUSBController") && !ib.KeepInHost {
t.Fatalf("IoBundle %+v should be kept in host", ib)
}
if ib.Phylabel == "IoUSBDevice" && ib.KeepInHost {
t.Fatalf("IoBundle %+v should not be kept in host", ib)
}
}

for i := range ctx.assignableAdapters.IoBundleList {
ctx.assignableAdapters.IoBundleList[i].KeepInHost = false
}
ib.KeepInHost = false

ctx.usbAccess = false
updatePortAndPciBackIoBundle(ctx, ib)

for _, ib := range ctx.assignableAdapters.IoBundleList {
if (ib.Phylabel == "IoUSB" || ib.Phylabel == "IoUSBController") && ib.KeepInHost {
t.Fatalf("IoBundle %+v should be not kept in host", ib)
}
if ib.Phylabel == "IoUSBDevice" && ib.KeepInHost {
t.Fatalf("IoBundle %+v should not be kept in host", ib)
}
}
}

0 comments on commit 43adcc2

Please sign in to comment.