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

network interact tests: fix SSH check #1071

Merged

Conversation

m-ildefons
Copy link
Contributor

  • Fix SSH connection checks There are serveral places where a test checks that an SSH connection to a VM on a specific interface can not be established. Doing so by checking for the specific error "no route to host" is potentially wrong, because this presumes that the host executing the test even knows how to route to the network. This isn't always the case, e.g. when executing the test suite on a developer workstation instead of a CI server. In those cases there may be an SSH error "network unreachable" instead, which should also be acceptable to let the test pass.
    To allow for this case, instead of checking the output of the SSH command for a specific substring, checking for the return code 255 is better, because it allows for different kind of errors and is less fragile than searching for a string in the command output.

  • Mark networking tests with @pytest.mark.networks This includes the network interaction tests when selecting tests with the pytest mark "networks"

  • Fix SSH connection with paramiko when the ssh agent contains keys, but password authentication is used
    By defaul paramiko will try to use key based authentication using whichever keys it finds in the ssh-agent. In this case however password based authentication is used and paramiko should not try to use the keys from the ssh-agent. Otherwise it may be confused and error out. This is the same problem that was fixed in networking tests: fix ssh auth, clean up code #1060 for other tests

- Fix SSH connection checks
There are serveral places where a test checks that an SSH connection to
a VM on a specific interface can not be established.
Doing so by checking for the specific error "no route to host" is
potentially wrong, because this presumes that the host executing the
test even knows how to route to the network. This isn't always the case,
e.g. when executing the test suite on a developer workstation instead of
a CI server. In those cases there may be an SSH error "network
unreachable" instead, which should also be acceptable to let the test
pass.
To allow for this case, instead of checking the output of the SSH
command for a specific substring, checking for the return code 255 is
better, because it allows for different kind of errors and is less
fragile than searching for a string in the command output.

- Mark networking tests with @pytest.mark.networks
This includes the network interaction tests when selecting tests with
the pytest mark "networks"

- Fix SSH connection with paramiko when the ssh agent contains keys, but
password authentication is used
By defaul paramiko will try to use key based authentication using
whichever keys it finds in the ssh-agent. In this case however password
based authentication is used and paramiko should not try to use the keys
from the ssh-agent. Otherwise it may be confused and error out.

Signed-off-by: Moritz Röhrich <[email protected]>
@m-ildefons m-ildefons self-assigned this Jan 22, 2024
Copy link
Member

@lanfon72 lanfon72 left a comment

Choose a reason for hiding this comment

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

The change looks fine to me, but tested on harvester-runtests#459(this PR, modified) and harvester-runtests#460(original), modified get more fails.

I feel there might have some bugs inside which not caused by this change.

btw, for reviewers, we can just simply add harvester/qa team them all QAs will receive the mail to review this PR.

@lanfon72 lanfon72 requested a review from a team January 22, 2024 16:58
@khushboo-rancher khushboo-rancher merged commit da344f4 into harvester:main Jan 22, 2024
2 checks passed
@m-ildefons
Copy link
Contributor Author

This change worked perfectly fine for me on a clean cluster:

│ ~/repos/harvester/tests │► pytest harvester_e2e_tests/ -m networks                                                                                                                                                                                                                                                                                                                                                                     
=============================================================================================== test session starts ================================================================================================                                                                                                                                                                                                                     
platform linux -- Python 3.6.15, pytest-7.0.1, pluggy-1.0.0                                                                                                                                                                                                                                                                                                                                                                              
rootdir: /home/moritz/repos/harvester/tests, configfile: tox.ini                                                                                                                                                                                                                                                                                                                                                                         
plugins: drop-dup-tests-0.3.0, ordering-0.6, metadata-1.11.0, html-3.2.0, json-report-1.5.0, dependency-0.6.0                                                                                                                                                                                                                                                                                                                            
collected 226 items / 206 deselected / 20 selected                                                                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                                                                                                                         
harvester_e2e_tests/apis/test_networks.py ..ss..s...                                                                                                                                                         [ 50%]                                                                                                                                                                                                                      
harvester_e2e_tests/integrations/test_0_storage_network.py .                                                                                                                                                 [ 55%]                                                                                                                                                                                                                      
harvester_e2e_tests/integrations/test_5_vm_networks.py ...                                                                                                                                                   [ 70%]                                                                                                                                                                                                                      
harvester_e2e_tests/integrations/test_5_vm_networks_interact.py ......                                                                                                                                       [100%]                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                         
================================================================================================= warnings summary =================================================================================================                                                                                                                                                                                                                     
.venv/lib64/python3.6/site-packages/paramiko/transport.py:32                                                                                                                                                                                                                                                                                                                                                                             
  /home/moritz/repos/harvester/tests/.venv/lib64/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for                                                                                                                                                                                                                     
 it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.                                                                                                                                                                                                                                                                                                                                  
    from cryptography.hazmat.backends import default_backend                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                                         
harvester_e2e_tests/apis/test_networks.py: 8 warnings                                                                                                                                                                                                                                                                                                                                                                                    
harvester_e2e_tests/integrations/test_0_storage_network.py: 1 warning                                                                                                                                                                                                                                                                                                                                                                    
harvester_e2e_tests/integrations/test_5_vm_networks.py: 3 warnings                                                                                                                                                                                                                                                                                                                                                                       
harvester_e2e_tests/integrations/test_5_vm_networks_interact.py: 6 warnings                                                                                                                                                                                                                                                                                                                                                              
  /home/moritz/repos/harvester/tests/.venv/lib64/python3.6/site-packages/urllib3/connectionpool.py:1068: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.84.102.31'. Adding certificate v                                                                                                                                                                                                                     
erification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings                                                                                                                                                                                                                                                                                                                          
    InsecureRequestWarning,                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                         
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html                                                                                                                                                                                                                                                                                                                                                                  
===================================================================== 17 passed, 3 skipped, 206 deselected, 19 warnings in 1565.35s (0:26:05) ======================================================================    

It might be worth looking at the logs to see if there is anything damning in there

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