URL: https://github.com/freeipa/freeipa/pull/5679
Author: abbra
 Title: #5679: [Backport][ipa-4-8] ipatests: allocate pseudo-terminal only for 
specific command
Action: opened

PR body:
"""
This PR was opened automatically because PR #5650 was pushed to master and 
backport to ipa-4-8 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/5679/head:pr5679
git checkout pr5679
From efb99898c9ba167cd9a28788902b00a228de29ae Mon Sep 17 00:00:00 2001
From: Sergey Orlov <sor...@redhat.com>
Date: Fri, 19 Mar 2021 16:02:34 +0100
Subject: [PATCH 1/2] ipatests: allocate pseudo-terminal only for specific
 command

While "ktutil" does require a pseudo-terminal on particular systems to
operate, majority of programs do not need it.
At the same time invoking `ssh` with forced pseudo-terminal allocation
interferes with sessions multiplexing feature and increases connection
time. The increase can be as large as 10 seconds in certain cases which
leads to unexpected EOFs of pexpect utility.
---
 ipatests/pytest_ipa/integration/host.py      | 8 +++++---
 ipatests/pytest_ipa/integration/tasks.py     | 3 ++-
 ipatests/pytest_ipa/integration/transport.py | 6 ++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ipatests/pytest_ipa/integration/host.py b/ipatests/pytest_ipa/integration/host.py
index bcadcbae2c4..e85cbc87e8c 100644
--- a/ipatests/pytest_ipa/integration/host.py
+++ b/ipatests/pytest_ipa/integration/host.py
@@ -204,9 +204,11 @@ def run_command(self, argv, set_env=True, stdin_text=None,
         else:
             return result
 
-    def spawn_expect(self, argv, default_timeout=10, encoding='utf-8'):
-        """Run command on host using IpaTestExpect"""
-        return self.transport.spawn_expect(argv, default_timeout, encoding)
+    def spawn_expect(self, argv, default_timeout=10, encoding='utf-8',
+                     extra_ssh_options=None):
+        """Run command on remote host using IpaTestExpect"""
+        return self.transport.spawn_expect(argv, default_timeout, encoding,
+                                           extra_ssh_options)
 
 class WinHost(pytest_multihost.host.WinHost):
     """
diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
index dc686bc500d..fe2d7ade70f 100755
--- a/ipatests/pytest_ipa/integration/tasks.py
+++ b/ipatests/pytest_ipa/integration/tasks.py
@@ -2166,7 +2166,8 @@ def get_keytab_mtime():
 
         mtime_before = get_keytab_mtime()
 
-        with self.host.spawn_expect(paths.KTUTIL, default_timeout=5) as e:
+        with self.host.spawn_expect(paths.KTUTIL, default_timeout=5,
+                                    extra_ssh_options=['-t']) as e:
             e.expect_exact('ktutil:')
             e.sendline('rkt {}'.format(keytab))
             e.expect_exact('ktutil:')
diff --git a/ipatests/pytest_ipa/integration/transport.py b/ipatests/pytest_ipa/integration/transport.py
index f12df122542..61aba86b618 100644
--- a/ipatests/pytest_ipa/integration/transport.py
+++ b/ipatests/pytest_ipa/integration/transport.py
@@ -49,9 +49,11 @@ def _get_ssh_argv(self):
 
         return argv
 
-    def spawn_expect(self, argv, default_timeout, encoding):
+    def spawn_expect(self, argv, default_timeout, encoding, extra_ssh_options):
         self.log.debug('Starting pexpect ssh session')
         if isinstance(argv, str):
             argv = [argv]
-        argv = self._get_ssh_argv() + ['-t', '-q'] + argv
+        if extra_ssh_options is None:
+            extra_ssh_options = []
+        argv = self._get_ssh_argv() + ['-q'] + extra_ssh_options + argv
         return IpaTestExpect(argv, default_timeout, encoding)

From 5d1d62520ce523aeb5ce5730ad6437e961352a24 Mon Sep 17 00:00:00 2001
From: Sergey Orlov <sor...@redhat.com>
Date: Mon, 22 Mar 2021 17:25:26 +0100
Subject: [PATCH 2/2] ipatests: log command spawned by pexpect

---
 ipatests/pytest_ipa/integration/expect.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ipatests/pytest_ipa/integration/expect.py b/ipatests/pytest_ipa/integration/expect.py
index 85350a10638..5490a99bb41 100644
--- a/ipatests/pytest_ipa/integration/expect.py
+++ b/ipatests/pytest_ipa/integration/expect.py
@@ -68,6 +68,8 @@ def __init__(self, argv, default_timeout=10, encoding='utf-8'):
         else:
             command = argv[0]
             args = argv[1:]
+        logger.debug('Expect will spawn command "%s" with args %s',
+                     command, args)
         super().__init__(
             command, args, timeout=default_timeout, encoding=encoding,
             echo=False
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to