From a6382b730b505dce400f31ae83c4b76f26b9e821 Mon Sep 17 00:00:00 2001
From: Sascha Bischoff <sascha.bischoff@arm.com>
Date: Mon, 2 Nov 2015 10:09:59 +0000
Subject: [PATCH] TelnetConnection:

- Allowed telnet connections without a password.

This is required as part of the upcoming Gem5Device, which uses a
password-less telnet connection to communicate with the device.
---
 wlauto/utils/ssh.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/wlauto/utils/ssh.py b/wlauto/utils/ssh.py
index 31d5b3d7..3b1ac9c4 100644
--- a/wlauto/utils/ssh.py
+++ b/wlauto/utils/ssh.py
@@ -62,15 +62,20 @@ class TelnetConnection(pxssh.pxssh):
         cmd = 'telnet -l {} {} {}'.format(username, server, port)
 
         spawn._spawn(self, cmd)  # pylint: disable=protected-access
-        i = self.expect('(?i)(?:password)', timeout=login_timeout)
-        if i == 0:
-            self.sendline(password)
-            i = self.expect([original_prompt, 'Login incorrect'], timeout=login_timeout)
-        else:
-            raise pxssh.ExceptionPxssh('could not log in: did not see a password prompt')
-
-        if i:
-            raise pxssh.ExceptionPxssh('could not log in: password was incorrect')
+        try:
+            i = self.expect('(?i)(?:password)', timeout=login_timeout)
+            if i == 0:
+                self.sendline(password)
+                i = self.expect([original_prompt, 'Login incorrect'], timeout=login_timeout)
+            if i:
+                raise pxssh.ExceptionPxssh('could not log in: password was incorrect')
+        except TIMEOUT:
+            if not password:
+                # There was no password prompt before TIMEOUT, and we didn't
+                # have a password to enter. Assume everything is OK.
+                pass
+            else:
+                raise pxssh.ExceptionPxssh('could not log in: did not see a password prompt')
 
         if not self.sync_original_prompt(sync_multiplier):
             self.close()