Skip to content

Commit bd53ff5

Browse files
committed
shelldriver: Move password handling into main poll loop
Moving the password handling into the main loop allows it to follow the same timeout handling logic as other prompts. Specifically, if no output is seen an empty newline will be sent instead of waiting indefinitely for a timeout. This prevents test timeout errors when other output is intermingled with the password prompting or the main prompt after entering the password. Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
1 parent 0758753 commit bd53ff5

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

labgrid/driver/shelldriver.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _await_login(self):
120120

121121
timeout = Timeout(float(self.login_timeout))
122122

123-
expectations = [self.prompt, self.login_prompt, TIMEOUT]
123+
expectations = [self.prompt, self.login_prompt, "Password: ", TIMEOUT]
124124
if self.console_ready != "":
125125
expectations.append(self.console_ready)
126126

@@ -130,6 +130,7 @@ def _await_login(self):
130130
# Because pexpect keeps any read data in it's buffer when a timeout
131131
# occours, we can't lose any data this way.
132132
last_before = b''
133+
did_login = False
133134

134135
while True:
135136
index, before, _, _ = self.console.expect(
@@ -146,21 +147,15 @@ def _await_login(self):
146147
elif index == 1:
147148
# we need to login
148149
self.console.sendline(self.username)
149-
index, _, _, _ = self.console.expect([self.prompt, "Password: "], timeout=10)
150-
if index == 1:
151-
if self.password:
152-
self.console.sendline(self.password)
153-
self.console.expect(self.prompt, timeout=timeout.remaining)
154-
else:
155-
raise Exception("Password entry needed but no password set")
156-
157-
if self.post_login_settle_time > 0:
158-
self.console.settle(self.post_login_settle_time, timeout=timeout.remaining)
159-
160-
self._check_prompt()
161-
break
150+
did_login = True
162151

163152
elif index == 2:
153+
if self.password:
154+
self.console.sendline(self.password)
155+
else:
156+
raise Exception("Password entry needed but no password set")
157+
158+
elif index == 3:
164159
# expect hit a timeout while waiting for a match
165160
if before == last_before:
166161
# we did not receive anything during
@@ -169,7 +164,7 @@ def _await_login(self):
169164
# newline to check the state
170165
self.console.sendline("")
171166

172-
elif index == 3:
167+
elif index == 4:
173168
# we have just activated a console here
174169
# lets start over again and see if login or prompt will appear
175170
# now.
@@ -180,6 +175,11 @@ def _await_login(self):
180175
if timeout.expired:
181176
raise TIMEOUT("Timeout of {} seconds exceeded during waiting for login".format(self.login_timeout)) # pylint: disable=line-too-long
182177

178+
if did_login:
179+
if self.post_login_settle_time > 0:
180+
self.console.settle(self.post_login_settle_time, timeout=timeout.remaining)
181+
self._check_prompt()
182+
183183
@step()
184184
def get_status(self):
185185
"""Returns the status of the shell-driver.

0 commit comments

Comments
 (0)