def setup_root_mount(self): # SLAVE means that mount events will get inside the container, but # mounting something inside will not leak out. # Use PRIVATE to not let outside events propagate in mount(Path("none"), Path("/"), None, MS_REC | MS_SLAVE, None) if not is_mount_point(self.root_dir): mount(self.root_dir, self.root_dir, None, MS_BIND, None) old_root_dir = self.root_dir.joinpath('old_root') old_root_dir.mkdir(parents=True, exist_ok=True) os.chdir(str(self.root_dir)) pivot_root(Path('.'), Path('old_root')) os.chroot('.')
def test_container_rootfs_is_mountpoint(rootfs_for_testing): assert is_mount_point(rootfs_for_testing) with ContainerContext(rootfs_for_testing): pass
def test_container_rootfs_is_not_mountpoint(debootstrapped_dir): assert not is_mount_point(debootstrapped_dir) with ContainerContext(debootstrapped_dir): pass