Esempio n. 1
0
    def test_MyFuse(self, mock_libfuse):
        # Tests the ctor to make sure the arguments are passed
        # correctly to the os
        mock_libfuse.fuse_main_real.return_value = False
        fuseops = fuse_operations()
        MyFuse(VOFS("vos:", "/tmp/vos_", None,
                    cache_limit=100,
                    cache_max_flush_threads=3),
               "/tmp/vospace",
               fsname="vos:",
               nothreads=5,
               foreground=False)
        # if it was easy to pick inside the args memory structures we would
        # have checked the the real arguments passed to the fuse library
        # instead of ANY
        mock_libfuse.fuse_main_real.assert_called_with(5, ANY, ANY,
                                                       ctypes.sizeof(fuseops),
                                                       None)

        MyFuse(VOFS("vos:", "/tmp/vos_", None,
                    cache_limit=100,
                    cache_max_flush_threads=3),
               "/tmp/vospace",
               fsname="vos:",
               nothreads=5,
               readonly=True,
               user_allow_other=True,
               foreground=False)

        mock_libfuse.fuse_main_real.assert_called_with(6, ANY, ANY,
                                                       ctypes.sizeof(fuseops),
                                                       None)
Esempio n. 2
0
    def test_MyFuse(self, mock_libfuse):
        #Tests the ctor to make sure the arguments are passed
        #correctly to the os
        conn = MagicMock()
        mock_libfuse.fuse_main_real.return_value = False
        fuseops = fuse_operations()
        buf = ctypes.create_string_buffer(4)
        fuse = MyFuse(VOFS(":vos", "/tmp/vos_", None, conn=conn,
                 cache_limit=100,
                 cache_max_flush_threads=3),
            "/tmp/vospace",
            fsname="vos:",
            nothreads=5,
            foreground=False)
        #if it was easy to pick inside the args memory structures we would
        #have checked the the real arguments passed to the fuse library
        #instead of ANY
        mock_libfuse.fuse_main_real.assert_called_with(5, ANY, ANY, 
                                                       ctypes.sizeof(fuseops), 
                                                       None)
        
        fuse = MyFuse(VOFS(":vos", "/tmp/vos_", None, conn=conn,
                 cache_limit=100,
                 cache_max_flush_threads=3),
            "/tmp/vospace",
            fsname="vos:",
            nothreads=5,
            readonly=True,
            user_allow_other=True,
            foreground=False)

        mock_libfuse.fuse_main_real.assert_called_with(6, ANY, ANY,
                                                       ctypes.sizeof(fuseops),
                                                       None)
Esempio n. 3
0
    def __init__(self,
                 operations,
                 mountpoint,
                 raw_fi=False,
                 encoding='utf-8',
                 **kwargs):
        '''
        Setting raw_fi to True will cause FUSE to pass the fuse_file_info
        class as is to Operations, instead of just the fh field.

        This gives you access to direct_io, keep_cache, etc.
        '''

        self.operations = operations
        self.raw_fi = raw_fi
        self.encoding = encoding

        args = ['fuse']

        args.extend(flag for arg, flag in self.OPTIONS
                    if kwargs.pop(arg, False))

        kwargs.setdefault('fsname', operations.__class__.__name__)
        args.append('-o')
        args.append(','.join(self._normalize_fuse_options(**kwargs)))
        args.append(mountpoint)

        args = [arg.encode(encoding) for arg in args]
        argv = (fuse.c_char_p * len(args))(*args)

        fuse_ops = fuse.fuse_operations()

        for field in fuse.fuse_operations._fields_:
            if len(field) == 3:
                continue

            name, prototype = field
            if prototype != fuse.c_voidp and getattr(operations, name, None):
                op = fuse.partial(self._wrapper, getattr(self, name))
                setattr(fuse_ops, name, prototype(op))

        self.args = args
        self.fuse_ops = fuse_ops
        self.argv = argv