Exemplo n.º 1
0
 def test_with_busybox(self):
     ret = tarutils.get_youngest_children(
         test_metadata_with_multiple_images_sharing_a_single_parent)
     expected_youngest_children = [
         '150ddf0474655d12dcc79b0d5ee360dadcfba01e25d89dee71b4fed3d0c30fbe',
         '89aba41176b8f979bae09db1df5d6f3b58584318fce5d9e56b49c5a3e9700ab4',
         '8e36c99cfab52f0cf6f1aed7674cbdfe57e2ec8d29cdfdfac816b1d659d3ca9e']
     self.assertEqual(set(ret), set(expected_youngest_children))
Exemplo n.º 2
0
 def test_with_busybox(self):
     ret = tarutils.get_youngest_children(
         test_metadata_with_multiple_images_sharing_a_single_parent)
     expected_youngest_children = [
         '150ddf0474655d12dcc79b0d5ee360dadcfba01e25d89dee71b4fed3d0c30fbe',
         '89aba41176b8f979bae09db1df5d6f3b58584318fce5d9e56b49c5a3e9700ab4',
         '8e36c99cfab52f0cf6f1aed7674cbdfe57e2ec8d29cdfdfac816b1d659d3ca9e']
     self.assertEqual(set(ret), set(expected_youngest_children))
Exemplo n.º 3
0
def get_models(metadata, mask_id=''):
    """
    Given image metadata, returns model instances to represent
    each layer of the image defined by the unit_key

    :param metadata:    a dictionary where keys are image IDs, and values are
                        dictionaries with keys "parent" and "size", containing
                        values for those two attributes as taken from the docker
                        image metadata.
    :type  metadata:    dict
    :param mask_id:     The ID of an image that should not be included in the
                        returned models. This image and all of its ancestors
                        will be excluded.
    :type  mask_id:     basestring

    :return:    list of models.DockerImage instances
    :rtype:     list
    """
    images = []
    existing_image_ids = set()

    leaf_image_ids = tarutils.get_youngest_children(metadata)

    for image_id in leaf_image_ids:
        while image_id:
            json_data = metadata[image_id]
            parent_id = json_data.get('parent')
            size = json_data['size']

            if image_id not in existing_image_ids:
                # This will avoid adding multiple images with a same id, which can happen
                # in case of parents with multiple children.
                existing_image_ids.add(image_id)
                images.append(models.DockerImage(image_id, parent_id, size))

            if parent_id == mask_id:
                break

            image_id = parent_id

    return images
Exemplo n.º 4
0
def get_models(metadata, mask_id=''):
    """
    Given image metadata, returns model instances to represent
    each layer of the image defined by the unit_key

    :param metadata:    a dictionary where keys are image IDs, and values are
                        dictionaries with keys "parent" and "size", containing
                        values for those two attributes as taken from the docker
                        image metadata.
    :type  metadata:    dict
    :param mask_id:     The ID of an image that should not be included in the
                        returned models. This image and all of its ancestors
                        will be excluded.
    :type  mask_id:     basestring

    :return:    list of models.DockerImage instances
    :rtype:     list
    """
    images = []
    existing_image_ids = set()

    leaf_image_ids = tarutils.get_youngest_children(metadata)

    for image_id in leaf_image_ids:
        while image_id:
            json_data = metadata[image_id]
            parent_id = json_data.get('parent')
            size = json_data['size']

            if image_id not in existing_image_ids:
                # This will avoid adding multiple images with a same id, which can happen
                # in case of parents with multiple children.
                existing_image_ids.add(image_id)
                images.append(models.DockerImage(image_id, parent_id, size))

            if parent_id == mask_id:
                break

            image_id = parent_id

    return images
Exemplo n.º 5
0
    def test_with_busybox_light(self):
        metadata = tarutils.get_metadata(busybox_tar_path)
        ret = tarutils.get_youngest_children(metadata)

        self.assertEqual(ret, [busybox_ids[0]])
Exemplo n.º 6
0
    def test_with_busybox_light(self):
        metadata = tarutils.get_metadata(busybox_tar_path)
        ret = tarutils.get_youngest_children(metadata)

        self.assertEqual(ret, [busybox_ids[0]])