def test_volume_repo(self): artifacts_dir = tempfile.mkdtemp(prefix='test_volume_repo') volume_dir = os.path.join(artifacts_dir, vfr.VOLUME_DIR) image_file = os.path.join(artifacts_dir, vfr.IMAGE_FILE) min_free_bytes = 250e6 try: self.assertEqual( vfr.get_volume_for_current_repo( min_free_bytes=min_free_bytes, artifacts_dir=artifacts_dir, ), volume_dir, ) self.assertGreaterEqual( os.stat(image_file).st_size, min_free_bytes, ) fstype_and_avail = subprocess.check_output([ 'findmnt', '--noheadings', '--output', 'FSTYPE,AVAIL', '--bytes', volume_dir ]) fstype, avail = fstype_and_avail.strip().split() self.assertEqual(b'btrfs', fstype) self.assertGreaterEqual(int(avail), min_free_bytes) finally: try: subprocess.call(['sudo', 'umount', volume_dir]) except Exception: pass # Might not have been mounted in case of an earlier error shutil.rmtree(artifacts_dir)
def __init__(self, path_in_repo): self.subvols = [] self._temp_dir_ctx = tempfile.TemporaryDirectory( dir=get_volume_for_current_repo( 1e8, ensure_per_repo_artifacts_dir_exists(path_in_repo), ))
def setUp(self): self.subvolumes_dir = os.path.join( get_volume_for_current_repo( 1e8, ensure_per_repo_artifacts_dir_exists(sys.argv[0]), ), 'targets', )
def volume_dir(path_in_repo=None): if path_in_repo is None: # This is the right default for unit tests and other things that get # run directly from the repo's `buck-out`. path_in_repo = sys.argv[0] lots_of_bytes = 1e8 # Our loopback is sparse, so just make it huge. return get_volume_for_current_repo( lots_of_bytes, ensure_per_repo_artifacts_dir_exists(path_in_repo), )
def setUp(self): self.subvolumes_dir = os.path.join( get_volume_for_current_repo( 1e8, ensure_per_repo_artifacts_dir_exists(sys.argv[0]), ), 'targets', ) # More output for easier debugging unittest.util._MAX_LENGTH = 12345 self.maxDiff = 12345
def setUp(self): # More output for easier debugging unittest.util._MAX_LENGTH = 12345 self.maxDiff = 12345 self.subvolumes_dir = os.path.join( get_volume_for_current_repo( 1e8, ensure_per_repo_artifacts_dir_exists(sys.argv[0]), ), 'targets', ) # Works in @mode/opt since the files of interest are baked into the XAR self.my_dir = os.path.dirname(__file__)
def test_ensure_print_demo_dump_covers_all_operations(self): print_demo_dump_sh = _sibling_path('print_demo_dump.sh') out_bytes = subprocess.check_output( ['sudo', print_demo_dump_sh], cwd=get_volume_for_current_repo(1e8, get_per_repo_artifacts_dir()), ) out_lines = out_bytes.rstrip(b'\n').split(b'\n') # Ensure we have exercised all the implemented operations: # https://github.com/kdave/btrfs-progs/blob/master/send-dump.c#L319 expected_ops = { 'chmod', 'chown', 'clone', 'link', 'mkdir', 'mkfifo', 'mkfile', 'mknod', 'mksock', 'remove_xattr', 'rename', 'rmdir', 'set_xattr', 'snapshot', 'subvol', 'symlink', 'truncate', 'unlink', 'update_extent', 'utimes', 'write', } self.assertEqual( {n.decode() for n in NAME_TO_ITEM_TYPE.keys()}, expected_ops, ) self.assertEqual( expected_ops, {l.split(b' ', 1)[0].decode() for l in out_lines if l}, ) items = _parse_bytes_to_list(out_bytes) # We an item per line, and the items cover the expected operations. self.assertEqual(len(items), len(out_lines)) self.assertEqual( {getattr(DumpItems, op_name) for op_name in expected_ops}, {i.__class__ for i in items}, )
def __init__(self, path_in_repo): self.subvols = [] # The 'tmp' subdirectory simplifies cleanup of leaked temp subvolumes volume_tmp_dir = os.path.join( get_volume_for_current_repo( 1e8, ensure_per_repo_artifacts_dir_exists(path_in_repo), ), 'tmp') try: os.mkdir(volume_tmp_dir) except FileExistsError: pass # Our exit is written with exception-safety in mind, so this # `_temp_dir_ctx` **should** get `__exit__`ed when this class does. self._temp_dir_ctx = tempfile.TemporaryDirectory( # noqa: P201 dir=volume_tmp_dir, prefix=self.__class__.__name__ + '_', )