Example #1
0
    def testInstance(self):
        self.assertEqual(
            self.image.repotag, 'vmware/tern@sha256:20b32a9a2'
            '0752aa1ad7582c667704fda9f004cc4'
            'bfd8601fac7f2656c7567bb4')
        self.assertEqual(self.image.name, 'vmware/tern')
        self.assertEqual(self.image.tag, '')
        self.assertTrue(self.image.checksum_type, 'sha256')
        self.assertTrue(
            self.image.checksum, '20b32a9a20752aa1ad7582c66'
            '7704fda9f004cc4bfd8601fac7'
            'f2656c7567bb4')
        self.assertFalse(self.image.manifest)
        self.assertFalse(self.image.repotags)
        self.assertFalse(self.image.config)
        self.assertFalse(self.image.layers)
        self.assertFalse(self.image.history)
        # test instantiating with a tag
        if not check_image('vmware/tern:testimage'):
            try:
                container.pull_image('vmware/tern:testimage')
            except subprocess.CalledProcessError as error:
                print(error.output)

        d = DockerImage('vmware/tern:testimage')
        self.assertEqual(d.name, 'vmware/tern')
        self.assertEqual(d.tag, 'testimage')
        self.assertEqual(d.checksum_type, 'sha256')
        self.assertEqual(
            d.checksum, '20b32a9a20752aa1ad7582c667704fda9f004cc4'
            'bfd8601fac7f2656c7567bb4')
Example #2
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 / ')
Example #3
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 / ')
     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')
     ]
Example #4
0
File: report.py Project: zoek1/tern
def setup(dockerfile=None, image_tag_string=None):
    '''Any initial setup'''
    # generate random names for image, container, and tag
    general.initialize_names()
    # load the cache
    cache.load()
    # load dockerfile if present
    if dockerfile:
        dhelper.load_docker_commands(dockerfile)
    # check if the docker image is present
    if image_tag_string and general.check_tar(image_tag_string) is False:
        if container.check_image(image_tag_string) is None:
            # if no docker image is present, try to pull it
            if container.pull_image(image_tag_string) is None:
                logger.fatal("%s", errors.cannot_find_image.format(
                    imagetag=image_tag_string))
                sys.exit()
Example #5
0
def load_base_image():
    '''Create base image from dockerfile instructions and return the image'''
    base_image, dockerfile_lines = dhelper.get_dockerfile_base()
    # try to get image metadata
    if container.check_image(base_image.repotag) is None:
        # if no base image is found, give a warning and continue
        if container.pull_image(base_image.repotag) is None:
            logger.warning(
                "%s",
                errors.cannot_find_image.format(imagetag=base_image.repotag))
    try:
        base_image.load_image()
    except (NameError, subprocess.CalledProcessError, IOError, ValueError,
            EOFError) as error:
        logger.warning('Error in loading base image: %s', str(error))
        base_image.origins.add_notice_to_origins(dockerfile_lines,
                                                 Notice(str(error), 'error'))
    return base_image