def formatted_loopback_device_for_test(test_case, label=None):
 losetup = Losetup()
 backing_file = test_case.make_temporary_file()
 with backing_file.open('wb') as f:
  f.truncate(LOOPBACK_MINIMUM_ALLOCATABLE_SIZE)
 device = losetup.add(backing_file=backing_file)
 bdm = BlockDeviceManager()
 bdm.make_filesystem(blockdevice=device.device, filesystem=u'ext4')
 if label:
  run_process(['tune2fs', '-L', label, device.device.path])
 def cleanup():
  '\n        Try to unmount the device 10 times or until it detaches.\n        '
  device.remove()
  for _ in xrange(10):
   if (device in losetup.list()):
    _unmount(path=device.device, idempotent=True)
   else:
    break
 test_case.addCleanup(cleanup)
 return device

def formatted_loopback_device_for_test ( test_case , label = None ) : losetup = Losetup ( ) backing_file = test_case . make_temporary_file ( ) with backing_file . open ( 'wb' ) as f : f . truncate ( LOOPBACK_MINIMUM_ALLOCATABLE_SIZE ) device = losetup . add ( backing_file = backing_file ) bdm = BlockDeviceManager ( ) bdm . make_filesystem ( blockdevice = device . device , filesystem = u'ext4' ) if label : run_process ( [ 'tune2fs' , '-L' , label , device . device . path ] ) def cleanup ( ) : device . remove ( ) for _ in xrange ( 10 ) : if ( device in losetup . list ( ) ) : _unmount ( path = device . device , idempotent = True ) else : break test_case . addCleanup ( cleanup ) return device
create a loopback device .