Пример #1
0
 def test_basic_update(self, mock_repo_qs):
     mock_repo = mock_repo_qs.get_repo_or_missing_resource.return_value
     mock_repo.scratchpad = {}
     upload.update_tags('repo1', data.busybox_tar_path)
     mock_repo.save.assert_called_once_with()
     self.assertEqual(
         mock_repo.scratchpad['tags'], [{constants.IMAGE_TAG_KEY: 'latest',
                                        constants.IMAGE_ID_KEY: data.busybox_ids[0]}]
     )
Пример #2
0
    def test_basic_update(self, mock_update, mock_get):
        mock_get.return_value = {'foo': 'other data that should not be part of the update'}

        upload.update_tags('repo1', data.busybox_tar_path)

        mock_update.assert_called_once_with('repo1',
                                            {'tags':
                                                [{constants.IMAGE_TAG_KEY: 'latest',
                                                  constants.IMAGE_ID_KEY: data.busybox_ids[0]}]})
Пример #3
0
    def test_preserves_existing_tags(self, mock_repo_qs):
        mock_repo = mock_repo_qs.get_repo_or_missing_resource.return_value
        mock_repo.scratchpad = {'tags': [{constants.IMAGE_TAG_KEY: 'greatest',
                                          constants.IMAGE_ID_KEY: data.busybox_ids[1]}]}

        upload.update_tags('repo1', data.busybox_tar_path)

        expected_tags = [{constants.IMAGE_TAG_KEY: 'greatest',
                          constants.IMAGE_ID_KEY: data.busybox_ids[1]},
                         {constants.IMAGE_TAG_KEY: 'latest',
                          constants.IMAGE_ID_KEY: data.busybox_ids[0]}]
        self.assertEqual(mock_repo.scratchpad['tags'], expected_tags)
        mock_repo.save.assert_called_once_with()
Пример #4
0
    def test_preserves_existing_tags(self, mock_update, mock_get):
        mock_get.return_value = {'tags': [{constants.IMAGE_TAG_KEY: 'greatest',
                                           constants.IMAGE_ID_KEY: data.busybox_ids[1]}]}

        upload.update_tags('repo1', data.busybox_tar_path)

        expected_tags = {
            'tags': [{constants.IMAGE_TAG_KEY: 'greatest',
                      constants.IMAGE_ID_KEY: data.busybox_ids[1]},
                     {constants.IMAGE_TAG_KEY: 'latest',
                      constants.IMAGE_ID_KEY: data.busybox_ids[0]}]
        }
        mock_update.assert_called_once_with('repo1', expected_tags)
Пример #5
0
    def test_basic_update(self, mock_update, mock_get):
        mock_get.return_value = {
            'foo': 'other data that should not be part of the update'
        }

        upload.update_tags('repo1', data.busybox_tar_path)

        mock_update.assert_called_once_with(
            'repo1', {
                'tags': [{
                    constants.IMAGE_TAG_KEY: 'latest',
                    constants.IMAGE_ID_KEY: data.busybox_ids[0]
                }]
            })
Пример #6
0
    def test_overwrite_existing_duplicate_tags(self, mock_update, mock_get):
        mock_get.return_value = {'tags': [{constants.IMAGE_TAG_KEY: 'latest',
                                           constants.IMAGE_ID_KEY: 'original_latest'},
                                          {constants.IMAGE_TAG_KEY: 'existing',
                                           constants.IMAGE_ID_KEY: 'existing'}]}

        upload.update_tags('repo1', data.busybox_tar_path)

        expected_tags = {
            'tags': [{constants.IMAGE_TAG_KEY: 'existing',
                      constants.IMAGE_ID_KEY: 'existing'},
                     {constants.IMAGE_TAG_KEY: 'latest',
                      constants.IMAGE_ID_KEY: data.busybox_ids[0]}]
        }
        mock_update.assert_called_once_with('repo1', expected_tags)
Пример #7
0
    def test_preserves_existing_tags(self, mock_update, mock_get):
        mock_get.return_value = {
            'tags': [{
                constants.IMAGE_TAG_KEY: 'greatest',
                constants.IMAGE_ID_KEY: data.busybox_ids[1]
            }]
        }

        upload.update_tags('repo1', data.busybox_tar_path)

        expected_tags = {
            'tags': [{
                constants.IMAGE_TAG_KEY: 'greatest',
                constants.IMAGE_ID_KEY: data.busybox_ids[1]
            }, {
                constants.IMAGE_TAG_KEY: 'latest',
                constants.IMAGE_ID_KEY: data.busybox_ids[0]
            }]
        }
        mock_update.assert_called_once_with('repo1', expected_tags)
Пример #8
0
    def upload_unit(self, repo, type_id, unit_key, metadata, file_path, conduit, config):
        """
        Upload a docker image. The file should be the product of "docker save".
        This will import all images in that tarfile into the specified
        repository, each as an individual unit. This will also update the
        repo's tags to reflect the tags present in the tarfile.

        The following is copied from the superclass.

        :param repo:      metadata describing the repository
        :type  repo:      pulp.plugins.model.Repository
        :param type_id:   type of unit being uploaded
        :type  type_id:   str
        :param unit_key:  identifier for the unit, specified by the user
        :type  unit_key:  dict
        :param metadata:  any user-specified metadata for the unit
        :type  metadata:  dict
        :param file_path: path on the Pulp server's filesystem to the temporary location of the
                          uploaded file; may be None in the event that a unit is comprised entirely
                          of metadata and has no bits associated
        :type  file_path: str
        :param conduit:   provides access to relevant Pulp functionality
        :type  conduit:   pulp.plugins.conduits.unit_add.UnitAddConduit
        :param config:    plugin configuration for the repository
        :type  config:    pulp.plugins.config.PluginCallConfiguration
        :return:          A dictionary describing the success or failure of the upload. It must
                          contain the following keys:
                            'success_flag': bool. Indicates whether the upload was successful
                            'summary':      json-serializable object, providing summary
                            'details':      json-serializable object, providing details
        :rtype:           dict
        """
        # retrieve metadata from the tarball
        metadata = tarutils.get_metadata(file_path)
        # turn that metadata into a collection of models
        mask_id = config.get(constants.CONFIG_KEY_MASK_ID)
        models = upload.get_models(metadata, mask_id)
        ancestry = tarutils.get_ancestry(models[0].image_id, metadata)
        # save those models as units in pulp
        upload.save_models(conduit, models, ancestry, file_path)
        upload.update_tags(repo.id, file_path)
Пример #9
0
    def upload_unit(self, repo, type_id, unit_key, metadata, file_path, conduit, config):
        """
        Upload a docker image. The file should be the product of "docker save".
        This will import all images in that tarfile into the specified
        repository, each as an individual unit. This will also update the
        repo's tags to reflect the tags present in the tarfile.

        The following is copied from the superclass.

        :param repo:      metadata describing the repository
        :type  repo:      pulp.plugins.model.Repository
        :param type_id:   type of unit being uploaded
        :type  type_id:   str
        :param unit_key:  identifier for the unit, specified by the user
        :type  unit_key:  dict
        :param metadata:  any user-specified metadata for the unit
        :type  metadata:  dict
        :param file_path: path on the Pulp server's filesystem to the temporary location of the
                          uploaded file; may be None in the event that a unit is comprised entirely
                          of metadata and has no bits associated
        :type  file_path: str
        :param conduit:   provides access to relevant Pulp functionality
        :type  conduit:   pulp.plugins.conduits.unit_add.UnitAddConduit
        :param config:    plugin configuration for the repository
        :type  config:    pulp.plugins.config.PluginCallConfiguration
        :return:          A dictionary describing the success or failure of the upload. It must
                          contain the following keys:
                            'success_flag': bool. Indicates whether the upload was successful
                            'summary':      json-serializable object, providing summary
                            'details':      json-serializable object, providing details
        :rtype:           dict
        """
        # retrieve metadata from the tarball
        metadata = tarutils.get_metadata(file_path)
        # turn that metadata into a collection of models
        mask_id = config.get(constants.CONFIG_KEY_MASK_ID)
        models = upload.get_models(metadata, mask_id)
        ancestry = tarutils.get_ancestry(models[0].image_id, metadata)
        # save those models as units in pulp
        upload.save_models(conduit, models, ancestry, file_path)
        upload.update_tags(repo.id, file_path)
Пример #10
0
    def test_overwrite_existing_duplicate_tags(self, mock_update, mock_get):
        mock_get.return_value = {
            'tags': [{
                constants.IMAGE_TAG_KEY: 'latest',
                constants.IMAGE_ID_KEY: 'original_latest'
            }, {
                constants.IMAGE_TAG_KEY: 'existing',
                constants.IMAGE_ID_KEY: 'existing'
            }]
        }

        upload.update_tags('repo1', data.busybox_tar_path)

        expected_tags = {
            'tags': [{
                constants.IMAGE_TAG_KEY: 'existing',
                constants.IMAGE_ID_KEY: 'existing'
            }, {
                constants.IMAGE_TAG_KEY: 'latest',
                constants.IMAGE_ID_KEY: data.busybox_ids[0]
            }]
        }
        mock_update.assert_called_once_with('repo1', expected_tags)