test_docker.py 文件源码

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

项目:aardvark 作者: Netflix-Skunkworks 项目源码 文件源码
def get_docker_image_list(*expected_images):
        '''Get the output from "docker image ls" for specified image names.'''

        image_listing_pattern = (
            r'(?P<name>[^\s]+)\s+'
            r'(?P<tag>[^\s]+)\s+'
            r'(?P<id>[0-9a-f]+)\s+'
            r'(?P<created>.+ago)\s+'
            r'(?P<size>[^\s]+)'
            r'\s*$'
            )
        image_listing_re = re.compile(image_listing_pattern)

        docker_images_response = pexpect.run('docker image ls')

        image_list = []
        expected_image_nametag_pairs = [
            (x.split(':') + ['latest'])[0:2] for x in expected_images
            ] if expected_images else None

        for line in docker_images_response.split('\n'):
            match = image_listing_re.match(line)
            if (
                    match and (
                        not expected_images or [
                            match.groupdict()['name'], match.groupdict()['tag']
                            ] in expected_image_nametag_pairs
                        )
                    ):
                image_list.append(match.groupdict())

        return image_list

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


问题


面经


文章

微信
公众号

扫码关注公众号