예제 #1
0
    def _mount_source(self):

        print("Mounting Memfs for source")

        mountId = 'source'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.source_memfs_inport = InPort(unixAddr)
        self.source_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(
            self.cfg.cache_manager.source_dir, logpath, unixAddr)
        self.source_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.source_memfs_mounter.mount()
예제 #2
0
    def _mount_source(self):

        print("Mounting Memfs for source")

        mountId = 'source'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.source_memfs_inport = InPort(unixAddr)
        self.source_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(self.cfg.cache_manager.source_dir, logpath, unixAddr)
        self.source_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.source_memfs_mounter.mount()
예제 #3
0
class CachefsSystemTest(ModuleTestCase):
    def __init__(self, *args, **kw):
        try:
            cache_via_memfs = kw['cache_via_memfs']
            del kw['cache_via_memfs']
        except KeyError:
            cache_via_memfs = False

        try:
            source_via_memfs = kw['source_via_memfs']
            del kw['source_via_memfs']
        except KeyError:
            source_via_memfs = False

        ModuleTestCase.__init__(self, *args, **kw)
        self.cfg = TestHelper.get_cfg()
        self.tag = 0  # used for testcases with reboot scenario
        self.cache_memfs = cache_via_memfs
        self.source_memfs = source_via_memfs
        if self.cache_memfs:
            self.cache_memfs_inport = None  # must be initialized after port creation in test suite
            self.cache_memfs_mounter = None

        if self.source_memfs:
            self.source_memfs_inport = None  # must be initialized after port creation in test suite
            self.source_memfs_mounter = None

    def setUpImpl(self):
        cfg = self.cfg
        mountpoint = cfg.cache_fs.cache_fs_mountpoint
        self.assertTrue(not os.path.ismount(mountpoint), msg=mountpoint)
        if not os.path.exists(mountpoint):
            os.makedirs(mountpoint)

        self.prepareSource()
        self.precondition()
        self.prepareCache()

        self.mount_cachefs()

    def tearDownImpl(self):
        self.cachefs_mounter.unmount()

    def cleanupWorkspaceImpl(self):
        self.cleanupCache()
        self.cleanupSource()  # TODO: consider method reordering
        #TestHelper.remove_source_dir(self.cfg.cache_manager)

    def precondition(self):
        pass

    def prepareCache(self):
        os.makedirs(self.cfg.cache_manager.cache_root_dir)
        if self.cache_memfs:
            self._mount_cache()

    def prepareSource(self):
        #TestHelper.create_source_dir(self.cfg.cache_manager)
        if self.source_memfs:
            self._mount_source()

    def cleanupCache(self):
        if self.cache_memfs:
            self.cache_memfs_mounter.unmount()
            self.cache_memfs_inport.dispose()
        # add some safety checks
        assert (self.cfg.cache_manager.cache_root_dir)
        shutil.rmtree(self.cfg.cache_manager.cache_root_dir)

    def cleanupSource(self):
        if self.source_memfs:
            self.source_memfs_mounter.unmount()
            self.source_memfs_inport.dispose()
        assert (self.cfg.cache_manager.source_dir)
        shutil.rmtree(self.cfg.cache_manager.source_dir)

    def _getstat(self, path):
        return os.lstat(self._abspath(path))

    def _listdir(self, path):
        return os.listdir(self._abspath(path))

    def _opendir(self, path):
        return os.opendir(self._abspath(path))

    def _open(self, path):
        return open(self._abspath(path))

    def _readlink(self, path):
        return os.readlink(self._abspath(path))

    def _access(self, path, mode=os.F_OK):
        return os.access(self._abspath(path), mode)

    def _abspath(self, path):
        return os.sep.join([self.cfg.cache_fs.cache_fs_mountpoint, path])

    def _mount_cache(self):

        print("Mounting Memfs for cache")

        mountId = 'cache'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.cache_memfs_inport = InPort(unixAddr)
        self.cache_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(
            self.cfg.cache_manager.cache_root_dir, logpath, unixAddr)
        self.cache_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.cache_memfs_mounter.mount()

    def _mount_source(self):

        print("Mounting Memfs for source")

        mountId = 'source'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.source_memfs_inport = InPort(unixAddr)
        self.source_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(
            self.cfg.cache_manager.source_dir, logpath, unixAddr)
        self.source_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.source_memfs_mounter.mount()

    def _buildCmdLineOptions(self, mountpoint, logpath, unixAddr):
        cmdline_options = [
            os.path.join(config.getProjectRoot(), 'tests', 'mocks',
                         'memfs.py'),
            mountpoint,
            '--log={log_path}'.format(log_path=logpath),
            '--commport={commport}'.format(commport=unixAddr),
            '-f'  # foreground
        ]
        return cmdline_options

    def _buildMemfsLogPath(self, label):
        filename = ''.join([
            "LOG_MEMFS_", label, "_", self.__class__.__name__,
            str(self.tag), ".txt"
        ])
        return os.path.join(self.cfg.ut_tests_root, filename)

    def _buildMemfsUnixAddress(self, label):
        filename = ''.join([
            label.capitalize(), self.__class__.__name__,
            str(self.tag), '.sock'
        ])
        return os.path.join(self.cfg.ut_tests_root, filename)

    def mount_cachefs(self):
        cmdline_options = [
            os.path.join(config.getProjectRoot(), 'scripts', 'wrapper.sh'),
            os.path.join(config.getProjectRoot(), 'cachefs.py'),
            self.cfg.cache_fs.cache_fs_mountpoint,
            '--source-dir={source}'.format(
                source=self.cfg.cache_manager.source_dir),
            '--cache-dir={cache}'.format(
                cache=self.cfg.cache_manager.cache_root_dir),
            '--log={log_path}'.format(log_path=os.path.join(
                self.cfg.ut_tests_root, "LOG_" + self.__class__.__name__ +
                str(self.tag))),
            '--disk-cache-lifetime={disk_cache_lifetime}'.format(
                disk_cache_lifetime=self.cfg.cache_manager.disk_cache_lifetime
            ),
            '--memory-cache-lifetime={memory_cache_lifetime}'.format(
                memory_cache_lifetime=self.cfg.cache_manager.
                memory_cache_lifetime),
            '--debug',
            '-f'  # foreground
        ]
        self.cachefs_mounter = mounter.FuseFsMounter(
            cmdline_options, self.cfg.cache_fs.cache_fs_mountpoint)
        try:
            self.cachefs_mounter.mount()
        except:
            print("************************************************")
            print("************************************************")
            print("CANNOT MOUNT CACHEFS, TRYING TO CLEANUP THE MESS")
            print("************************************************")
            print("************************************************")
            self.cleanupWorkspace()
예제 #4
0
class CachefsSystemTest(ModuleTestCase):

    def __init__(self, *args, **kw):
        try:
            cache_via_memfs = kw['cache_via_memfs']
            del kw['cache_via_memfs']
        except KeyError:
            cache_via_memfs = False

        try:
            source_via_memfs = kw['source_via_memfs']
            del kw['source_via_memfs']
        except KeyError:
            source_via_memfs = False

        ModuleTestCase.__init__(self, *args, **kw)
        self.cfg = TestHelper.get_cfg()
        self.tag = 0 # used for testcases with reboot scenario
        self.cache_memfs = cache_via_memfs
        self.source_memfs = source_via_memfs
        if self.cache_memfs:
            self.cache_memfs_inport = None # must be initialized after port creation in test suite
            self.cache_memfs_mounter = None

        if self.source_memfs:
            self.source_memfs_inport = None # must be initialized after port creation in test suite
            self.source_memfs_mounter = None

    def setUpImpl(self):
        cfg = self.cfg 
        mountpoint = cfg.cache_fs.cache_fs_mountpoint
        self.assertTrue(not os.path.ismount(mountpoint), msg=mountpoint)
        if not os.path.exists(mountpoint):
            os.makedirs(mountpoint)

        self.prepareSource()
        self.precondition()
        self.prepareCache()

        self.mount_cachefs();

    def tearDownImpl(self):
        self.cachefs_mounter.unmount()

    def cleanupWorkspaceImpl(self):
        self.cleanupCache()
        self.cleanupSource() # TODO: consider method reordering
        #TestHelper.remove_source_dir(self.cfg.cache_manager)

    def precondition(self):
        pass

    def prepareCache(self):
        os.makedirs(self.cfg.cache_manager.cache_root_dir)
        if self.cache_memfs:
            self._mount_cache()

    def prepareSource(self):
        #TestHelper.create_source_dir(self.cfg.cache_manager)
        if self.source_memfs:
            self._mount_source()

    def cleanupCache(self):
        if self.cache_memfs:
            self.cache_memfs_mounter.unmount()
            self.cache_memfs_inport.dispose()
        # add some safety checks
        assert(self.cfg.cache_manager.cache_root_dir)
        shutil.rmtree(self.cfg.cache_manager.cache_root_dir)

    def cleanupSource(self):
        if self.source_memfs:
            self.source_memfs_mounter.unmount()
            self.source_memfs_inport.dispose()
        assert(self.cfg.cache_manager.source_dir)
        shutil.rmtree(self.cfg.cache_manager.source_dir)

    def _getstat(self, path):
        return os.lstat(self._abspath(path))

    def _listdir(self, path):
        return os.listdir(self._abspath(path))

    def _opendir(self, path):
        return os.opendir(self._abspath(path))

    def _open(self, path):
        return open(self._abspath(path))

    def _readlink(self, path):
        return os.readlink(self._abspath(path))

    def _access(self, path, mode=os.F_OK):
        return os.access(self._abspath(path), mode)

    def _abspath(self, path):
        return os.sep.join([self.cfg.cache_fs.cache_fs_mountpoint, path])


    def _mount_cache(self):

        print("Mounting Memfs for cache")

        mountId = 'cache'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.cache_memfs_inport = InPort(unixAddr)
        self.cache_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(self.cfg.cache_manager.cache_root_dir, logpath, unixAddr)
        self.cache_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.cache_memfs_mounter.mount()

    def _mount_source(self):

        print("Mounting Memfs for source")

        mountId = 'source'
        logpath = self._buildMemfsLogPath(mountId)
        unixAddr = self._buildMemfsUnixAddress(mountId)

        self.source_memfs_inport = InPort(unixAddr)
        self.source_memfs_inport.listen()

        cmdline_options = self._buildCmdLineOptions(self.cfg.cache_manager.source_dir, logpath, unixAddr)
        self.source_memfs_mounter = mounter.FuseFsMounter(cmdline_options)
        self.source_memfs_mounter.mount()

    def _buildCmdLineOptions(self, mountpoint, logpath, unixAddr):
        cmdline_options = [
            os.path.join(config.getProjectRoot(), 'tests', 'mocks', 'memfs.py'),
            mountpoint,
            '--log={log_path}'.format(log_path=logpath),
            '--commport={commport}'.format(commport=unixAddr),
            '-f' # foreground
        ]
        return cmdline_options

    def _buildMemfsLogPath(self, label):
        filename = ''.join(["LOG_MEMFS_", label, "_", self.__class__.__name__, str(self.tag), ".txt"])
        return os.path.join(self.cfg.ut_tests_root, filename)

    def _buildMemfsUnixAddress(self, label):
        filename = ''.join([label.capitalize(), self.__class__.__name__, str(self.tag), '.sock'])
        return os.path.join(self.cfg.ut_tests_root, filename)

    def mount_cachefs(self):
        cmdline_options = [
            os.path.join(config.getProjectRoot(), 'scripts', 'wrapper.sh'),
            os.path.join(config.getProjectRoot(), 'cachefs.py'),
            self.cfg.cache_fs.cache_fs_mountpoint,
            '--source-dir={source}'.format(source=self.cfg.cache_manager.source_dir),
            '--cache-dir={cache}'.format(cache=self.cfg.cache_manager.cache_root_dir),
            '--log={log_path}'.format(log_path=os.path.join(self.cfg.ut_tests_root, "LOG_" + self.__class__.__name__ + str(self.tag))),
            '--disk-cache-lifetime={disk_cache_lifetime}'.format(disk_cache_lifetime=self.cfg.cache_manager.disk_cache_lifetime),
            '--memory-cache-lifetime={memory_cache_lifetime}'.format(memory_cache_lifetime=self.cfg.cache_manager.memory_cache_lifetime),
            '--debug',
            '-f' # foreground
        ]
        self.cachefs_mounter = mounter.FuseFsMounter(cmdline_options, self.cfg.cache_fs.cache_fs_mountpoint)
        try:
            self.cachefs_mounter.mount()
        except:
            print("************************************************")
            print("************************************************")
            print("CANNOT MOUNT CACHEFS, TRYING TO CLEANUP THE MESS")
            print("************************************************")
            print("************************************************")
            self.cleanupWorkspace()