]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
runner: More extensive Python 3 universal_newline fixes
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 5 Jan 2024 21:48:39 +0000 (21:48 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 8 Jan 2024 14:40:12 +0000 (14:40 +0000)
When pv32pae is disabled e.g. due to CET being active, under Python 3, we
still get:

  Executing 'xl create -p tests/example/test-pv32pae-example.cfg'
  b'Parsing config from tests/example/test-pv32pae-example.cfg\nlibxl: error: ...\n'
  Error: Failed to create VM

out, rather than `xl create`'s stdout/stderr rendered nicely.

All subprocess invocations we make will want universal_newlines, so wrap the
functions to have it active by default, but still allow it to be explicitly
turned off by passing universal_newlines = None.

Reinstate the use of check_output() now that we've upped the minimum python
version to 2.7.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
xtf-runner

index 87ae321c631d53fc37bbbdfa9aa43ca5377b0d40..b6f26fd6c28d7130fd5bd44bccf42147324a1153 100755 (executable)
@@ -11,15 +11,24 @@ from __future__ import print_function, unicode_literals
 
 import json
 import sys, os, os.path as path
+import subprocess
 
+from functools import partial
 from optparse import OptionParser
-from subprocess import Popen, PIPE, call as subproc_call
+from subprocess import PIPE
 
 
 # Python 2/3 compatibility
 if sys.version_info >= (3, ):
     basestring = str
 
+
+# Wrap Subprocess functions to use universal_newlines by default
+Popen        = partial(subprocess.Popen, universal_newlines = True)
+subproc_call = partial(subprocess.call, universal_newlines = True)
+check_output = partial(subprocess.check_output, universal_newlines = True)
+
+
 # All results of a test, keep in sync with C code report.h.
 # Notes:
 #  - WARNING is not a result on its own.
@@ -400,10 +409,7 @@ def interpret_selection(opts):
 
         host_envs = []
 
-        cmd = Popen(['xl', 'info'], stdout = PIPE, universal_newlines = True)
-        stdout, _ = cmd.communicate()
-
-        for line in stdout.splitlines():
+        for line in check_output(['xl', 'info']).splitlines():
             if not line.startswith("xen_caps"):
                 continue
 
@@ -493,7 +499,7 @@ def run_test_console(opts, test):
     if console.returncode:
         raise RunnerError("Failed to obtain VM console")
 
-    lines = stdout.decode("utf-8").splitlines()
+    lines = stdout.splitlines()
 
     if lines:
         if not opts.quiet: