-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dutagent runs module init on startup
Signed-off-by: Jens Drenhaus <jens.drenhaus@blindspot.software>
- Loading branch information
1 parent
c2a6f40
commit c34757f
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dutagent | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/BlindspotSoftware/dutctl/pkg/dut" | ||
) | ||
|
||
// ModuleInitError is a container for errors that occur during module | ||
// initialization. | ||
type ModuleInitError struct { | ||
Errs map[string]error | ||
} | ||
|
||
func (e *ModuleInitError) Error() string { | ||
return fmt.Sprintf("\n%d initialization errors", len(e.Errs)) | ||
} | ||
|
||
// Init runs the Init function of all modules for all commands of the provided | ||
// devices. All init functions are called, even if an error occurs. In this case | ||
// the an ModuleInitErr is returned that holds all errors reported by the modules. | ||
func Init(devices dut.Devlist) error { | ||
var ierr = &ModuleInitError{ | ||
Errs: map[string]error{}, | ||
} | ||
|
||
for devname, device := range devices { | ||
for cmdname, cmd := range device.Cmds { | ||
for _, module := range cmd.Modules { | ||
err := module.Init() | ||
if err != nil { | ||
m := fmt.Sprintf("dev: %s, cmd: %s, mod: %s", devname, cmdname, module.Config.Name) | ||
ierr.Errs[m] = err | ||
} | ||
} | ||
} | ||
} | ||
|
||
if len(ierr.Errs) != 0 { | ||
return ierr | ||
} | ||
|
||
log.Print("Module Initialization OK") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters