non-root status has a bunch of warnings which should be avoided
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ubuntu-advantage-tools (Ubuntu) |
Fix Released
|
Undecided
|
Alberto Contreras | ||
Xenial |
Fix Released
|
Undecided
|
Unassigned | ||
Bionic |
Fix Released
|
Undecided
|
Unassigned | ||
Focal |
Fix Released
|
Undecided
|
Unassigned | ||
Jammy |
Fix Released
|
Undecided
|
Unassigned | ||
Kinetic |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
When running `pro status --warning` as a non-root user, `pro` would show numerous unnecessary warnings.
There were two warnings that showed up:
1. a failed contract-server request warning
2. a failure to remove a notice
(1) is fixed because of a separate refactor that removed that network call from `pro status` entirely.
(2) is fixed by removing the warning from the output. There is no reason the user needs to worry about these, and there's nothing for the user to do, so we shouldn't display them.
[Test Case]
On an attached machine, run `pro status --format json | jq .warnings`
Before the fix, this will show many warnings.
After the fix, this will be an empty list.
[Regression Potential]
The fix involved some refactors to the python code that adds and removes notices. If we made a mistake, then there could arise a situation where notices are not removed/added when they should be.
[Discussion]
These warnings about removing notices are due to us calling `notice.remove` in many places even when the notice is not present (the `remove` function is idempotent). The notices are stored in root-readable files becuase they can only be added when running root-only pro operations - that is why the non-root process cannot remove them. The case where a notice is present and should be removed will be resolved the next time that root runs `pro status`.
[Original Description]
$ sudo pro status --format=json | jq | less
...
"warnings": []
But
$ pro status --format=json | jq | less
"warnings": [
{
"message": "Failed to check for change in machine contract. Reason: Unauthorized: [https:/
"
"service": null,
"type": "system"
},
{
"message": "Trying to remove notice as non-root user",
"
"service": null,
"type": "system"
},
{
"message": "Trying to remove notice as non-root user",
"
"service": null,
"type": "system"
},
many of them
Changed in ubuntu-advantage-tools (Ubuntu): | |
status: | New → Triaged |
Changed in ubuntu-advantage-tools (Ubuntu): | |
assignee: | nobody → Alberto Contreras (aciba) |
Changed in ubuntu-advantage-tools (Ubuntu): | |
status: | Triaged → In Progress |
Changed in ubuntu-advantage-tools (Ubuntu): | |
status: | In Progress → Fix Committed |
description: | updated |
description: | updated |
The `Failed to check for change in machine contract` message won't appear after [1] is merged, as we are moving the update contract check to be a background job and background jobs are executed as root.
The other notices are being addressed by [2].
[1] https:/ /github. com/canonical/ ubuntu- advantage- client/ pull/2409 /github. com/canonical/ ubuntu- advantage- client/ pull/2436
[2] https:/