This repository was archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
[1LP][RFR] Prepare connect_ssh #10056
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7948c57
Prepare connect_ssh
94b3c96
Make trying_ips not default to ininite loop, make it use math.inf.
d53a1f4
Redesign reconnection stuff. Make it use unquirking client-factory me…
de4b80a
Remove retry_connect_rounds
fddf905
React on review of unquirked_ssh_client.
8b54c62
Make _try_batch_of_ips underscored.
c225cd8
Remove f string.
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,68 @@ | ||
| from types import SimpleNamespace | ||
| from unittest.mock import Mock | ||
| from unittest.mock import PropertyMock | ||
|
|
||
| import pytest | ||
|
|
||
| from cfme.utils.ssh import connect_ssh | ||
|
|
||
|
|
||
| creds = SimpleNamespace(principal='mockuser', secret='mockpass') | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def nosleep(mocker): | ||
| mocker.patch('time.sleep') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def vm_mock(): | ||
| vm = Mock() | ||
| all_ips_mock = PropertyMock() | ||
| type(vm).all_ips = all_ips_mock | ||
| all_ips_mock.side_effect = [ | ||
| [None], | ||
| ['NOT_WORKING_IP_MOCK'], | ||
| ['NOT_WORKING_IP_MOCK', 'OTHER_NOT_WORKING_IP_MOCK', | ||
| 'WORKING_IP_MOCK', 'SHOULD_NOT_REACH_THIS_MOCK'], | ||
| ['SHOULD_NOT_REACH_THIS_MOCK', 'SHOULD_NOT_REACH_THIS_MOCK'] | ||
| ] | ||
| return vm | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def vm_mock2(): | ||
| vm = Mock() | ||
| all_ips_mock = PropertyMock() | ||
| type(vm).all_ips = all_ips_mock | ||
| all_ips_mock.side_effect = [ | ||
| ['WORKING_IP_MOCK', 'SHOULD_NOT_REACH_THIS_MOCK'] | ||
| ] | ||
| return vm | ||
|
|
||
|
|
||
| class SSHClientMock: | ||
| def __init__(self, **kwargs): | ||
| self.kwargs = kwargs | ||
| self.close = Mock() | ||
| self.run_command = Mock() | ||
| self.run_command.success.return_value = True | ||
|
|
||
| # disabling check_port is required for not making repeated connection | ||
| # attempts in the SSHClient | ||
| assert kwargs['use_check_port'] is False | ||
|
|
||
| def connect(self): | ||
| hostname = self.kwargs['hostname'] | ||
| if hostname == 'WORKING_IP_MOCK': | ||
| return self | ||
| elif hostname == 'SHOULD_NOT_REACH_THIS_MOCK': | ||
| pytest.fail('We should not have reached checking this IP!') | ||
| else: | ||
| raise Exception(f'This was raised for IP {hostname}.') | ||
|
|
||
|
|
||
| def test_connect_ssh(mocker, vm_mock, vm_mock2): | ||
| mocker.patch('cfme.utils.ssh.SSHClient', SSHClientMock) | ||
| assert connect_ssh(vm_mock, creds, num_sec=3, connect_timeout=1, delay=1).run_command() | ||
| assert connect_ssh(vm_mock2, creds, num_sec=3, connect_timeout=1, delay=1).run_command() |
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
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.
Uh oh!
There was an error while loading. Please reload this page.