Add pro feature flag (stable-4.0)#17703
Conversation
269f419 to
c07dd69
Compare
Signed-off-by: Simon Deziel <[email protected]>
Signed-off-by: Simon Deziel <[email protected]> (cherry picked from commit 5f6ff2c)
Signed-off-by: Simon Deziel <[email protected]> (cherry picked from commit 4106bd3)
Signed-off-by: Simon Deziel <[email protected]> (cherry picked from commit 6568ac5)
Signed-off-by: Stéphane Graber <[email protected]> (cherry picked from commit bb0d433) License: Apache-2.0
Signed-off-by: Simon Deziel <[email protected]>
c07dd69 to
b6185d8
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds support for detecting Ubuntu Pro attachment status and advertising it through the LXD user agent. The implementation checks if the host is running Ubuntu and is attached to an Ubuntu Pro subscription, then adds a "pro" feature flag to the user agent string.
Changes:
- Modified
UserAgentFeaturesto validate inputs and return errors, with behavior change from assignment to append - Added new
ubuntupropackage to detect Ubuntu Pro attachment status via CLI - Integrated Ubuntu Pro detection into daemon initialization using OS release information
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/version/useragent.go | Added input validation for whitespace in features and changed error handling from void to error return; changed behavior from assignment to append |
| lxd/ubuntupro/client.go | New client implementation for checking Ubuntu Pro attachment status via CLI |
| lxd/ubuntupro/client_test.go | Comprehensive tests for Ubuntu Pro client functionality |
| lxd/sys/os.go | Added ReleaseInfo field to store OS release information from /etc/os-release |
| lxd/daemon.go | Integrated Ubuntu Pro client in daemon Ready() method; updated UserAgentFeatures error handling |
| lxd/api_cluster.go | Updated UserAgentFeatures calls to handle new error return value |
| // Determine if the host is attached to Ubuntu Pro and update the user agent accordingly. | ||
| isAttached, err := s.pro.isHostAttached() | ||
| if err != nil { | ||
| logger.Debug("Failed to check if host is Ubuntu Pro attached") |
There was a problem hiding this comment.
The logger.Debug call should include the error in the log context for better debugging. Based on patterns in the codebase (e.g., lxd/daemon_images.go:243, lxd/images.go:1684), errors should be logged using log.Ctx. You'll need to import log "gopkg.in/inconshreveable/log15.v2" and then use: logger.Debug("Failed to check if host is Ubuntu Pro attached", log.Ctx{"err": err})
| func UserAgentFeatures(features []string) error { | ||
| for _, feature := range features { | ||
| if strings.IndexFunc(feature, unicode.IsSpace) >= 0 { | ||
| return errors.New("User agent features may not contain whitespace") | ||
| } | ||
| } |
There was a problem hiding this comment.
The new whitespace validation in UserAgentFeatures lacks test coverage. Given that the shared/version package has comprehensive tests (version_test.go), the new validation logic should be tested. Consider adding tests that verify:
- Features without whitespace are accepted
- Features with spaces, tabs, newlines, etc. are rejected
- The error message is correct
- Multiple features can be added successfully
From - canonical/lxd#17478 - canonical/lxd#17703 - canonical/lxd#17741 Signed-off-by: Thomas Parrott <[email protected]>
No description provided.