コード例 #1
0
 def setUp(self):
     '''Using a specific image here. If this test fails due to the image
     not being found anymore, pick a different image to test against
     For now use Docker to pull the image from Dockerhub'''
     set_mount_dir()
     create_top_dir()
     check_docker_setup()
     if not check_image('vmware/tern@sha256:20b32a9a20752aa1ad'
                        '7582c667704fda9f004cc4bfd8601fac7f2656c7567bb4'):
         try:
             container.pull_image('vmware/tern@sha256:20b32a9a20'
                                  '752aa1ad7582c667704fda9f004cc4'
                                  'bfd8601fac7f2656c7567bb4')
         except subprocess.CalledProcessError as error:
             print(error.output)
     self.image = DockerImage('vmware/tern@sha256:20b32'
                              'a9a20752aa1ad7582c667704fda9f00'
                              '4cc4bfd8601fac7f2656c7567bb4')
     # constants for this image
     self.image_id = ('acb194ad84d0f9734e794fbbdbb65fb'
                      '7db6eda83f33e9e817bcc75b1bdd99f5e')
     self.layer = ('c1c3a87012e7ff5791b31e94515b661'
                   'cdf06f6d5dc2f9a6245eda8774d257a13')
     self.no_layers = 1
     self.created_by = ('/bin/sh -c #(nop) ADD '
                        'file:92137e724f46c720d8083a11290c67'
                        'd9daa387e523336b1757a0e3c4f5867cd5 '
                        'in / ')
コード例 #2
0
def do_main(args):
    '''Execute according to subcommands'''
    # set bind mount location if working in a container
    rootfs.set_mount_dir(args.bind_mount)
    # create working directory
    create_top_dir()
    if args.log_stream:
        # set up console logs
        global logger
        global console
        logger.addHandler(console)
    logger.debug('Starting...')
    if args.clear_cache:
        logger.debug('Clearing cache...')
        cache.clear()
    if hasattr(args, 'name') and args.name == 'report':
        if args.dockerfile:
            run.execute_dockerfile(args)
        if args.docker_image:
            if general.check_tar(args.docker_image):
                logger.error("%s", errors.incorrect_raw_option)
            else:
                run.execute_docker_image(args)
                logger.debug('Report completed.')
        if args.raw_image:
            if not general.check_tar(args.raw_image):
                logger.error(
                    "%s",
                    errors.invalid_raw_image.format(image=args.raw_image))
            else:
                run.execute_docker_image(args)
                logger.debug('Report completed.')
    logger.debug('Finished')
コード例 #3
0
ファイル: test_class_docker_image.py プロジェクト: zoek1/tern
 def setUp(self):
     '''Using a specific image here. If this test fails due to the image
     not being found anymore, pick a different image to test against
     For now use Docker to pull the image from Dockerhub'''
     set_mount_dir()
     create_top_dir()
     check_docker_setup()
     if not check_image('vmware/tern@sha256:20b32a9a20752aa1ad'
                        '7582c667704fda9f004cc4bfd8601fac7f2656c7567bb4'):
         try:
             container.pull_image('vmware/tern@sha256:20b32a9a20'
                                  '752aa1ad7582c667704fda9f004cc4'
                                  'bfd8601fac7f2656c7567bb4')
         except subprocess.CalledProcessError as error:
             print(error.output)
     self.image = DockerImage('vmware/tern@sha256:20b32'
                              'a9a20752aa1ad7582c667704fda9f00'
                              '4cc4bfd8601fac7f2656c7567bb4')
     # constants for this image
     self.image_id = ('acb194ad84d0f9734e794fbbdbb65fb'
                      '7db6eda83f33e9e817bcc75b1bdd99f5e')
     self.layer = ('c1c3a87012e7ff5791b31e94515b661'
                   'cdf06f6d5dc2f9a6245eda8774d257a13')
     self.no_layers = 1
     self.created_by = ('/bin/sh -c #(nop) ADD '
                        'file:92137e724f46c720d8083a11290c67'
                        'd9daa387e523336b1757a0e3c4f5867cd5 '
                        'in / ')
     self.file_info = [
         ('file2.txt', 'documents/test/file2.txt',
          '9710f003d924890c7677b4dd91fd753f6ed71cc57d4f'
          '9482261b6786d81957fa',
          'sha256'),
         ('file2.txt', 'documents/test/test2/file2.txt',
          '885000512dee8ac814641bbf6a7c887012ec23a2fb3e'
          '3b2cff583c45a611317d',
          'sha256'),
         ('file1.txt', 'documents/test/test2/file1.txt',
          '885000512dee8ac814641bbf6a7c887012ec'
          '23a2fb3e3b2cff583c45a611317d',
          'sha256'),
         ('file1.txt', 'documents/test/file1.txt',
          'a3cccbc52486d50a86ff0bc1e6ea0e0b701ac'
          '4bb139f8713fa136ef9ec68e97e',
          'sha256')
     ]
コード例 #4
0
def do_main(args):
    '''Execute according to subcommands'''
    # set bind mount location if working in a container
    rootfs.set_mount_dir(args.bind_mount, args.working_dir)
    # create working directory
    create_top_dir(args.working_dir)
    if not args.quiet:
        # set up console logs
        global logger
        global console
        logger.addHandler(console)
    logger.debug('Starting...')
    if args.clear_cache:
        logger.debug('Clearing cache...')
        cache.clear()
    if hasattr(args, 'name') and (args.name == 'report'
                                  or args.name == 'lock'):
        if args.name == 'lock':
            run.execute_dockerfile(args)
        elif args.dockerfile:
            run.execute_dockerfile(args)
        elif args.docker_image:
            # Check if the image is of image:tag
            # or image@digest_type:digest format
            if not check_image_string(args.docker_image):
                sys.stderr.write('Error running Tern\n'
                                 'Please provide docker image '
                                 'string in image:tag or '
                                 'image@digest_type:digest format\n')
                sys.exit(1)
            if general.check_tar(args.docker_image):
                logger.error("%s", errors.incorrect_raw_option)
            else:
                run.execute_docker_image(args)
                logger.debug('Report completed.')
        if args.name == 'report':
            if args.raw_image:
                if not general.check_tar(args.raw_image):
                    logger.error(
                        "%s",
                        errors.invalid_raw_image.format(image=args.raw_image))
                else:
                    run.execute_docker_image(args)
                    logger.debug('Report completed.')
    logger.debug('Finished')
コード例 #5
0
                        help='List of keys to look up in the command '
                        'library. Eg: base dpkg names')
    parser.add_argument('--shell',
                        default='/bin/sh',
                        help='The shell executable that the image uses')
    parser.add_argument('--package',
                        default='',
                        help='A package name that the command needs to '
                        'execute with. Useful when testing commands in the '
                        'snippet library')
    args = parser.parse_args()

    # do initial setup to analyze docker image
    container.check_docker_setup()
    # set some global variables
    rootfs.set_mount_dir()
    # try to load the image
    image_obj = report.load_full_image(args.image)
    if image_obj.origins.is_empty():
        # image loading was successful
        # proceed mounting diff filesystems
        rootfs.set_up()
        if len(image_obj.layers) == 1:
            # mount only one layer
            target = rootfs.mount_base_layer(image_obj.layers[0].tar_file)
        else:
            target = analyze.mount_overlay_fs(image_obj,
                                              len(image_obj.layers) - 1)
        rootfs.prep_rootfs(target)
        # invoke commands in chroot
        # if we're looking up the snippets library