]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: fix various py3 cephfs qa bugs 32467/head
authorPatrick Donnelly <pdonnell@redhat.com>
Fri, 3 Jan 2020 04:41:57 +0000 (20:41 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Sat, 4 Jan 2020 00:42:13 +0000 (16:42 -0800)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
qa/tasks/cephfs/mount.py
qa/tasks/cephfs/test_cap_flush.py
qa/tasks/cephfs/test_journal_migration.py
qa/tasks/cephfs/test_pool_perm.py
qa/tasks/cephfs/test_strays.py

index b729d801ab7038b0ca39cb5658f49941f6d4841f..4d7375f6d5c0693dcd21ad4b446d6bdd6149d95f 100644 (file)
@@ -233,20 +233,20 @@ class CephFSMount(object):
             pyscript = dedent("""
                 import time
 
-                f = open("{path}", 'w')
-                f.write('content')
-                f.flush()
-                f.write('content2')
-                while True:
-                    time.sleep(1)
+                with open("{path}", 'w') as f:
+                    f.write('content')
+                    f.flush()
+                    f.write('content2')
+                    while True:
+                        time.sleep(1)
                 """).format(path=path)
         else:
             pyscript = dedent("""
                 import time
 
-                f = open("{path}", 'r')
-                while True:
-                    time.sleep(1)
+                with open("{path}", 'r') as f:
+                    while True:
+                        time.sleep(1)
                 """).format(path=path)
 
         rproc = self._run_python(pyscript)
@@ -357,7 +357,7 @@ class CephFSMount(object):
             f1 = open("{path}-1", 'r')
             try:
                 fcntl.flock(f1, fcntl.LOCK_EX | fcntl.LOCK_NB)
-            except IOError, e:
+            except IOError as e:
                 if e.errno == errno.EAGAIN:
                     pass
             else:
@@ -367,7 +367,7 @@ class CephFSMount(object):
             try:
                 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
                 fcntl.fcntl(f2, fcntl.F_SETLK, lockdata)
-            except IOError, e:
+            except IOError as e:
                 if e.errno == errno.EAGAIN:
                     pass
             else:
@@ -401,7 +401,7 @@ class CephFSMount(object):
                     time.sleep(1)
                     if not {loop}:
                         break
-            except IOError, e:
+            except IOError as e:
                 pass
             os.close(fd)
             """).format(path=path, loop=str(loop))
@@ -427,11 +427,10 @@ class CephFSMount(object):
         return self.run_python(dedent("""
             import zlib
             path = "{path}"
-            f = open(path, 'w')
-            for i in range(0, {size}):
-                val = zlib.crc32("%s" % i) & 7
-                f.write(chr(val))
-            f.close()
+            with open(path, 'w') as f:
+                for i in range(0, {size}):
+                    val = zlib.crc32(str(i).encode('utf-8')) & 7
+                    f.write(chr(val))
         """.format(
             path=os.path.join(self.mountpoint, filename),
             size=size
@@ -442,15 +441,14 @@ class CephFSMount(object):
         return self.run_python(dedent("""
             import zlib
             path = "{path}"
-            f = open(path, 'r')
-            bytes = f.read()
-            f.close()
+            with open(path, 'r') as f:
+                bytes = f.read()
             if len(bytes) != {size}:
                 raise RuntimeError("Bad length {{0}} vs. expected {{1}}".format(
                     len(bytes), {size}
                 ))
             for i, b in enumerate(bytes):
-                val = zlib.crc32("%s" % i) & 7
+                val = zlib.crc32(str(i).encode('utf-8')) & 7
                 if b != chr(val):
                     raise RuntimeError("Bad data at offset {{0}}".format(i))
         """.format(
@@ -511,12 +509,11 @@ class CephFSMount(object):
 
             for i in range(0, n):
                 fname = "{{0}}_{{1}}".format(abs_path, i)
-                h = open(fname, 'w')
-                h.write('content')
-                if {sync}:
-                    h.flush()
-                    os.fsync(h.fileno())
-                h.close()
+                with open(fname, 'w') as f:
+                    f.write('content')
+                    if {sync}:
+                        f.flush()
+                        os.fsync(f.fileno())
             """).format(abs_path=abs_path, count=count, sync=str(sync))
 
         self.run_python(pyscript)
index cea6ff3f9b0c32447233d9ca0186069e166a8526..cb1053681264b089993ee2a10a7aca5059a7eccb 100644 (file)
@@ -23,7 +23,7 @@ class TestCapFlush(CephFSTestCase):
             import os
             os.mkdir("{0}")
             fd = os.open("{0}", os.O_RDONLY)
-            os.fchmod(fd, 0777)
+            os.fchmod(fd, 0o777)
             os.fsync(fd)
             """).format(dir_path)
         self.mount_a.run_python(py_script)
@@ -43,7 +43,7 @@ class TestCapFlush(CephFSTestCase):
             os.setgid(65534)
             os.setuid(65534)
             fd = os.open("{1}", os.O_CREAT | os.O_RDWR, 0644)
-            os.fchmod(fd, 0640)
+            os.fchmod(fd, 0o640)
             """).format(dir_path, file_name)
         self.mount_a.run_python(py_script)
 
index de4867ef0a58073281ac6ba85f216d9c6aa7cf73..9d1d399caa8ed67d4b56d474a36887b0f9c804a2 100644 (file)
@@ -78,7 +78,7 @@ class TestJournalMigration(CephFSTestCase):
                               "--path", "/tmp/journal.json"], 0)
         p = self.fs.tool_remote.run(
             args=[
-                "python",
+                "python3",
                 "-c",
                 "import json; print(len(json.load(open('/tmp/journal.json'))))"
             ],
index f0efc43ec6368275a0dd70d3f4e43699abf3d79d..a1f234a22538bfae7086e5a0ea8eb36d7846fcd7 100644 (file)
@@ -20,7 +20,7 @@ class TestPoolPerm(CephFSTestCase):
                     ret = os.read(fd, 1024)
                 else:
                     os.write(fd, b'content')
-            except OSError, e:
+            except OSError as e:
                 if e.errno != errno.EPERM:
                     raise
             else:
index a294cc46087813dd347028d6c79e3642d4389fec..5dd1524a324f2f8589d1dd4941faeb907fd47086 100644 (file)
@@ -44,11 +44,10 @@ class TestStrays(CephFSTestCase):
             size = {size}
             file_count = {file_count}
             os.mkdir(os.path.join(mount_path, subdir))
-            for i in xrange(0, file_count):
+            for i in range(0, file_count):
                 filename = "{{0}}_{{1}}.bin".format(i, size)
-                f = open(os.path.join(mount_path, subdir, filename), 'w')
-                f.write(size * 'x')
-                f.close()
+                with open(os.path.join(mount_path, subdir, filename), 'w') as f:
+                    f.write(size * 'x')
         """.format(
             mount_path=self.mount_a.mountpoint,
             size=1024,
@@ -151,12 +150,11 @@ class TestStrays(CephFSTestCase):
             size_unit = {size_unit}
             file_multiplier = {file_multiplier}
             os.mkdir(os.path.join(mount_path, subdir))
-            for i in xrange(0, file_multiplier):
-                for size in xrange(0, {size_range}*size_unit, size_unit):
+            for i in range(0, file_multiplier):
+                for size in range(0, {size_range}*size_unit, size_unit):
                     filename = "{{0}}_{{1}}.bin".format(i, size / size_unit)
-                    f = open(os.path.join(mount_path, subdir, filename), 'w')
-                    f.write(size * 'x')
-                    f.close()
+                    with open(os.path.join(mount_path, subdir, filename), 'w') as f:
+                        f.write(size * 'x')
         """.format(
             mount_path=self.mount_a.mountpoint,
             size_unit=size_unit,
@@ -835,7 +833,8 @@ class TestStrays(CephFSTestCase):
                 path = os.path.join("{path}", "subdir")
                 os.mkdir(path)
                 for n in range(0, {file_count}):
-                    open(os.path.join(path, "%s" % n), 'w').write("%s" % n)
+                    with open(os.path.join(path, "%s" % n), 'w') as f:
+                        f.write(str(n))
                 """.format(
             path=self.mount_a.mountpoint,
             file_count=LOW_LIMIT+1
@@ -852,7 +851,8 @@ class TestStrays(CephFSTestCase):
             path = os.path.join("{path}", "subdir2")
             os.mkdir(path)
             for n in range(0, {file_count}):
-                open(os.path.join(path, "%s" % n), 'w').write("%s" % n)
+                with open(os.path.join(path, "%s" % n), 'w') as f:
+                    f.write(str(n))
             dfd = os.open(path, os.O_DIRECTORY)
             os.fsync(dfd)
             """.format(
@@ -875,7 +875,8 @@ class TestStrays(CephFSTestCase):
             import os
             path = os.path.join("{path}", "subdir2")
             for n in range({file_count}, ({file_count}*3)//2):
-                open(os.path.join(path, "%s" % n), 'w').write("%s" % n)
+                with open(os.path.join(path, "%s" % n), 'w') as f:
+                    f.write(str(n))
             """.format(
         path=self.mount_a.mountpoint,
         file_count=LOW_LIMIT
@@ -890,9 +891,8 @@ class TestStrays(CephFSTestCase):
                 os.mkdir(path)
                 for n in range({file_count}):
                     fpath = os.path.join(path, "%s" % n)
-                    f = open(fpath, 'w')
-                    f.write("%s" % n)
-                    f.close()
+                    with open(fpath, 'w') as f:
+                        f.write(str(n))
                     os.unlink(fpath)
                 """.format(
             path=self.mount_a.mountpoint,
@@ -915,9 +915,8 @@ class TestStrays(CephFSTestCase):
             os.mkdir(path)
             for n in range({file_count}):
                 fpath = os.path.join(path, "%s" % n)
-                f = open(fpath, 'w')
-                f.write("%s" % n)
-                f.close()
+                with open(fpath, 'w') as f:
+                    f.write(str(n))
                 os.unlink(fpath)
             """.format(
         path=self.mount_a.mountpoint,