| 1289 | ))) |
| 1290 | |
| 1291 | def validate_test_pattern(self, filename, size, timeout=None): |
| 1292 | log.info("Validating {0} bytes from {1}".format(size, filename)) |
| 1293 | # Use sudo because cephfs-data-scan may recreate the file with owner==root |
| 1294 | return self.run_python(dedent(""" |
| 1295 | import zlib |
| 1296 | path = "{path}" |
| 1297 | with open(path, 'r') as f: |
| 1298 | bytes = f.read() |
| 1299 | if len(bytes) != {size}: |
| 1300 | raise RuntimeError("Bad length {{0}} vs. expected {{1}}".format( |
| 1301 | len(bytes), {size} |
| 1302 | )) |
| 1303 | for i, b in enumerate(bytes): |
| 1304 | val = zlib.crc32(str(i).encode('utf-8')) & 7 |
| 1305 | if b != chr(val): |
| 1306 | raise RuntimeError("Bad data at offset {{0}}".format(i)) |
| 1307 | """.format( |
| 1308 | path=os.path.join(self.hostfs_mntpt, filename), |
| 1309 | size=size |
| 1310 | )), sudo=True, timeout=timeout) |
| 1311 | |
| 1312 | def open_n_background(self, fs_path, count): |
| 1313 | """ |