test_docker.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:aardvark 作者: Netflix-Skunkworks 项目源码 文件源码
def get_container_details(self, image):
        '''Run a docker container shell and retrieve several details.'''

        # (detail name, command, result filter) for extracting details
        # from container command lines.
        shell_commands = (
            ('pwd', 'pwd', None),
            ('phantomjs_path', 'which phantomjs', None),
            ('phantomjs_perms', 'ls -l $(which phantomjs)', lambda x: x[1:10]),
            ('config_file', 'ls {}'.format(CONTAINER_CONFIG_PATH), None),
            ('config_contents', 'cat {}'.format(CONTAINER_CONFIG_PATH), None),
            )

        command = "docker run --rm -it {} bash".format(image)
        logger.info('IMAGE: %s', image)
        logger.info('CONTAINER LAUNCH COMMAND: %s', command)
        spawn = pexpect.spawn(command)

        container_details = {}

        for field, shell_command, response_filter in shell_commands:
            container_details[field] = interact(
                spawn, shell_command, response_filter
                )

        # Exit the container.
        spawn.sendcontrol('d')

        # "Expand" the config records if we found a config file.
        if container_details['config_file'] == CONTAINER_CONFIG_PATH:
            try:
                exec(container_details['config_contents'], container_details)
            except SyntaxError:
                pass
            # The '__builtins__' are noise:
            if '__builtins__' in container_details:
                del container_details['__builtins__']

        return container_details

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - -
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号