Skip to content
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

Conversation

alexlovelltroy
Copy link
Member

This adds validation of xnames for bss using the Cray-HPE xname library and adds tests to validate the behavior I believe is requested in #51

Copy link
Collaborator

@synackd synackd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. According to the OpenAPI spec, PUT only updates and does not create new so I think implementing the check just for POST is fine for now.

Comment on lines -59 to +61
Hosts []string `json:"hosts,omitempty"`
Hosts []string `json:"hosts,omitempty"` // This list of hosts must be xnames
Copy link
Collaborator

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)

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.

@@ -450,6 +450,16 @@ func BootparametersPost(w http.ResponseWriter, r *http.Request) {
fmt.Sprintf("Bad Request: %s", err))
return
}
// Check that the xnames are valid
err = args.CheckXnames()
Copy link
Collaborator

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.

@synackd
Copy link
Collaborator

synackd commented Dec 2, 2024

Tested this on our cluster:

$ curl -H "Authorization: Bearer $ACCESS_TOKEN" https://foobar.openchami.cluster:8443/boot/v1/bootparameters -v -d '{"hosts": ["test1.local", "test2.local"], "macs": ["00:40:a6:82:f6:c5","a4:bf:01:3e:c0:a2","00:40:a6:82:f7:0c"], "nids": [1, 2, 3], "params": "test", "kernel": "test", "initrd": "test", "cloud-init": {"user-data": {"foo": "bar"},"meta-data": {"foo": "bar"}}}'
[...]
< HTTP/2 400 
< content-type: application/problem+json
< date: Mon, 02 Dec 2024 21:00:06 GMT 
< content-length: 109 
< 
{"type":"about:blank","title":"Bad Request","detail":"Bad Request: invalid xname: test1.local","status":400}
* Connection #0 to host foobar.openchami.cluster left intact
$ curl -H "Authorization: Bearer $ACCESS_TOKEN" https://foobar.openchami.cluster:8443/boot/v1/bootparameters -v
[...]
< HTTP/2 200 
< content-type: application/json; charset=UTF-8
< date: Mon, 02 Dec 2024 21:01:09 GMT 
< content-length: 5
< 
null
* Connection #0 to host foobar.openchami.cluster left intact
$ curl -H "Authorization: Bearer $ACCESS_TOKEN" https://foobar.openchami.cluster:8443/boot/v1/bootparameters -v -d '{"hosts": ["x0c0s2b0n0", "x0c0s3b0n0"], "macs": ["00:40:a6:82:f6:c5","a4:bf:01:3e:c0:a2","00:40:a6:82:f7:0c"], "nids": [1, 2, 3], "params": "test", "kernel": "test", "initrd": "test", "cloud-init": {"user-data": {"foo": "bar"},"meta-data": {"foo": "bar"}}}'
[...]
< HTTP/2 201 
< bss-referral-token: 2c6fd5db-8224-4ae7-ad8d-d692f54f5801
< content-type: application/json; charset=UTF-8
< date: Mon, 02 Dec 2024 21:03:07 GMT 
< content-length: 0
< 
* Connection #0 to host foobar.openchami.cluster left intact
$ curl -H "Authorization: Bearer $ACCESS_TOKEN" https://foobar.openchami.cluster:8443/boot/v1/bootparameters -v
[...]
< HTTP/2 200 
< content-type: application/json; charset=UTF-8
< date: Mon, 02 Dec 2024 21:04:03 GMT 
< content-length: 246 
< 
[{"hosts":["x0c0s2b0n0","x0c0s3b0n0"],"params":"test","kernel":"test","initrd":"test","cloud-init":{"meta-data":null,"user-data":null,"phone-home":{"pub_key_dsa":"","pub_key_rsa":"","pub_key_ecdsa":"","instance_id":"","hostname":"","fqdn":""}}}]
* Connection #0 to host foobar.openchami.cluster left intact

@alexlovelltroy alexlovelltroy merged commit 49484ea into main Dec 2, 2024
3 checks passed
@synackd synackd deleted the 51-bug-bss-post-not-returns-201-but-data-missing-in-database-if-hosts-are-not-valid-xnames branch December 2, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] BSS POST returns 201 but data missing in database if hosts are not valid xnames
2 participants