Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if re.split(patterns[match], output[i])[-1]:
output[i] = re.split(patterns[match],
output[i])[-1]
output_slice = output[i:]
else:
output_slice = output[i + 1:]
for j in range(len(output_slice) - 1):
output_slice[j] = output_slice[j] + '\n'
for k in range(len(output_slice)):
out += output_slice[k]
return match, out
return match, o
# Check if the child has terminated
if utils_misc.wait_for(lambda: not self.is_alive(), 5, 0, 0.1):
raise aexpect.ExpectProcessTerminatedError(patterns,
self.get_status(), o)
else:
# This shouldn't happen
raise aexpect.ExpectError(patterns, o)
if re.split(patterns[match], output[i])[-1]:
output[i] = re.split(patterns[match],
output[i])[-1]
output_slice = output[i:]
else:
output_slice = output[i + 1:]
for j in range(len(output_slice) - 1):
output_slice[j] = output_slice[j] + '\n'
for k in range(len(output_slice)):
out += output_slice[k]
return match, out
return match, o
# Check if the child has terminated
if utils_misc.wait_for(lambda: not self.is_alive(), 5, 0, 0.1):
raise aexpect.ExpectProcessTerminatedError(patterns,
self.get_status(), o)
else:
# This shouldn't happen
raise aexpect.ExpectError(patterns, o)
session.sendline(password_list[password_prompt_count])
password_prompt_count += 1
timeout = transfer_timeout
authentication_done = True
continue
else:
raise SCPAuthenticationError("Got password prompt twice",
text)
elif match == 2: # "lost connection"
raise SCPError("SCP client said 'lost connection'", text)
except aexpect.ExpectTimeoutError, e:
if authentication_done:
raise SCPTransferTimeoutError(e.output)
else:
raise SCPAuthenticationTimeoutError(e.output)
except aexpect.ExpectProcessTerminatedError, e:
if e.status == 0:
logging.debug("SCP process terminated with status 0")
break
else:
raise SCPTransferFailedError(e.status, e.output)
elif match == 5: # "Please wait"
if debug:
logging.debug("Got 'Please wait'")
timeout = 30
continue
elif match == 6: # "Warning added RSA"
if debug:
logging.debug("Got 'Warning added RSA to known host list")
continue
elif match == 7: # prompt
if debug:
logging.debug("Got shell prompt -- logged in")
break
except aexpect.ExpectTimeoutError, e:
raise LoginTimeoutError(e.output)
except aexpect.ExpectProcessTerminatedError, e:
raise LoginProcessTerminatedError(e.status, e.output)
session.sendline(password_list[password_prompt_count])
password_prompt_count += 1
timeout = transfer_timeout
authentication_done = True
continue
else:
raise SCPAuthenticationError("Got password prompt twice",
text)
elif match == 2: # "lost connection"
raise SCPError("SCP client said 'lost connection'", text)
except aexpect.ExpectTimeoutError, e:
if authentication_done:
raise SCPTransferTimeoutError(e.output)
else:
raise SCPAuthenticationTimeoutError(e.output)
except aexpect.ExpectProcessTerminatedError, e:
if e.status == 0:
logging.debug("SCP process terminated with status 0")
break
else:
raise SCPTransferFailedError(e.status, e.output)
session.sendline(password_list[password_prompt_count])
password_prompt_count += 1
timeout = transfer_timeout
authentication_done = True
continue
else:
raise SCPAuthenticationError("Got password prompt twice",
text)
elif match == 2: # "lost connection"
raise SCPError("SCP client said 'lost connection'", text)
except aexpect.ExpectTimeoutError as e:
if authentication_done:
raise SCPTransferTimeoutError(e.output)
else:
raise SCPAuthenticationTimeoutError(e.output)
except aexpect.ExpectProcessTerminatedError as e:
if e.status == 0:
logging.debug("SCP process terminated with status 0")
break
else:
raise SCPTransferFailedError(e.status, e.output)
logging.info("SSH key pair already exist")
session = self.runner.session
# To avoid the host key checking
ssh_options = "%s %s" % ("-o UserKnownHostsFile=/dev/null",
"-o StrictHostKeyChecking=no")
session.sendline("ssh-copy-id %s -i %s root@%s"
% (ssh_options, pub_key, vm_ip))
while True:
matched_strs = [r"[Aa]re you sure", r"[Pp]assword:\s*$",
r"lost connection", r"]#"]
try:
index, text = session.read_until_last_line_matches(
matched_strs, timeout=timeout,
internal_timeout=0.5)
except (aexpect.ExpectTimeoutError,
aexpect.ExpectProcessTerminatedError) as e:
raise exceptions.TestFail(
"Setup autologin to vm failed:%s" % e)
logging.debug("%s:%s", index, text)
if index == 0:
logging.debug("Sending 'yes' for fingerprint...")
session.sendline("yes")
continue
elif index == 1:
logging.debug("Sending '%s' for vm logging...", vm_pwd)
session.sendline(vm_pwd)
continue
elif index == 2:
raise exceptions.TestFail("Disconnected to vm on remote host.")
elif index == 3:
logging.debug("Logged in now...")
break
session.sendline(password_list[password_prompt_count])
password_prompt_count += 1
timeout = transfer_timeout
authentication_done = True
continue
else:
raise SCPAuthenticationError("Got password prompt twice",
text)
elif match == 2: # "lost connection"
raise SCPError("SCP client said 'lost connection'", text)
except aexpect.ExpectTimeoutError, e:
if authentication_done:
raise SCPTransferTimeoutError(e.output)
else:
raise SCPAuthenticationTimeoutError(e.output)
except aexpect.ExpectProcessTerminatedError, e:
if e.status == 0:
logging.debug("SCP process terminated with status 0")
break
else:
raise SCPTransferFailedError(e.status, e.output)