diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2018-06-12 11:56:20 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2018-06-12 11:56:21 +0100 |
commit | 5eca450b2ec219c4256062bfb5498c726c1ed0a4 (patch) | |
tree | 63bbbeb6fe3e21017c07eced27ee5ba34dc2d550 /tests | |
parent | 6e3bd769916e643d371882da1bda5fbd453d3c3b (diff) | |
parent | c7883412440905b41dde7e70f4af782932e80e90 (diff) | |
download | qemu-5eca450b2ec219c4256062bfb5498c726c1ed0a4.zip qemu-5eca450b2ec219c4256062bfb5498c726c1ed0a4.tar.gz qemu-5eca450b2ec219c4256062bfb5498c726c1ed0a4.tar.bz2 |
Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging
Python queue, 2018-06-11
* Make code compatible with Python 3 using 'futurize --stage1'
* Require Python >= 2.7 and remove Python 2.6 compatibility
modules
# gpg: Signature made Mon 11 Jun 2018 18:41:26 BST
# gpg: using RSA key 2807936F984DC5A6
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>"
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6
* remotes/ehabkost/tags/python-next-pull-request:
python: Remove scripts/ordereddict.py
python: Remove scripts/argparse.py
configure: Require Python 2.7 or newer
python: futurize -f lib2to3.fixes.fix_numliterals
python: futurize -f lib2to3.fixes.fix_except
python: futurize -f lib2to3.fixes.fix_renames
python: futurize -f lib2to3.fixes.fix_tuple_params
python: futurize -f lib2to3.fixes.fix_reduce
python: futurize -f lib2to3.fixes.fix_standarderror
python: futurize -f lib2to3.fixes.fix_has_key
python: futurize -f libfuturize.fixes.fix_next_call
python: futurize -f libfuturize.fixes.fix_absolute_import
python: futurize -f libfuturize.fixes.fix_print_with_import
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.include | 1 | ||||
-rwxr-xr-x | tests/docker/docker.py | 17 | ||||
-rwxr-xr-x | tests/docker/travis.py | 15 | ||||
-rw-r--r-- | tests/guest-debug/test-gdbstub.py | 1 | ||||
-rw-r--r-- | tests/image-fuzzer/qcow2/__init__.py | 3 | ||||
-rw-r--r-- | tests/image-fuzzer/qcow2/fuzz.py | 1 | ||||
-rw-r--r-- | tests/image-fuzzer/qcow2/layout.py | 3 | ||||
-rwxr-xr-x | tests/image-fuzzer/runner.py | 42 | ||||
-rw-r--r-- | tests/migration/guestperf/engine.py | 29 | ||||
-rw-r--r-- | tests/migration/guestperf/plot.py | 17 | ||||
-rw-r--r-- | tests/migration/guestperf/shell.py | 19 | ||||
-rwxr-xr-x | tests/qemu-iotests/093 | 2 | ||||
-rwxr-xr-x | tests/qemu-iotests/096 | 4 | ||||
-rwxr-xr-x | tests/qemu-iotests/118 | 24 | ||||
-rwxr-xr-x | tests/qemu-iotests/136 | 2 | ||||
-rwxr-xr-x | tests/qemu-iotests/149 | 3 | ||||
-rwxr-xr-x | tests/qemu-iotests/165 | 3 | ||||
-rw-r--r-- | tests/qemu-iotests/iotests.py | 5 | ||||
-rwxr-xr-x | tests/qemu-iotests/nbd-fault-injector.py | 7 | ||||
-rwxr-xr-x | tests/qemu-iotests/qcow2.py | 39 | ||||
-rwxr-xr-x | tests/qemu-iotests/qed.py | 17 | ||||
-rwxr-xr-x | tests/vm/basevm.py | 3 |
22 files changed, 133 insertions, 124 deletions
diff --git a/tests/Makefile.include b/tests/Makefile.include index d098a10..bb08e37 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -31,7 +31,6 @@ $(SRC_PATH)/scripts/qapi/types.py \ $(SRC_PATH)/scripts/qapi/visit.py \ $(SRC_PATH)/scripts/qapi/common.py \ $(SRC_PATH)/scripts/qapi/doc.py \ -$(SRC_PATH)/scripts/ordereddict.py \ $(SRC_PATH)/scripts/qapi-gen.py # Get the list of all supported sysemu targets diff --git a/tests/docker/docker.py b/tests/docker/docker.py index f826758..306e14c 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -11,6 +11,7 @@ # or (at your option) any later version. See the COPYING file in # the top-level directory. +from __future__ import print_function import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), @@ -87,7 +88,7 @@ def _get_so_libs(executable): so_lib = search.groups()[1] libs.append("%s/%s" % (so_path, so_lib)) except subprocess.CalledProcessError: - print "%s had no associated libraries (static build?)" % (executable) + print("%s had no associated libraries (static build?)" % (executable)) return libs @@ -161,7 +162,7 @@ class Docker(object): continue if only_known and instance_uuid not in self._instances: continue - print "Terminating", i + print("Terminating", i) if active: self._do(["kill", i]) self._do(["rm", i]) @@ -288,7 +289,7 @@ class BuildCommand(SubCommand): if "--no-cache" not in argv and \ dkr.image_matches_dockerfile(tag, dockerfile): if not args.quiet: - print "Image is up to date." + print("Image is up to date.") else: # Create a docker context directory for the build docker_dir = tempfile.mkdtemp(prefix="docker_build") @@ -300,10 +301,10 @@ class BuildCommand(SubCommand): rc = subprocess.call(os.path.realpath(docker_pre), cwd=docker_dir, stdout=stdout) if rc == 3: - print "Skip" + print("Skip") return 0 elif rc != 0: - print "%s exited with code %d" % (docker_pre, rc) + print("%s exited with code %d" % (docker_pre, rc)) return 1 # Copy any extra files into the Docker context. These can be @@ -399,11 +400,11 @@ class ProbeCommand(SubCommand): try: docker = Docker() if docker._command[0] == "docker": - print "yes" + print("yes") elif docker._command[0] == "sudo": - print "sudo" + print("sudo") except Exception: - print "no" + print("no") return diff --git a/tests/docker/travis.py b/tests/docker/travis.py index 703a7fd..ea1ef16 100755 --- a/tests/docker/travis.py +++ b/tests/docker/travis.py @@ -11,6 +11,7 @@ # or (at your option) any later version. See the COPYING file in # the top-level directory. +from __future__ import print_function import sys import yaml import itertools @@ -34,14 +35,14 @@ def main(): sys.stderr.write("Usage: %s <travis-file>\n" % sys.argv[0]) return 1 conf = load_yaml(sys.argv[1]) - print "\n".join((": ${%s}" % var for var in conf["env"]["global"])) + print("\n".join((": ${%s}" % var for var in conf["env"]["global"]))) for config in conf_iter(conf): - print "(" - print "\n".join(config["env"]) - print "alias cc=" + config["compiler"] - print "\n".join(conf["before_script"]) - print "\n".join(conf["script"]) - print ")" + print("(") + print("\n".join(config["env"])) + print("alias cc=" + config["compiler"]) + print("\n".join(conf["before_script"])) + print("\n".join(conf["script"])) + print(")") return 0 if __name__ == "__main__": diff --git a/tests/guest-debug/test-gdbstub.py b/tests/guest-debug/test-gdbstub.py index 31ba6c9..474d2c5 100644 --- a/tests/guest-debug/test-gdbstub.py +++ b/tests/guest-debug/test-gdbstub.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # This script needs to be run on startup # qemu -kernel ${KERNEL} -s -S diff --git a/tests/image-fuzzer/qcow2/__init__.py b/tests/image-fuzzer/qcow2/__init__.py index e2ebe19..09ef598 100644 --- a/tests/image-fuzzer/qcow2/__init__.py +++ b/tests/image-fuzzer/qcow2/__init__.py @@ -1 +1,2 @@ -from layout import create_image +from __future__ import absolute_import +from .layout import create_image diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fuzz.py index 20eba6b..abc4f06 100644 --- a/tests/image-fuzzer/qcow2/fuzz.py +++ b/tests/image-fuzzer/qcow2/fuzz.py @@ -17,6 +17,7 @@ # import random +from functools import reduce UINT8 = 0xff UINT16 = 0xffff diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py index 63e801f..675877d 100644 --- a/tests/image-fuzzer/qcow2/layout.py +++ b/tests/image-fuzzer/qcow2/layout.py @@ -16,9 +16,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import absolute_import import random import struct -import fuzz +from . import fuzz from math import ceil from os import urandom from itertools import chain diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index 96a1c11..95d84f3 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import sys import os import signal @@ -36,9 +37,8 @@ except ImportError: try: import simplejson as json except ImportError: - print >>sys.stderr, \ - "Warning: Module for JSON processing is not found.\n" \ - "'--config' and '--command' options are not supported." + print("Warning: Module for JSON processing is not found.\n" \ + "'--config' and '--command' options are not supported.", file=sys.stderr) # Backing file sizes in MB MAX_BACKING_FILE_SIZE = 10 @@ -128,7 +128,7 @@ class TestEnv(object): if seed is not None: self.seed = seed else: - self.seed = str(random.randint(0, sys.maxint)) + self.seed = str(random.randint(0, sys.maxsize)) random.seed(self.seed) self.init_path = os.getcwd() @@ -158,9 +158,8 @@ class TestEnv(object): try: os.makedirs(self.current_dir) except OSError as e: - print >>sys.stderr, \ - "Error: The working directory '%s' cannot be used. Reason: %s"\ - % (self.work_dir, e[1]) + print("Error: The working directory '%s' cannot be used. Reason: %s"\ + % (self.work_dir, e[1]), file=sys.stderr) raise TestException self.log = open(os.path.join(self.current_dir, "test.log"), "w") self.parent_log = open(run_log, "a") @@ -277,7 +276,7 @@ class TestEnv(object): if __name__ == '__main__': def usage(): - print """ + print(""" Usage: runner.py [OPTION...] TEST_DIR IMG_GENERATOR Set up test environment in TEST_DIR and run a test in it. A module for @@ -326,7 +325,7 @@ if __name__ == '__main__': If '--config' argument is specified, fields not listed in the configuration array will not be fuzzed. - """ + """) def run_test(test_id, seed, work_dir, run_log, cleanup, log_all, command, fuzz_config): @@ -357,8 +356,7 @@ if __name__ == '__main__': ['command=', 'help', 'seed=', 'config=', 'keep_passed', 'verbose', 'duration=']) except getopt.error as e: - print >>sys.stderr, \ - "Error: %s\n\nTry 'runner.py --help' for more information" % e + print("Error: %s\n\nTry 'runner.py --help' for more information" % e, file=sys.stderr) sys.exit(1) command = None @@ -375,9 +373,8 @@ if __name__ == '__main__': try: command = json.loads(arg) except (TypeError, ValueError, NameError) as e: - print >>sys.stderr, \ - "Error: JSON array of test commands cannot be loaded.\n" \ - "Reason: %s" % e + print("Error: JSON array of test commands cannot be loaded.\n" \ + "Reason: %s" % e, file=sys.stderr) sys.exit(1) elif opt in ('-k', '--keep_passed'): cleanup = False @@ -391,15 +388,13 @@ if __name__ == '__main__': try: config = json.loads(arg) except (TypeError, ValueError, NameError) as e: - print >>sys.stderr, \ - "Error: JSON array with the fuzzer configuration cannot" \ - " be loaded\nReason: %s" % e + print("Error: JSON array with the fuzzer configuration cannot" \ + " be loaded\nReason: %s" % e, file=sys.stderr) sys.exit(1) if not len(args) == 2: - print >>sys.stderr, \ - "Expected two parameters\nTry 'runner.py --help'" \ - " for more information." + print("Expected two parameters\nTry 'runner.py --help'" \ + " for more information.", file=sys.stderr) sys.exit(1) work_dir = os.path.realpath(args[0]) @@ -415,9 +410,8 @@ if __name__ == '__main__': try: image_generator = __import__(generator_name) except ImportError as e: - print >>sys.stderr, \ - "Error: The image generator '%s' cannot be imported.\n" \ - "Reason: %s" % (generator_name, e) + print("Error: The image generator '%s' cannot be imported.\n" \ + "Reason: %s" % (generator_name, e), file=sys.stderr) sys.exit(1) # Enable core dumps @@ -428,7 +422,7 @@ if __name__ == '__main__': test_id = count(1) while should_continue(duration, start_time): try: - run_test(str(test_id.next()), seed, work_dir, run_log, cleanup, + run_test(str(next(test_id)), seed, work_dir, run_log, cleanup, log_all, command, config) except (KeyboardInterrupt, SystemExit): sys.exit(1) diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestperf/engine.py index e14d432..398e3f2 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # Migration test main engine # @@ -117,7 +118,7 @@ class Engine(object): # XXX how to get dst timings on remote host ? if self._verbose: - print "Sleeping %d seconds for initial guest workload run" % self._sleep + print("Sleeping %d seconds for initial guest workload run" % self._sleep) sleep_secs = self._sleep while sleep_secs > 1: src_qemu_time.append(self._cpu_timing(src_pid)) @@ -126,7 +127,7 @@ class Engine(object): sleep_secs -= 1 if self._verbose: - print "Starting migration" + print("Starting migration") if scenario._auto_converge: resp = src.command("migrate-set-capabilities", capabilities = [ @@ -216,7 +217,7 @@ class Engine(object): if progress._status == "completed": if self._verbose: - print "Sleeping %d seconds for final guest workload run" % self._sleep + print("Sleeping %d seconds for final guest workload run" % self._sleep) sleep_secs = self._sleep while sleep_secs > 1: time.sleep(1) @@ -227,23 +228,23 @@ class Engine(object): return [progress_history, src_qemu_time, src_vcpu_time] if self._verbose and (loop % 20) == 0: - print "Iter %d: remain %5dMB of %5dMB (total %5dMB @ %5dMb/sec)" % ( + print("Iter %d: remain %5dMB of %5dMB (total %5dMB @ %5dMb/sec)" % ( progress._ram._iterations, progress._ram._remaining_bytes / (1024 * 1024), progress._ram._total_bytes / (1024 * 1024), progress._ram._transferred_bytes / (1024 * 1024), progress._ram._transfer_rate_mbs, - ) + )) if progress._ram._iterations > scenario._max_iters: if self._verbose: - print "No completion after %d iterations over RAM" % scenario._max_iters + print("No completion after %d iterations over RAM" % scenario._max_iters) src.command("migrate_cancel") continue if time.time() > (start + scenario._max_time): if self._verbose: - print "No completion after %d seconds" % scenario._max_time + print("No completion after %d seconds" % scenario._max_time) src.command("migrate_cancel") continue @@ -251,7 +252,7 @@ class Engine(object): progress._ram._iterations >= scenario._post_copy_iters and not post_copy): if self._verbose: - print "Switching to post-copy after %d iterations" % scenario._post_copy_iters + print("Switching to post-copy after %d iterations" % scenario._post_copy_iters) resp = src.command("migrate-start-postcopy") post_copy = True @@ -259,7 +260,7 @@ class Engine(object): progress._ram._iterations >= scenario._pause_iters and not paused): if self._verbose: - print "Pausing VM after %d iterations" % scenario._pause_iters + print("Pausing VM after %d iterations" % scenario._pause_iters) resp = src.command("stop") paused = True @@ -348,7 +349,7 @@ class Engine(object): if not log: return [] if self._debug: - print log + print(log) regex = r"[^\s]+\s\((\d+)\):\sINFO:\s(\d+)ms\scopied\s\d+\sGB\sin\s(\d+)ms" matcher = re.compile(regex) @@ -407,7 +408,7 @@ class Engine(object): if uri[0:5] == "unix:": os.remove(uri[5:]) if self._verbose: - print "Finished migration" + print("Finished migration") src.shutdown() dst.shutdown() @@ -420,7 +421,7 @@ class Engine(object): self._initrd, self._transport, self._sleep) except Exception as e: if self._debug: - print "Failed: %s" % str(e) + print("Failed: %s" % str(e)) try: src.shutdown() except: @@ -431,7 +432,7 @@ class Engine(object): pass if self._debug: - print src.get_log() - print dst.get_log() + print(src.get_log()) + print(dst.get_log()) raise diff --git a/tests/migration/guestperf/plot.py b/tests/migration/guestperf/plot.py index bc42249..aa98912 100644 --- a/tests/migration/guestperf/plot.py +++ b/tests/migration/guestperf/plot.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # Migration test graph plotting # @@ -588,7 +589,7 @@ class Plot(object): """ def generate_html(self, fh): - print >>fh, """<html> + print("""<html> <head> <script type="text/javascript" src="plotly.min.js"> </script> @@ -601,19 +602,19 @@ class Plot(object): <h1>Migration report</h1> <h2>Chart summary</h2> <div id="chart"> -""" % self._generate_style() - print >>fh, self._generate_chart() - print >>fh, """ +""" % self._generate_style(), file=fh) + print(self._generate_chart(), file=fh) + print(""" </div> <h2>Report details</h2> <div id="report"> -""" - print >>fh, self._generate_report() - print >>fh, """ +""", file=fh) + print(self._generate_report(), file=fh) + print(""" </div> </body> </html> -""" +""", file=fh) def generate(self, filename): if filename is None: diff --git a/tests/migration/guestperf/shell.py b/tests/migration/guestperf/shell.py index b272978..a6b8cec 100644 --- a/tests/migration/guestperf/shell.py +++ b/tests/migration/guestperf/shell.py @@ -1,3 +1,4 @@ +from __future__ import print_function # # Migration test command line shell integration # @@ -160,13 +161,13 @@ class Shell(BaseShell): try: report = engine.run(hardware, scenario) if args.output is None: - print report.to_json() + print(report.to_json()) else: with open(args.output, "w") as fh: - print >>fh, report.to_json() + print(report.to_json(), file=fh) return 0 except Exception as e: - print >>sys.stderr, "Error: %s" % str(e) + print("Error: %s" % str(e), file=sys.stderr) if args.debug: raise return 1 @@ -199,11 +200,11 @@ class BatchShell(BaseShell): name = os.path.join(comparison._name, scenario._name) if not fnmatch.fnmatch(name, args.filter): if args.verbose: - print "Skipping %s" % name + print("Skipping %s" % name) continue if args.verbose: - print "Running %s" % name + print("Running %s" % name) dirname = os.path.join(args.output, comparison._name) filename = os.path.join(dirname, scenario._name + ".json") @@ -211,9 +212,9 @@ class BatchShell(BaseShell): os.makedirs(dirname) report = engine.run(hardware, scenario) with open(filename, "w") as fh: - print >>fh, report.to_json() + print(report.to_json(), file=fh) except Exception as e: - print >>sys.stderr, "Error: %s" % str(e) + print("Error: %s" % str(e), file=sys.stderr) if args.debug: raise @@ -246,14 +247,14 @@ class PlotShell(object): if len(args.reports) == 0: - print >>sys.stderr, "At least one report required" + print("At least one report required", file=sys.stderr) return 1 if not (args.qemu_cpu or args.vcpu_cpu or args.total_guest_cpu or args.split_guest_cpu): - print >>sys.stderr, "At least one chart type is required" + print("At least one chart type is required", file=sys.stderr) return 1 reports = [] diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093 index c3404a3..68e344f 100755 --- a/tests/qemu-iotests/093 +++ b/tests/qemu-iotests/093 @@ -237,7 +237,7 @@ class ThrottleTestGroupNames(iotests.QMPTestCase): if name: self.assertEqual(info["group"], name) else: - self.assertFalse(info.has_key('group')) + self.assertFalse('group' in info) return raise Exception("No group information found for '%s'" % device) diff --git a/tests/qemu-iotests/096 b/tests/qemu-iotests/096 index aeeb375..a694396 100755 --- a/tests/qemu-iotests/096 +++ b/tests/qemu-iotests/096 @@ -53,9 +53,9 @@ class TestLiveSnapshot(iotests.QMPTestCase): self.assertEqual(r['iops'], self.iops) self.assertEqual(r['iops_size'], self.iops_size) else: - self.assertFalse(r.has_key('group')) + self.assertFalse('group' in r) self.assertEqual(r['iops'], 0) - self.assertFalse(r.has_key('iops_size')) + self.assertFalse('iops_size' in r) def testSnapshot(self): self.checkConfig('base') diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index a0469b5..ff3b2ae 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -390,14 +390,14 @@ class TestChangeReadOnly(ChangeBaseClass): def tearDown(self): self.vm.shutdown() - os.chmod(old_img, 0666) - os.chmod(new_img, 0666) + os.chmod(old_img, 0o666) + os.chmod(new_img, 0o666) os.remove(old_img) os.remove(new_img) def test_ro_ro_retain(self): - os.chmod(old_img, 0444) - os.chmod(new_img, 0444) + os.chmod(old_img, 0o444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -417,7 +417,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_ro_rw_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -437,7 +437,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -459,7 +459,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_ro_rw(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -480,7 +480,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_rw_ro(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -521,7 +521,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -542,7 +542,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_make_rw_ro_by_retain(self): - os.chmod(old_img, 0444) + os.chmod(old_img, 0o444) self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -562,7 +562,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img) def test_make_ro_rw_by_retain(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() @@ -582,7 +582,7 @@ class TestChangeReadOnly(ChangeBaseClass): self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img) def test_rw_ro_cycle(self): - os.chmod(new_img, 0444) + os.chmod(new_img, 0o444) self.vm.add_drive(old_img, 'media=disk', 'none') self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name) self.vm.launch() diff --git a/tests/qemu-iotests/136 b/tests/qemu-iotests/136 index 88b97ea..a154d8e 100755 --- a/tests/qemu-iotests/136 +++ b/tests/qemu-iotests/136 @@ -203,7 +203,7 @@ sector = "%d" if (self.accounted_ops(read = True, write = True, flush = True) != 0): self.assertLess(0, stats['idle_time_ns']) else: - self.assertFalse(stats.has_key('idle_time_ns')) + self.assertFalse('idle_time_ns' in stats) # This test does not alter these, so they must be all 0 self.assertEqual(0, stats['rd_merged']) diff --git a/tests/qemu-iotests/149 b/tests/qemu-iotests/149 index 223cd68..d3ffa25 100755 --- a/tests/qemu-iotests/149 +++ b/tests/qemu-iotests/149 @@ -20,6 +20,7 @@ # Exercise the QEMU 'luks' block driver to validate interoperability # with the Linux dm-crypt + cryptsetup implementation +from __future__ import print_function import subprocess import os import os.path @@ -376,7 +377,7 @@ def test_once(config, qemu_img=False): finally: iotests.log("# Delete image") delete_image(config) - print + print() # Obviously we only work with the luks image format diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 index 2936929..88f62d3 100755 --- a/tests/qemu-iotests/165 +++ b/tests/qemu-iotests/165 @@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +from __future__ import print_function import os import re import iotests @@ -85,7 +86,7 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) if log: - print log + print(log) self.vm = self.mkVm() self.vm.launch() diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 2f22fab..4e67fbb 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Common utilities and Python wrappers for qemu-iotests # # Copyright (C) 2012 IBM Corp. @@ -248,7 +249,7 @@ def filter_img_info(output, filename): def log(msg, filters=[]): for flt in filters: msg = flt(msg) - print msg + print(msg) class Timeout: def __init__(self, seconds, errmsg = "Timeout"): @@ -613,7 +614,7 @@ def notrun(reason): seq = os.path.basename(sys.argv[0]) open('%s/%s.notrun' % (output_dir, seq), 'wb').write(reason + '\n') - print '%s not run: %s' % (seq, reason) + print('%s not run: %s' % (seq, reason)) sys.exit(0) def verify_image_format(supported_fmts=[], unsupported_fmts=[]): diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/nbd-fault-injector.py index 8a04d97..f9193c0 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -43,6 +43,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +from __future__ import print_function import sys import socket import struct @@ -110,7 +111,7 @@ class FaultInjectionSocket(object): for rule in self.rules: if rule.match(event, io): if rule.when == 0 or bufsize is None: - print 'Closing connection on rule match %s' % rule.name + print('Closing connection on rule match %s' % rule.name) sys.exit(0) if rule.when != -1: return rule.when @@ -182,7 +183,7 @@ def handle_connection(conn, use_export): elif req.type == NBD_CMD_DISC: break else: - print 'unrecognized command type %#02x' % req.type + print('unrecognized command type %#02x' % req.type) break conn.close() @@ -242,7 +243,7 @@ def open_socket(path): sock = socket.socket(socket.AF_UNIX) sock.bind(path) sock.listen(0) - print 'Listening on %s' % path + print('Listening on %s' % path) sys.stdout.flush() # another process may be waiting, show message now return sock diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py index 9cc4cf7..b95a837 100755 --- a/tests/qemu-iotests/qcow2.py +++ b/tests/qemu-iotests/qcow2.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import sys import struct import string @@ -129,8 +130,8 @@ class QcowHeader: def dump(self): for f in QcowHeader.fields: - print "%-25s" % f[2], f[1] % self.__dict__[f[2]] - print "" + print("%-25s" % f[2], f[1] % self.__dict__[f[2]]) + print("") def dump_extensions(self): for ex in self.extensions: @@ -141,11 +142,11 @@ class QcowHeader: else: data = "<binary>" - print "Header extension:" - print "%-25s %#x" % ("magic", ex.magic) - print "%-25s %d" % ("length", ex.length) - print "%-25s %s" % ("data", data) - print "" + print("Header extension:") + print("%-25s %#x" % ("magic", ex.magic)) + print("%-25s %d" % ("length", ex.length)) + print("%-25s %s" % ("data", data)) + print("") def cmd_dump_header(fd): @@ -157,12 +158,12 @@ def cmd_set_header(fd, name, value): try: value = int(value, 0) except: - print "'%s' is not a valid number" % value + print("'%s' is not a valid number" % value) sys.exit(1) fields = (field[2] for field in QcowHeader.fields) if not name in fields: - print "'%s' is not a known header field" % name + print("'%s' is not a known header field" % name) sys.exit(1) h = QcowHeader(fd) @@ -173,7 +174,7 @@ def cmd_add_header_ext(fd, magic, data): try: magic = int(magic, 0) except: - print "'%s' is not a valid magic number" % magic + print("'%s' is not a valid magic number" % magic) sys.exit(1) h = QcowHeader(fd) @@ -188,7 +189,7 @@ def cmd_del_header_ext(fd, magic): try: magic = int(magic, 0) except: - print "'%s' is not a valid magic number" % magic + print("'%s' is not a valid magic number" % magic) sys.exit(1) h = QcowHeader(fd) @@ -200,7 +201,7 @@ def cmd_del_header_ext(fd, magic): h.extensions.remove(ex) if not found: - print "No such header extension" + print("No such header extension") return h.update(fd) @@ -211,7 +212,7 @@ def cmd_set_feature_bit(fd, group, bit): if bit < 0 or bit >= 64: raise ValueError except: - print "'%s' is not a valid bit number in range [0, 64)" % bit + print("'%s' is not a valid bit number in range [0, 64)" % bit) sys.exit(1) h = QcowHeader(fd) @@ -222,7 +223,7 @@ def cmd_set_feature_bit(fd, group, bit): elif group == 'autoclear': h.autoclear_features |= 1 << bit else: - print "'%s' is not a valid group, try 'incompatible', 'compatible', or 'autoclear'" % group + print("'%s' is not a valid group, try 'incompatible', 'compatible', or 'autoclear'" % group) sys.exit(1) h.update(fd) @@ -248,16 +249,16 @@ def main(filename, cmd, args): else: handler(fd, *args) return - print "Unknown command '%s'" % cmd + print("Unknown command '%s'" % cmd) finally: fd.close() def usage(): - print "Usage: %s <file> <cmd> [<arg>, ...]" % sys.argv[0] - print "" - print "Supported commands:" + print("Usage: %s <file> <cmd> [<arg>, ...]" % sys.argv[0]) + print("") + print("Supported commands:") for name, handler, num_args, desc in cmds: - print " %-20s - %s" % (name, desc) + print(" %-20s - %s" % (name, desc)) if __name__ == '__main__': if len(sys.argv) < 3: diff --git a/tests/qemu-iotests/qed.py b/tests/qemu-iotests/qed.py index 748068d..ea469b9 100755 --- a/tests/qemu-iotests/qed.py +++ b/tests/qemu-iotests/qed.py @@ -10,6 +10,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +from __future__ import print_function import sys import struct import random @@ -108,12 +109,12 @@ def corrupt_table_invalidate(qed, table): def cmd_show(qed, *args): '''show [header|l1|l2 <offset>]- Show header or l1/l2 tables''' if not args or args[0] == 'header': - print qed.header + print(qed.header) elif args[0] == 'l1': - print qed.l1_table + print(qed.l1_table) elif len(args) == 2 and args[0] == 'l2': offset = int(args[1]) - print qed.read_table(offset) + print(qed.read_table(offset)) else: err('unrecognized sub-command') @@ -146,7 +147,7 @@ def cmd_invalidate(qed, table_level): def cmd_need_check(qed, *args): '''need-check [on|off] - Test, set, or clear the QED_F_NEED_CHECK header bit''' if not args: - print bool(qed.header['features'] & QED_F_NEED_CHECK) + print(bool(qed.header['features'] & QED_F_NEED_CHECK)) return if args[0] == 'on': @@ -208,11 +209,11 @@ def cmd_copy_metadata(qed, outfile): out.close() def usage(): - print 'Usage: %s <file> <cmd> [<arg>, ...]' % sys.argv[0] - print - print 'Supported commands:' + print('Usage: %s <file> <cmd> [<arg>, ...]' % sys.argv[0]) + print() + print('Supported commands:') for cmd in sorted(x for x in globals() if x.startswith('cmd_')): - print globals()[cmd].__doc__ + print(globals()[cmd].__doc__) sys.exit(1) def main(): diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py index 3a2d508..3643117 100755 --- a/tests/vm/basevm.py +++ b/tests/vm/basevm.py @@ -11,6 +11,7 @@ # the COPYING file in the top-level directory. # +from __future__ import print_function import os import sys import logging @@ -222,7 +223,7 @@ def main(vmcls): try: args, argv = parse_args(vmcls.name) if not argv and not args.build_qemu and not args.build_image: - print "Nothing to do?" + print("Nothing to do?") return 1 logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARN)) |