diff --git a/tests/ssh/test_ssh_ciphers.py b/tests/ssh/test_ssh_ciphers.py index f675553cad7..30bdc4f917d 100644 --- a/tests/ssh/test_ssh_ciphers.py +++ b/tests/ssh/test_ssh_ciphers.py @@ -17,6 +17,8 @@ def connect_with_specified_ciphers(duthosts, rand_one_dut_hostname, specified_ci dutuser, dutpass = creds['sonicadmin_user'], creds['sonicadmin_password'] sonic_admin_alt_password = duthost.host.options['variable_manager']._hostvars[duthost.hostname].get( "ansible_altpassword") + sonic_admin_alt_passwords = creds["ansible_altpasswords"] + dut_passwords = [dutpass, sonic_admin_alt_password] + sonic_admin_alt_passwords dutip = duthost.mgmt_ip if typename == "enc": @@ -31,29 +33,23 @@ def connect_with_specified_ciphers(duthosts, rand_one_dut_hostname, specified_ci ssh_cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {} {}@{}".format( ssh_cipher_option, dutuser, dutip) - try: - connect = pexpect.spawn(ssh_cmd) - connect.expect('.*[Pp]assword:') - connect.sendline(dutpass) - - i = connect.expect( - '{}@{}:'.format(dutuser, duthost.hostname), timeout=10) - pytest_assert(i == 0, "Failed to connect") - except Exception: + for dutpass in dut_passwords: try: connect = pexpect.spawn(ssh_cmd) connect.expect('.*[Pp]assword:') - connect.sendline(sonic_admin_alt_password) + connect.sendline(dutpass) i = connect.expect( '{}@{}:'.format(dutuser, duthost.hostname), timeout=10) pytest_assert(i == 0, "Failed to connect") - except pexpect.exceptions.EOF: - pytest.fail("EOF reached") - except pexpect.exceptions.TIMEOUT: - pytest.fail("Timeout reached") + return except Exception as e: - pytest.fail("Cannot connect to DUT host via SSH: {}".format(e)) + output = connect.before.decode() + if "Permission denied" in output: + continue + else: + pytest.fail(e) + pytest.fail("Cannot connect to DUT host via SSH") def test_ssh_protocol_version(duthosts, rand_one_dut_hostname):