Ejemplo n.º 1
0
    def run(self):

        args = [
            '--mountdir', self.mountdir, '--metadir', self.metadir,
            '--rootdir', self.rootdir, '-l', self._address
        ]

        logger.debug(f"spawning daemon")
        logger.debug(f"cmdline: {self._cmd} " + " ".join(map(str, args)))
        logger.debug(f"patched env:\n{pformat(self._patched_env)}")

        self._proc = self._cmd(
            args,
            _env=self._env,
            #                _out=sys.stdout,
            #                _err=sys.stderr,
            _bg=True,
        )

        logger.debug(f"daemon process spawned (PID={self._proc.pid})")
        logger.debug("waiting for daemon to be ready")

        try:
            self.wait_until_active(self._proc.pid, 10.0)
        except Exception as ex:
            logger.error(f"daemon initialization failed: {ex}")

            # if the daemon initialized correctly but took longer than
            # `timeout`, we may be leaving running processes behind
            if _process_exists(self._proc.pid):
                self.shutdown()

            logger.critical(
                f"daemon was shut down, what is ex? {ex.__repr__}?")
            raise ex

        logger.debug("daemon is ready")

        return self
Ejemplo n.º 2
0
    def __init__(self, workspace):
        self._parser = IOParser()
        self._workspace = workspace
        self._cmd = sh.Command(gkfs_client_cmd, self._workspace.bindirs)
        self._env = os.environ.copy()

        libdirs = ':'.join(
            filter(None, [os.environ.get('LD_LIBRARY_PATH', '')] +
                   [str(p) for p in self._workspace.libdirs]))

        # ensure the client interception library is available:
        # to avoid running code with potentially installed libraries,
        # it must be found in one (and only one) of the workspace's bindirs
        preloads = []
        for d in self._workspace.bindirs:
            search_path = Path(d) / gkfs_client_lib_file
            if search_path.exists():
                preloads.append(search_path)

        if len(preloads) == 0:
            logger.error(
                f'No client libraries found in the test\'s binary directories:'
            )
            pytest.exit(
                "Aborted due to initialization error. Check test logs.")

        if len(preloads) != 1:
            logger.error(
                f'Multiple client libraries found in the test\'s binary directories:'
            )
            for p in preloads:
                logger.error(f'  {p}')
            logger.error(
                f'Make sure that only one copy of the client library is available.'
            )
            pytest.exit(
                "Aborted due to initialization error. Check test logs.")

        self._preload_library = preloads[0]

        self._patched_env = {
            'LD_LIBRARY_PATH': libdirs,
            'LD_PRELOAD': self._preload_library,
            'LIBGKFS_HOSTS_FILE': self.cwd / gkfs_hosts_file,
            'LIBGKFS_LOG': gkfs_client_log_level,
            'LIBGKFS_LOG_OUTPUT': self._workspace.logdir / gkfs_client_log_file
        }

        self._env.update(self._patched_env)
Ejemplo n.º 3
0
    def __init__(self, workspace):
        self._workspace = workspace
        self._cmd = sh.Command("bash")
        self._env = os.environ.copy()

        # create the forwarding map file
        fwd_map_file = open(self.cwd / gkfwd_forwarding_map_file, 'w')
        fwd_map_file.write('{} {}\n'.format(socket.gethostname(), 0))
        fwd_map_file.close()

        libdirs = ':'.join(
            filter(None, [os.environ.get('LD_LIBRARY_PATH', '')] +
                   [str(p) for p in self._workspace.libdirs]))

        # ensure the client interception library is available:
        # to avoid running code with potentially installed libraries,
        # it must be found in one (and only one) of the workspace's bindirs
        preloads = []
        for d in self._workspace.bindirs:
            search_path = Path(d) / gkfwd_client_lib_file
            if search_path.exists():
                preloads.append(search_path)

        if len(preloads) != 1:
            logger.error(
                f'Multiple client libraries found in the test\'s binary directories:'
            )
            for p in preloads:
                logger.error(f'  {p}')
            logger.error(
                f'Make sure that only one copy of the client library is available.'
            )
            pytest.exit("Aborted due to initialization error")

        self._preload_library = preloads[0]

        self._patched_env = {
            'LD_LIBRARY_PATH': libdirs,
            'LD_PRELOAD': self._preload_library,
            'LIBGKFS_HOSTS_FILE': self.cwd / gkfwd_hosts_file,
            'LIBGKFS_FORWARDING_MAP_FILE':
            self.cwd / gkfwd_forwarding_map_file,
            'LIBGKFS_LOG': gkfwd_client_log_level,
            'LIBGKFS_LOG_OUTPUT':
            self._workspace.logdir / gkfwd_client_log_file
        }

        self._env.update(self._patched_env)
Ejemplo n.º 4
0
    def __init__(self, workspace, identifier):
        self._parser = IOParser()
        self._workspace = workspace
        self._identifier = identifier
        self._cmd = sh.Command(gkfwd_client_cmd, self._workspace.bindirs)
        self._env = os.environ.copy()

        gkfwd_forwarding_map_file_local = '{}-{}'.format(
            identifier, gkfwd_forwarding_map_file)

        # create the forwarding map file
        fwd_map_file = open(self.cwd / gkfwd_forwarding_map_file_local, 'w')
        fwd_map_file.write('{} {}\n'.format(socket.gethostname(),
                                            int(identifier.split('-')[1])))
        fwd_map_file.close()

        # record the map so we can modify it latter if needed
        self._map = self.cwd / gkfwd_forwarding_map_file_local

        # we need to ensure each client will have a distinct log
        gkfwd_client_log_file_local = '{}-{}'.format(identifier,
                                                     gkfwd_client_log_file)
        self._log = self._workspace.logdir / gkfwd_client_log_file_local

        libdirs = ':'.join(
            filter(None, [os.environ.get('LD_LIBRARY_PATH', '')] +
                   [str(p) for p in self._workspace.libdirs]))

        # ensure the client interception library is available:
        # to avoid running code with potentially installed libraries,
        # it must be found in one (and only one) of the workspace's bindirs
        preloads = []
        for d in self._workspace.bindirs:
            search_path = Path(d) / gkfwd_client_lib_file
            if search_path.exists():
                preloads.append(search_path)

        if len(preloads) == 0:
            logger.error(
                f'No client libraries found in the test\'s binary directories:'
            )
            pytest.exit(
                "Aborted due to initialization error. Check test logs.")

        if len(preloads) != 1:
            logger.error(
                f'Multiple client libraries found in the test\'s binary directories:'
            )
            for p in preloads:
                logger.error(f'  {p}')
            logger.error(
                f'Make sure that only one copy of the client library is available.'
            )
            pytest.exit(
                "Aborted due to initialization error. Check test logs.")

        self._preload_library = preloads[0]

        self._patched_env = {
            'LD_LIBRARY_PATH':
            libdirs,
            'LD_PRELOAD':
            self._preload_library,
            'LIBGKFS_HOSTS_FILE':
            self.cwd / gkfwd_hosts_file,
            'LIBGKFS_FORWARDING_MAP_FILE':
            self.cwd / gkfwd_forwarding_map_file_local,
            'LIBGKFS_LOG':
            gkfs_client_log_level,
            'LIBGKFS_LOG_OUTPUT':
            self._workspace.logdir / gkfwd_client_log_file_local
        }

        self._env.update(self._patched_env)