From 48c9a45ce3c2fbf40b087a581b4670f75df8f4c7 Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Thu, 27 Jul 2017 12:39:29 +0200 Subject: [PATCH] Fix encoding for pexpect with Python 3.6 --- fence/agents/lib/fencing.py.py | 15 +++++++++++++-- fence/agents/lib/fencing_snmp.py.py | 4 ++-- fence/agents/vmware/fence_vmware.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 4001787d..d2b7f033 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -472,9 +472,11 @@ } class fspawn(pexpect.spawn): - def __init__(self, options, command): + def __init__(self, options, command, **kwargs): + if sys.version_info[0] > 2: + kwargs.setdefault('encoding', 'utf-8') logging.info("Running command: %s", command) - pexpect.spawn.__init__(self, command) + pexpect.spawn.__init__(self, command, **kwargs) self.opt = options def log_expect(self, pattern, timeout): @@ -490,6 +492,15 @@ def send(self, message): def send_eol(self, message): return self.send(message + self.opt["eol"]) +def frun(command, timeout=30, withexitstatus=False, events=None, + extra_args=None, logfile=None, cwd=None, env=None, **kwargs): + if sys.version_info[0] > 2: + kwargs.setdefault('encoding', 'utf-8') + return pexpect.run(command, timeout=timeout, + withexitstatus=withexitstatus, events=events, + extra_args=extra_args, logfile=logfile, cwd=cwd, + env=env, **kwargs) + def atexit_handler(): try: sys.stdout.close() diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py index 9aaf52be..6d9e2110 100644 --- a/fence/agents/lib/fencing_snmp.py.py +++ b/fence/agents/lib/fencing_snmp.py.py @@ -5,7 +5,7 @@ import re, pexpect import logging from fencing import * -from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay +from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay, frun __all__ = ['FencingSnmp'] @@ -87,7 +87,7 @@ def run_command(self, command, additional_timemout=0): try: logging.debug("%s\n", command) - (res_output, res_code) = pexpect.run(command, + (res_output, res_code) = frun(command, int(self.options["--shell-timeout"]) + int(self.options["--login-timeout"]) + additional_timemout, True) diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 8bb061e4..6b60b5e5 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -27,7 +27,7 @@ import atexit sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * -from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay +from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay, frun #BEGIN_VERSION_GENERATION RELEASE_VERSION="VMware Agent using VI Perl API and/or VIX vmrun command" @@ -146,7 +146,7 @@ def vmware_run_command(options, add_login_params, additional_params, additional_ try: logging.debug("%s\n", command) - (res_output, res_code) = pexpect.run(command, + (res_output, res_code) = frun(command, int(options["--shell-timeout"]) + int(options["--login-timeout"]) + additional_timeout, True) if res_code == None: