URL: https://github.com/freeipa/freeipa/pull/5678
Author: abbra
 Title: #5678: [Backport][ipa-4-9] 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-9 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/5678/head:pr5678
git checkout pr5678
From 0c9cd58809fb5a4bbb4d4c590cbe0efbca25c496 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 1e420dfee47..a9758e7dc77 100644
--- a/ipatests/pytest_ipa/integration/host.py
+++ b/ipatests/pytest_ipa/integration/host.py
@@ -206,9 +206,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 023179a1e06..8c4dd955371 100755
--- a/ipatests/pytest_ipa/integration/tasks.py
+++ b/ipatests/pytest_ipa/integration/tasks.py
@@ -2252,7 +2252,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 1e9e8063ef392436864daa1f7d60df674e1b5e3c 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