-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation for xnames in BootparametersPost and enhance tests #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ package bssTypes | |
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/Cray-HPE/hms-xname/xnames" | ||
) | ||
|
||
type PhoneHome struct { | ||
|
@@ -56,7 +58,7 @@ type CloudInit struct { | |
// provide a "default" selection which provides a way to supply default | ||
// parameters for any node which is not explicitly configured. | ||
type BootParams struct { | ||
Hosts []string `json:"hosts,omitempty"` | ||
Hosts []string `json:"hosts,omitempty"` // This list of hosts must be xnames | ||
Comment on lines
-59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (No change requested here, just commenting for posterity) Unfortunately, it looks like there may have been premature optimization here as this field (according to the comment above) is supposed to support xnames and "special names" (i.e. groups). However, the current BSS does not support boot groups with Postgres (yet). This may change with a solution to #50. However for now, this is fine as-is. |
||
Macs []string `json:"macs,omitempty"` | ||
Nids []int32 `json:"nids,omitempty"` | ||
Params string `json:"params,omitempty"` | ||
|
@@ -65,6 +67,7 @@ type BootParams struct { | |
CloudInit CloudInit `json:"cloud-init,omitempty"` | ||
} | ||
|
||
// Validate the MACs in the boot parameters | ||
func (bp BootParams) CheckMacs() (err error) { | ||
if len(bp.Macs) > 0 { | ||
re := regexp.MustCompile(`^([0-9A-Fa-f]{2}:){5}[0-9a-fA-F]{2}$`) | ||
|
@@ -80,6 +83,20 @@ func (bp BootParams) CheckMacs() (err error) { | |
return | ||
} | ||
|
||
// Validate the xnames in the boot parameters. They must be of type "Node" | ||
func (bp BootParams) CheckXnames() (err error) { | ||
for _, xname := range bp.Hosts { | ||
myXname := xnames.FromString(xname) | ||
if myXname == nil { | ||
return fmt.Errorf("invalid xname: %s", xname) | ||
} | ||
if myXname.Type() != "Node" { | ||
return fmt.Errorf("invalid xname type: %s", myXname.Type()) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// The following structures and types all related to the last access information for bootscripts and cloud-init data. | ||
|
||
type EndpointType string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No change requested here, just commenting for posterity)
See comment in pkg/bssTypes/types.go on line 61. When a solution comes for the mentioned issue, this may change to be conditional in the future.