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

charmcraft: perform LXD checks before use (CRAFT-420) #474

Merged
merged 4 commits into from
Aug 3, 2021

Conversation

cjp256
Copy link
Contributor

@cjp256 cjp256 commented Aug 2, 2021

Invoke ensure_lxd_is_ready() interface before using LXD
provider. This consolidates a couple of existing checks
done elsewhere as well as a new one for ensuring the user
has the necessary permissions to use LXD.

Minor simplification of imports used in providers module
to improve and update mocks accordingly.

Example error:

$ /snap/bin/charmcraft pack
LXD requires additional permissions.
Please ensure that the user is in the 'lxd' group.
(full execution logs in '/home/test1/snap/charmcraft/common/charmcraft-log-0xgcist7')

Signed-off-by: Chris Patterson chris.patterson@canonical.com

Invoke ensure_lxd_is_ready() interface before using LXD
provider. This consolidates a couple of existing checks
done elsewhere as well as a new one for ensuring the user
has the necessary permissions to use LXD.

Minor simplification of imports used in providers module
to improve and update mocks accordingly.

Example error:
```
$ /snap/bin/charmcraft pack
LXD requires additional permissions.
Please ensure that the user is in the 'lxd' group.
(full execution logs in '/home/test1/snap/charmcraft/common/charmcraft-log-0xgcist7')
```

Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
Copy link
Collaborator

@sergiusens sergiusens left a comment

Choose a reason for hiding this comment

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

Looks generally good, tone of voice needs adjusting.

lxd.install()
except lxd.LXDInstallationError as error:
raise CommandError(
"Failed to install LXD. Please visit https://snapcraft.io/lxd for "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove Please, start with Visit -> https://discourse.ubuntu.com/t/tone-of-voice/18883

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I questioned it when I wrote it way back when and never did reconsider. 🤔 I think I just feel compelled to be polite 🤣 will fix (but note that this was just an indent change, not new text).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

raise CommandError(
"Failed to install LXD. Please visit https://snapcraft.io/lxd for "
"LXD is required, but not installed. Please visit https://snapcraft.io/lxd for "
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Chris Patterson added 2 commits August 2, 2021 19:01
Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
Copy link
Contributor

@facundobatista facundobatista left a comment

Choose a reason for hiding this comment

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

Looks great!

if not is_provider_available():
if confirm_with_user(
"LXD is required, but not installed. Do you wish to install LXD "
"and configure it with the defaults?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not worth for this branch, but for the future: for readability in these cases please write the long message outside the if. Thanks!

@cjp256 cjp256 merged commit 1dfb54b into canonical:master Aug 3, 2021
@cjp256 cjp256 deleted the lxd-checks branch August 3, 2021 14:32
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.

3 participants