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

Move pexpect from a runtime dependency to test #2921

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ py3-mccabe \
py3-netifaces \
py3-paramiko \
py3-pbr \
py3-pexpect \
py3-pip \
py3-pluggy \
py3-psutil \
Expand Down Expand Up @@ -116,7 +115,6 @@ py3-mccabe \
py3-netifaces \
py3-paramiko \
py3-pbr \
py3-pexpect \
py3-pip \
py3-pluggy \
py3-psutil \
Expand Down
20 changes: 2 additions & 18 deletions lib/molecule/command/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@
# DEALINGS IN THE SOFTWARE.
"""Login Command Module."""

import fcntl
import os
import signal
import struct
import sys
import termios
from subprocess import run

import click
import pexpect

from molecule import logger, scenarios, util
from molecule.command import base
Expand Down Expand Up @@ -147,19 +142,8 @@ def _get_login(self, hostname): # pragma: no cover
login_options["lines"] = lines
login_cmd = self._config.driver.login_cmd_template.format(**login_options)

dimensions = (int(lines), int(columns))
cmd = "/usr/bin/env {}".format(login_cmd)
self._pt = pexpect.spawn(cmd, dimensions=dimensions)
Copy link
Member Author

Choose a reason for hiding this comment

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

@retr0h Can you please comment on why the pexpect implementation was added in the first place for the interactive login? I am asking because I would not want to introduce a serious regression just because I do not know the reasons behind original implementation.

I did some basic tests and using subprocess.run() appeared to be working fine for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Possible reason from the docs: "The run() function was added in Python 3.5"

If we previously supported < 3.5, then this call wouldn't have been possible.

signal.signal(signal.SIGWINCH, self._sigwinch_passthrough)
self._pt.interact()

def _sigwinch_passthrough(self, sig, data): # pragma: no cover
tiocgwinsz = 1074295912 # assume
if "TIOCGWINSZ" in dir(termios):
tiocgwinsz = termios.TIOCGWINSZ
s = struct.pack("HHHH", 0, 0, 0, 0)
a = struct.unpack("HHHH", fcntl.ioctl(sys.stdout.fileno(), tiocgwinsz, s))
self._pt.setwinsize(a[0], a[1])
run(cmd, shell=True)


@base.click_command_ex()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ install_requires =
Jinja2 >= 2.10.1
packaging
paramiko >= 2.5.0, < 3
pexpect >= 4.6.0, < 5
pluggy >= 0.7.1, < 1.0
PyYAML >= 5.1, < 6
rich >= 6.0
Expand Down Expand Up @@ -112,6 +111,7 @@ test =
ansi2html

mock>=3.0.5
pexpect >= 4.6.0, < 5
pytest-cov>=2.7.1
pytest-helpers-namespace>=2019.1.8
pytest-html>=1.21.0
Expand Down