@contextlib.contextmanager<EOL>def guestfs_conn_mount_ro(disk_path, disk_root, retries=<NUM_LIT:5>, wait=<NUM_LIT:1>):
for attempt in range(retries):<EOL><INDENT>with guestfs_conn_ro(disk_path) as conn:<EOL><INDENT>rootfs = find_rootfs(conn, disk_root)<EOL>try:<EOL><INDENT>conn.mount_ro(rootfs, '<STR_LIT:/>')<EOL><DEDENT>except RuntimeError as err:<EOL><INDENT>LOGGER.debug(err)<EOL>if attempt < retries - <NUM_LIT:1>:<EOL><INDENT>LOGGER.debug(<EOL>(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>), disk_path, rootfs, attempt + <NUM_LIT:1>, retries<EOL>)<EOL>time.sleep(wait)<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>raise GuestFSError(<EOL>'<STR_LIT>'.format(<EOL>disk_path, rootfs<EOL>)<EOL>)<EOL><DEDENT><DEDENT>yield conn<EOL>try:<EOL><INDENT>conn.umount(rootfs)<EOL><DEDENT>except RuntimeError as err:<EOL><INDENT>LOGGER.debug(err)<EOL>raise GuestFSError(<EOL>('<STR_LIT>'<EOL>'<STR_LIT>').format(disk_path, rootfs)<EOL>)<EOL><DEDENT>break<EOL><DEDENT><DEDENT>
Open a GuestFS handle with `disk_path` and try mounting the root
filesystem. `disk_root` is a hint where it should be looked and will
only be used if GuestFS will not be able to deduce it independently.

Note that mounting a live guest, can lead to filesystem inconsistencies,
causing the mount operation to fail. As we use readonly mode, this is
safe, but the operation itself can still fail. Therefore, this method
will watch for mount failures and retry 5 times before throwing
an exception.


Args:
    disk_path(str): Path to the disk.
    disk_root(str): Hint what is the root device with the OS filesystem.
    retries(int): Number of retries for :func:`~guestfs.GuestFS.mount_ro`
        operation. Note that on each retry a new GuestFS handle will
        be used.
    wait(int): Time to wait between retries.

Yields:
    guestfs.GuestFS: An open GuestFS handle.

Raises:
    :exc:`GuestFSError`: On any guestfs operation error, including
        exceeding retries for the :func:`~guestfs.GuestFS.mount_ro`
        operation.