]> Git Repo - qemu.git/blobdiff - tests/qemu-iotests/qcow2.py
iotests: add test 226 for file driver types
[qemu.git] / tests / qemu-iotests / qcow2.py
index 2058596964219f22d89afce14c63ba6020ac0544..b95a837759440989890351d4f2dfeab8589f8b8e 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+from __future__ import print_function
 import sys
 import struct
 import string
@@ -7,6 +8,10 @@ import string
 class QcowHeaderExtension:
 
     def __init__(self, magic, length, data):
+        if length % 8 != 0:
+            padding = 8 - (length % 8)
+            data += "\0" * padding
+
         self.magic  = magic
         self.length = length
         self.data   = data
@@ -125,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:
@@ -137,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):
@@ -153,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)
@@ -169,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)
@@ -184,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)
@@ -196,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)
@@ -207,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)
@@ -218,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)
@@ -244,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:
This page took 0.036539 seconds and 4 git commands to generate.