'Attaches a file image to a loopback device using losetup.
:param img_path: Path of the image file that will be attached to a
loopback device
:return: Path of the loopback device associated.'

def _attach_img_loop(self, img_path):

    logging.debug('Attaching    image    %s    to    a    loop    device', img_path)
    try:
        cmd = 'losetup    -f'
        loop_path = utils.system_output(cmd)
        cmd = ('losetup    -f    %s' % img_path)
        utils.run(cmd)
    except error.CmdError as e:
        e_msg = ('Error    attaching    image    %s    to    a    loop    device:    %s' % (img_path, e))
        raise error.AutotestError(e_msg)
    return loop_path
