-
Notifications
You must be signed in to change notification settings - Fork 37
lxd/instance: use SSH by default, allow switching to exec
#114
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Tests for pycloudlib.lxd.instance.""" | ||
| from unittest import mock | ||
|
|
||
| from pycloudlib.lxd.instance import LXDInstance | ||
|
|
||
|
|
||
| class TestExecute: | ||
| """Tests covering pycloudlib.lxd.instance.Instance.execute.""" | ||
|
|
||
| def test_all_rcs_acceptable_when_using_exec(self): | ||
| """Test that we invoke util.subp with rcs=None for exec calls. | ||
|
|
||
| rcs=None means that we will get a Result object back for all return | ||
| codes, rather than an exception for non-zero return codes. | ||
| """ | ||
| instance = LXDInstance(None, execute_via_ssh=False) | ||
| with mock.patch("pycloudlib.lxd.instance.subp") as m_subp: | ||
| instance.execute("some_command") | ||
| assert 1 == m_subp.call_count | ||
| args, kwargs = m_subp.call_args | ||
| assert "exec" in args[0] | ||
| assert kwargs.get("rcs", mock.sentinel.not_none) is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that this code is not optimal at all, but the reason I have added it here is that we could change the ssh keys here, but still have launched instances that are using an old key. In that situation, we would provided an unusable instance.
However, I know that this is not optimal because, for example, if we can't exec into the machine, that
pull_filecall will not work. So maybe we can drop this check and live with this possibility.But if you think there is a smarter way to handle that, no problem at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, this is the code I was hoping to discuss! You're correct, the issue I found is that we don't necessarily have
execaccess when this runs (and, indeed, we definitely don't when this runs in the demo scripts, which was causing CI failure). Adding aninstance._wait_for_execute()call inget_instancedoesn't seem like the right thing to do: if the instance isn't expected to be accessible, that would cause a long delay.I think this logic is less necessary than it was previously, however, because
instance.key_pairno longer determines our execute behaviour: even ifinstance.key_pairisNone, we will still attempt to SSH in (using any keys available to paramiko).However, I don't think we can say it's entirely unnecessary: while we don't need it to determine the SSH key to use (and, actually, never did because paramiko will try all keys by default), it did serve a purpose previously: if SSH execution could work (determined via
exec), the LXDInstance would be configured to execute via SSH instead of viaexec, otherwise it would be configured to useexec. We lose that behaviour here: we will always return aLXDInstanceconfigured to execute via SSH.cloud-init's tests only have a single place which uses
get_instance(whenCLOUD_INIT_EXISTING_INSTANCE_IDis set). It actually has a similar issue to the one we're trying to solve here: previously with a local SSH key configured, it would have always configured SSH access (even to instances for which SSH wouldn't work: the existence of an authorized key does not indicate, e.g., working networking), and would otherwise have always configuredexecaccess. I need to update canonical/cloud-init#802 to handle things differently: we should setinstance.execute_via_sshafter the instance has been instantiated. We would still not require the "execution method auto-detection" which is being removed here.Does UA client have test code which would be affected by this removal? Or can we safely remove it (and modify the docstring here to explain the execution behaviour)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not known about the fact that
paramikowould try to access the machine with all of the keys that is has seen. If that is the case, I don't see any problem removing the code and it should not affect uaclient at all.Thanks for all the provided context @OddBloke :)