Skip to content

[lxd.py] Fixed commands for snap + added missing commands#4217

Open
rmolkentin wants to merge 1 commit intososreport:mainfrom
rmolkentin:main
Open

[lxd.py] Fixed commands for snap + added missing commands#4217
rmolkentin wants to merge 1 commit intososreport:mainfrom
rmolkentin:main

Conversation

@rmolkentin
Copy link

I added some missing LXD commands such as:

  • lxc operation list
  • lxc info
  • lxc alias list
  • lxc config show
  • lxc remote list
  • lxc version
  • lxc warning list
  • lxc auth permission list
  • lxc cluster list
  • lxd cluster list-database

The ‘snap’ section did not capture any LXD commands, this has been fixed.

Signed-off-by: Ryan Molkentin ryan.molkentin@canonical.com

Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • [ X ] Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • [ X ] Is the subject and message clear and concise?
  • [ X ] Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • [ X ] Does the commit contain a Signed-off-by: First Lastname email@example.com?
  • [ X ] Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • [ X ] Are all passwords or private data gathered by this PR obfuscated?

@packit-as-a-service
Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/sosreport-sos-4217
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

Copy link
Contributor

@MggMuggins MggMuggins left a comment

Choose a reason for hiding this comment

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

Hey @rmolkentin - thanks for this. Two thoughts.

  • I'm wondering if we can avoid duplicating the list of commands - I see that the SosPredicate is different between the snap and package installs. I wonder if we could declare lxd_pred outside the if self.is_snap block (just like lxd_pred = None) and then put the add_cmd_output after the if/else block
  • What happens, if for some reason, root's lxc configuration has a different remote than local configured? My sense is that sos shouldn't be trying to hit the API of a remote lxd server. I'm not remembering offhand what sos does for openstack (although I think it doesn't hit the API much at all). I think it's reasonable to scrape this data out of the local LXD, but I also think we should pass --remote local for each command so that we're sure that we're not accidentally scraping information about a remote cluster that the user didn't intend to send (you might consider calling add_cmd_output in a loop to avoid writing --remote local 20 times, but it's up to you what you think is more readable 🙂 ).

Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Overall looks fine, just the note below. We can reduce maintenance overhead by only defining the list once, outside the existing if-block.

Comment on lines 32 to 48
self.add_cmd_output([
"lxc image list",
"lxc list",
"lxc network list",
"lxc profile list",
"lxc storage list",
"lxc operation list",
"lxc info",
"lxc alias list",
"lxc config show",
"lxc remote list",
"lxc version",
"lxc warning list",
"lxc auth permission list",
"lxc cluster list",
"lxd cluster list-database"
], pred=lxd_pred, snap_cmd=True)
Copy link
Member

Choose a reason for hiding this comment

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

As @MggMuggins alluded to, you can pull this block outside the if self.is_snap block, and then only define the list once. You can then use snap_cmd=self.is_snap.

Copy link
Contributor

@MggMuggins MggMuggins left a comment

Choose a reason for hiding this comment

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

Looks nice! A few items

"lxc warning list local",
"lxc auth permission list",
"lxc cluster list local",
"lxd cluster list-database local"
Copy link
Contributor

@MggMuggins MggMuggins Jan 30, 2026

Choose a reason for hiding this comment

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

list-database doesn't exist in LXD 5.21; does it show anything different than cluster list? I'd recommend either just dropping it or making it conditional on the LXD version.

Copy link
Author

Choose a reason for hiding this comment

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

That's fair enough, removing lxd cluster list-database

def setup(self):

lxc_cmds = [
"lxc image list local",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"lxc image list local",
"lxc image list local:",

Missing a colon; same thing for all the other ones

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your feedback! These commands work with or without the colon for me, is it necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

From the --help output:

Usage:
  lxc image list [<remote>:] [<filter>...] [flags]

It uses local as a filter instead of the remote, so you end up with only images with aliases containing local (compare the outputs with and without the filter 🙂 )

Copy link
Author

Choose a reason for hiding this comment

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

Copy that, adding a colon to needed commands 👍

"lxc storage list local",
"lxc operation list",
"lxc info",
"lxc alias list",
Copy link
Contributor

Choose a reason for hiding this comment

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

lxc alias list and lxc remote list are client-only so you're good for those ones, but everything else takes a [remote:] argument

Copy link
Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

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

Code LGTM.

However, please squash your fixup commits into the base commit. You can do this with git rebase -i HEAD~5, then in your editor change pick to f (or fixup) for all commits except for the original first commit, which should remain pick. Save and exit, and everything should be squashed. Then you'll just need to git push origin $your_branch --force

@TurboTurtle
Copy link
Member

Oh, also, please add a DCO line. You can do this with git commit -s --amend after the git rebase I described above.

@TurboTurtle TurboTurtle added Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer Kind/Collection New or updated command or file collection Reviewed/Needs Rebase Code has been reviewed and can be merged once branch is rebased to current main. labels Jan 30, 2026
@rmolkentin rmolkentin force-pushed the main branch 2 times, most recently from 6290680 to 097367d Compare February 2, 2026 15:30
"lxc operation list local:",
"lxc info local:",
"lxc alias list",
"lxc config show local:",
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey Ryan, sorry for the additional comment, but config show might grab a few secrets that live in the server config:

And unfortunately those aren't necessarily exhaustive if the LXD team decides to add more integrations with more secrets in the future. Does lxd.buginfo (source code) collect the server config (and correctly redact the secrets)? I wonder if they avoided doing that for the same reason...

I think it's probably better to try and get the buginfo script updated than try to keep sos up to date with all the possible config values - could you drop config show from here for now (so we can merge the rest) and then we'll open an issue/PR in LXD?

Copy link
Author

@rmolkentin rmolkentin Feb 2, 2026

Choose a reason for hiding this comment

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

Hey, no worries. Looks like lxd.buginfo does collect the config but I'm not sure if it redacts out that information. That's fine with me, I'll drop that command.

The LXD plugin for sos had 2 main issues:

1. It was lacking in troubleshooting commands. For verifying cluster
quorum & health and for more information I have since added:
- lxc operation list
- lxc info
- lxc alias list
- lxc remote list
- lxc version
- lxc warning list
- lxc auth permission list
- lxc cluster list

All command use the local: remote.

2. The ‘snap’ section of the plugin was broken and did not capture
 much of anything except lxd.buginfo and the few lxc commands
 included only worked on debs. This has been changed to work on
 both the debian package and snap version of LXD.

Signed-off-by: Ryan Molkentin <ryan.molkentin@canonical.com>
Copy link
Contributor

@MggMuggins MggMuggins left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kind/Collection New or updated command or file collection Reviewed/Needs Rebase Code has been reviewed and can be merged once branch is rebased to current main. Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants