Skip to content

Commit

Permalink
fix crash with new args method when minimega not running
Browse files Browse the repository at this point in the history
  • Loading branch information
jacdavi committed Sep 11, 2024
1 parent 31370cc commit b6f1bd8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/go/util/mm/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ func GetMMFullPath(path string) string {
func GetMMFilesDirectory() string {
defaultMMFilesDirectory := fmt.Sprintf("%s/images", common.PhenixBase)

path, ok := GetMMArgs()["filepath"]
args, err := GetMMArgs()
if err != nil {
plog.Warn("Could not get mm files directory from minimega")
return defaultMMFilesDirectory
}

path, ok := args["filepath"]
if !ok {
plog.Warn("Could not get mm files directory from minimega")
return defaultMMFilesDirectory
Expand Down
8 changes: 6 additions & 2 deletions src/go/util/mm/minimega.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,14 @@ func (this Minimega) IsHeadnode(node string) bool {
return node == this.Headnode()
}

func (this Minimega) GetMMArgs() map[string]string {
func (this Minimega) GetMMArgs() (map[string]string, error) {
cmd := mmcli.NewCommand()
cmd.Command = "args"
return mmcli.RunTabular(cmd)[0]
rows := mmcli.RunTabular(cmd)
if len(rows) == 1 {
return rows[0], nil
}
return nil, fmt.Errorf("no args returned")
}

func (Minimega) GetVLANs(opts ...Option) (map[string]int, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/go/util/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MM interface {
GetNamespaceHosts(string) (Hosts, error)
Headnode() string
IsHeadnode(string) bool
GetMMArgs() map[string]string
GetMMArgs() (map[string]string, error)
GetVLANs(...Option) (map[string]int, error)

IsC2ClientActive(...C2Option) error
Expand Down
2 changes: 1 addition & 1 deletion src/go/util/mm/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func IsHeadnode(node string) bool {
return DefaultMM.IsHeadnode(node)
}

func GetMMArgs() map[string]string {
func GetMMArgs() (map[string]string, error) {
return DefaultMM.GetMMArgs()
}

Expand Down
2 changes: 1 addition & 1 deletion src/go/web/rbac/known_policy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6f1bd8

Please sign in to comment.