Skip to content

Commit

Permalink
Revert "hypervisor: move determining hypervisor"
Browse files Browse the repository at this point in the history
This reverts commit 8b1f5ba.

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa committed Nov 7, 2023
1 parent 1f73b43 commit c7c98de
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 56 deletions.
76 changes: 45 additions & 31 deletions pkg/pillar/cmd/domainmgr/domainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,20 @@ func (ctx *domainContext) publishAssignableAdapters() {
ctx.pubAssignableAdapters.Publish("global", *ctx.assignableAdapters)
}

var currentHypervisor hypervisor.Hypervisor
var currentHypervisorMutex sync.Mutex
var logger *logrus.Logger
var log *base.LogObject

// CurrentHypervisor returns the current hypervisor
func CurrentHypervisor() hypervisor.Hypervisor {
currentHypervisorMutex.Lock()
hv := currentHypervisor
currentHypervisorMutex.Unlock()

return hv

Check warning on line 150 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L145-L150

Added lines #L145 - L150 were not covered by tests
}

func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, arguments []string) int {
logger = loggerArg
log = logArg
Expand Down Expand Up @@ -168,14 +179,17 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
fmt.Printf("%s: %s\n", agentName, Version)
return 0
}
currentHypervisorMutex.Lock()
currentHypervisor, err = hypervisor.GetHypervisor(*domainCtx.hypervisorPtr)
currentHypervisorMutex.Unlock()

Check warning on line 184 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L182-L184

Added lines #L182 - L184 were not covered by tests
if err != nil {
log.Fatal(err)
}

if err := pidfile.CheckAndCreatePidfile(log, agentName); err != nil {
log.Fatal(err)
}
log.Functionf("Starting %s with %s hypervisor backend", agentName, hypervisor.CurrentHypervisor().Name())
log.Functionf("Starting %s with %s hypervisor backend", agentName, CurrentHypervisor().Name())

Check warning on line 192 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L192

Added line #L192 was not covered by tests

// Run a periodic timer so we always update StillRunning
stillRunning := time.NewTicker(25 * time.Second)
Expand Down Expand Up @@ -472,15 +486,15 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar

capabilitiesSent := false
capabilitiesTicker := time.NewTicker(5 * time.Second)
if err := getAndPublishCapabilities(&domainCtx, hypervisor.CurrentHypervisor()); err != nil {
if err := getAndPublishCapabilities(&domainCtx, CurrentHypervisor()); err != nil {

Check warning on line 489 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L489

Added line #L489 was not covered by tests
log.Warnf("getAndPublishCapabilities: %v", err)
} else {
capabilitiesSent = true
capabilitiesTicker.Stop()
}

log.Functionf("Creating %s at %s", "metricsTimerTask", agentlog.GetMyStack())
go metricsTimerTask(&domainCtx, hypervisor.CurrentHypervisor())
go metricsTimerTask(&domainCtx, CurrentHypervisor())

Check warning on line 497 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L497

Added line #L497 was not covered by tests

// Before starting to process DomainConfig, domainmgr should (in this order):
// 1. wait for NIM to publish DNS to learn which ports are used for management
Expand Down Expand Up @@ -516,7 +530,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
publishProcessesHandler(&domainCtx)

case <-capabilitiesTicker.C:
if err := getAndPublishCapabilities(&domainCtx, hypervisor.CurrentHypervisor()); err != nil {
if err := getAndPublishCapabilities(&domainCtx, CurrentHypervisor()); err != nil {

Check warning on line 533 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L533

Added line #L533 was not covered by tests
log.Warnf("getAndPublishCapabilities: %v", err)
} else {
capabilitiesSent = true
Expand All @@ -542,7 +556,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
var resources types.HostMemory
for i := 0; true; i++ {
delay := 10
resources, err = hypervisor.CurrentHypervisor().GetHostCPUMem()
resources, err = CurrentHypervisor().GetHostCPUMem()

Check warning on line 559 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L559

Added line #L559 was not covered by tests
if err == nil {
break
}
Expand Down Expand Up @@ -930,7 +944,7 @@ func verifyStatus(ctx *domainContext, status *types.DomainStatus) {
configActivate = true
}

domainID, domainStatus, err := hypervisor.CurrentHypervisor().Task(status).Info(status.DomainName)
domainID, domainStatus, err := CurrentHypervisor().Task(status).Info(status.DomainName)

Check warning on line 947 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L947

Added line #L947 was not covered by tests
if err != nil || domainStatus == types.HALTED {
if status.Activated && configActivate {
if err == nil {
Expand Down Expand Up @@ -963,10 +977,10 @@ func verifyStatus(ctx *domainContext, status *types.DomainStatus) {
}

//cleanup app instance tasks
if err := hypervisor.CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {

Check warning on line 980 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L980

Added line #L980 was not covered by tests
log.Errorf("failed to delete domain: %s (%v)", status.DomainName, err)
}
if err := hypervisor.CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {

Check warning on line 983 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L983

Added line #L983 was not covered by tests
log.Errorf("failed to cleanup domain: %s (%v)", status.DomainName, err)
}
}
Expand Down Expand Up @@ -1104,7 +1118,7 @@ func maybeRetryBoot(ctx *domainContext, status *types.DomainStatus) {
}
defer file.Close()

if err := hypervisor.CurrentHypervisor().Task(status).Setup(*status, *config, ctx.assignableAdapters, nil, file); err != nil {
if err := CurrentHypervisor().Task(status).Setup(*status, *config, ctx.assignableAdapters, nil, file); err != nil {

Check warning on line 1121 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1121

Added line #L1121 was not covered by tests
//it is retry, so omit error
log.Errorf("Failed to create DomainStatus from %v: %s",
config, err)
Expand Down Expand Up @@ -1383,14 +1397,14 @@ func doAssignIoAdaptersToDomain(ctx *domainContext, config types.DomainConfig,

}
for i, long := range assignmentsPci {
err := hypervisor.CurrentHypervisor().PCIReserve(long)
err := CurrentHypervisor().PCIReserve(long)

Check warning on line 1400 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1400

Added line #L1400 was not covered by tests
if err != nil {
// Undo what we assigned
for j, long := range assignmentsPci {
if j >= i {
break
}
hypervisor.CurrentHypervisor().PCIRelease(long)
CurrentHypervisor().PCIRelease(long)

Check warning on line 1407 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1407

Added line #L1407 was not covered by tests
}
if publishAssignableAdapters {
ctx.publishAssignableAdapters()
Expand Down Expand Up @@ -1567,7 +1581,7 @@ func doActivate(ctx *domainContext, config types.DomainConfig,
defer file.Close()

globalConfig := agentlog.GetGlobalConfig(log, ctx.subGlobalConfig)
if err := hypervisor.CurrentHypervisor().Task(status).Setup(*status, config, ctx.assignableAdapters, globalConfig, file); err != nil {
if err := CurrentHypervisor().Task(status).Setup(*status, config, ctx.assignableAdapters, globalConfig, file); err != nil {

Check warning on line 1584 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1584

Added line #L1584 was not covered by tests
log.Errorf("Failed to create DomainStatus from %v: %s",
config, err)
status.SetErrorNow(err.Error())
Expand Down Expand Up @@ -1626,17 +1640,17 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
status.State = types.BOOTING
publishDomainStatus(ctx, status)

err := hypervisor.CurrentHypervisor().Task(status).Start(status.DomainName)
err := CurrentHypervisor().Task(status).Start(status.DomainName)

Check warning on line 1643 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1643

Added line #L1643 was not covered by tests
if err != nil {
log.Errorf("domain start for %s: %s", status.DomainName, err)
status.SetErrorNow(err.Error())

// Delete
if err := hypervisor.CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {

Check warning on line 1649 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1649

Added line #L1649 was not covered by tests
log.Errorf("failed to delete domain: %s (%v)", status.DomainName, err)
}
// Cleanup
if err := hypervisor.CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {

Check warning on line 1653 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1653

Added line #L1653 was not covered by tests
log.Errorf("failed to cleanup domain: %s (%v)", status.DomainName, err)
}

Expand All @@ -1650,7 +1664,7 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
status.VifList = checkIfEmu(status.VifList)

status.State = types.RUNNING
domainID, state, err := hypervisor.CurrentHypervisor().Task(status).Info(status.DomainName)
domainID, state, err := CurrentHypervisor().Task(status).Info(status.DomainName)

Check warning on line 1667 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1667

Added line #L1667 was not covered by tests

if err != nil {
// Immediate failure treat as above
Expand All @@ -1661,11 +1675,11 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
log.Errorf("doActivateTail(%v) failed for %s: %s",
status.UUIDandVersion, status.DisplayName, err)
// Delete
if err := hypervisor.CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {

Check warning on line 1678 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1678

Added line #L1678 was not covered by tests
log.Errorf("failed to delete domain: %s (%v)", status.DomainName, err)
}
// Cleanup
if err := hypervisor.CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {

Check warning on line 1682 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1682

Added line #L1682 was not covered by tests
log.Errorf("failed to cleanup domain: %s (%v)", status.DomainName, err)
}
return
Expand Down Expand Up @@ -1710,7 +1724,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool

log.Functionf("doInactivate(%v) for %s domainId %d",
status.UUIDandVersion, status.DisplayName, status.DomainId)
domainID, _, err := hypervisor.CurrentHypervisor().Task(status).Info(status.DomainName)
domainID, _, err := CurrentHypervisor().Task(status).Info(status.DomainName)

Check warning on line 1727 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1727

Added line #L1727 was not covered by tests
if err == nil && domainID != status.DomainId {
status.DomainId = domainID
status.BootTime = time.Now()
Expand Down Expand Up @@ -1784,7 +1798,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool
}

if status.DomainId != 0 {
if err := hypervisor.CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Delete(status.DomainName); err != nil {

Check warning on line 1801 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1801

Added line #L1801 was not covered by tests
log.Errorf("Failed to delete domain %s (%v)", status.DomainName, err)
} else {
log.Functionf("doInactivate(%v) for %s: Delete succeeded",
Expand All @@ -1802,7 +1816,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool
}

func doCleanup(ctx *domainContext, status *types.DomainStatus) {
if err := hypervisor.CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {
if err := CurrentHypervisor().Task(status).Cleanup(status.DomainName); err != nil {

Check warning on line 1819 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1819

Added line #L1819 was not covered by tests
log.Errorf("failed to cleanup domain: %s (%v)", status.DomainName, err)
}

Expand Down Expand Up @@ -1906,7 +1920,7 @@ func releaseAdapters(ctx *domainContext, ioAdapterList []types.IoAdapter,
checkIoBundleAll(ctx)
}
for _, long := range assignments {
err := hypervisor.CurrentHypervisor().PCIRelease(long)
err := CurrentHypervisor().PCIRelease(long)

Check warning on line 1923 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L1923

Added line #L1923 was not covered by tests
if err != nil && !ignoreErrors {
status.SetErrorNow(err.Error())
}
Expand Down Expand Up @@ -2275,7 +2289,7 @@ func waitForDomainGone(status types.DomainStatus, maxDelay time.Duration) bool {
time.Sleep(delay)
waited += delay
}
_, state, err := hypervisor.CurrentHypervisor().Task(&status).Info(status.DomainName)
_, state, err := CurrentHypervisor().Task(&status).Info(status.DomainName)

Check warning on line 2292 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2292

Added line #L2292 was not covered by tests
if err != nil {
log.Errorf("waitForDomainGone(%v) for %s error %s state %s",
status.UUIDandVersion, status.DisplayName,
Expand Down Expand Up @@ -2363,7 +2377,7 @@ func DomainCreate(ctx *domainContext, status types.DomainStatus) (int, error) {
log.Errorf("DomainCreate(%s) no DomainConfig", status.Key())
return 0, fmt.Errorf("DomainCreate(%s) no DomainConfig", status.Key())
}
domainID, err = hypervisor.CurrentHypervisor().Task(&status).Create(status.DomainName, filename, config)
domainID, err = CurrentHypervisor().Task(&status).Create(status.DomainName, filename, config)

Check warning on line 2380 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2380

Added line #L2380 was not covered by tests

return domainID, err
}
Expand All @@ -2376,7 +2390,7 @@ func DomainShutdown(status types.DomainStatus, force bool) error {

// Stop the domain
log.Functionf("Stopping domain - %s", status.DomainName)
err = hypervisor.CurrentHypervisor().Task(&status).Stop(status.DomainName, force)
err = CurrentHypervisor().Task(&status).Stop(status.DomainName, force)

Check warning on line 2393 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2393

Added line #L2393 was not covered by tests

return err
}
Expand Down Expand Up @@ -2833,7 +2847,7 @@ func handlePhysicalIOAdapterListImpl(ctxArg interface{}, key string,
len(aa.IoBundleList))

// check for mismatched PCI-ids and assignment groups and mark as errors
aa.CheckBadAssignmentGroups(log, hypervisor.CurrentHypervisor().PCISameController)
aa.CheckBadAssignmentGroups(log, CurrentHypervisor().PCISameController)

Check warning on line 2850 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2850

Added line #L2850 was not covered by tests
for i := range aa.IoBundleList {
ib := &aa.IoBundleList[i]
log.Functionf("handlePhysicalIOAdapterListImpl: new Adapter: %+v",
Expand Down Expand Up @@ -2878,7 +2892,7 @@ func handlePhysicalIOAdapterListImpl(ctxArg interface{}, key string,
aa.AddOrUpdateIoBundle(log, *ib)

// check for mismatched PCI-ids and assignment groups and mark as errors
aa.CheckBadAssignmentGroups(log, hypervisor.CurrentHypervisor().PCISameController)
aa.CheckBadAssignmentGroups(log, CurrentHypervisor().PCISameController)

Check warning on line 2895 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2895

Added line #L2895 was not covered by tests
// Lookup since it could have changed
ib = aa.LookupIoBundlePhylabel(ib.Phylabel)
updatePortAndPciBackIoBundle(ctx, ib)
Expand Down Expand Up @@ -2979,7 +2993,7 @@ func updatePortAndPciBackIoBundle(ctx *domainContext, ib *types.IoBundle) (chang
// expand list to include other PCI functions on the same PCI controller
// since they need to be treated as part of the same bundle even if the
// EVE controller doesn't know it
list = aa.ExpandControllers(log, list, hypervisor.CurrentHypervisor().PCISameController)
list = aa.ExpandControllers(log, list, CurrentHypervisor().PCISameController)

Check warning on line 2996 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L2996

Added line #L2996 was not covered by tests
for _, ib := range list {
if types.IsPort(ctx.deviceNetworkStatus, ib.Ifname) {
isPort = true
Expand Down Expand Up @@ -3065,7 +3079,7 @@ func updatePortAndPciBackIoMember(ctx *domainContext, ib *types.IoBundle, isPort
if ib.PciLong != "" {
log.Functionf("updatePortAndPciBackIoMember: Removing %s (%s) from pciback",
ib.Phylabel, ib.PciLong)
err = hypervisor.CurrentHypervisor().PCIRelease(ib.PciLong)
err = CurrentHypervisor().PCIRelease(ib.PciLong)

Check warning on line 3082 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L3082

Added line #L3082 was not covered by tests
if err != nil {
err = fmt.Errorf("adapter %s (group %s, type %d) PCI ID %s; not released by hypervisor: %v",
ib.Phylabel, ib.AssignmentGroup, ib.Type,
Expand Down Expand Up @@ -3112,7 +3126,7 @@ func updatePortAndPciBackIoMember(ctx *domainContext, ib *types.IoBundle, isPort
} else if ib.PciLong != "" && ib.UsbAddr == "" {
log.Noticef("Assigning %s (%s) to pciback",
ib.Phylabel, ib.PciLong)
err := hypervisor.CurrentHypervisor().PCIReserve(ib.PciLong)
err := CurrentHypervisor().PCIReserve(ib.PciLong)

Check warning on line 3129 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L3129

Added line #L3129 was not covered by tests
if err != nil {
return changed, err
}
Expand Down Expand Up @@ -3353,7 +3367,7 @@ func handleIBDelete(ctx *domainContext, phylabel string) {
log.Functionf("handleIBDelete: Assigning %s (%s) back",
ib.Phylabel, ib.PciLong)
if ib.PciLong != "" {
err := hypervisor.CurrentHypervisor().PCIRelease(ib.PciLong)
err := CurrentHypervisor().PCIRelease(ib.PciLong)

Check warning on line 3370 in pkg/pillar/cmd/domainmgr/domainmgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/domainmgr/domainmgr.go#L3370

Added line #L3370 was not covered by tests
if err != nil {
log.Errorf("handleIBDelete(%d %s %s) PCIRelease %s failed %v",
ib.Type, ib.Phylabel, ib.AssignmentGroup, ib.PciLong, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/pillar/cmd/usbmanager/usbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/lf-edge/eve/pkg/pillar/agentbase"
"github.com/lf-edge/eve/pkg/pillar/base"
"github.com/lf-edge/eve/pkg/pillar/cmd/domainmgr"
"github.com/lf-edge/eve/pkg/pillar/hypervisor"
"github.com/lf-edge/eve/pkg/pillar/pubsub"
"github.com/lf-edge/eve/pkg/pillar/utils"
Expand Down Expand Up @@ -81,7 +82,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
}
log.Functionf("processed Vault Status")

currentHypervisor := hypervisor.CurrentHypervisor()
currentHypervisor := domainmgr.CurrentHypervisor()

Check warning on line 85 in pkg/pillar/cmd/usbmanager/usbmanager.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/usbmanager/usbmanager.go#L85

Added line #L85 was not covered by tests
_, ok := currentHypervisor.(hypervisor.KvmContext)
if ok {
usbCtx.subscribe(ps)
Expand Down
25 changes: 1 addition & 24 deletions pkg/pillar/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,14 @@
package hypervisor

import (
"flag"
"fmt"
"log"
"os"

"github.com/lf-edge/eve/pkg/pillar/types"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/sirupsen/logrus"
"os"
)

var currentHypervisor Hypervisor

func init() {
var err error

flagSet := flag.NewFlagSet("", flag.ExitOnError)
allHypervisors, enabledHypervisors := GetAvailableHypervisors()
hypervisorPtr := flagSet.String("h", enabledHypervisors[0], fmt.Sprintf("Current hypervisor %+q", allHypervisors))

currentHypervisor, err = GetHypervisor(*hypervisorPtr)
if err != nil {
log.Fatal(err)
}
}

// CurrentHypervisor returns the current hypervisor
func CurrentHypervisor() Hypervisor {
return currentHypervisor
}

// Hypervisor provides methods for manipulating domains on the host
type Hypervisor interface {
Name() string
Expand Down

0 comments on commit c7c98de

Please sign in to comment.