Beispiel #1
0
    def test_distributor_update_with_agent_errors(self, mock_dist_manager,
                                                  mock_bind_manager,
                                                  mock_bind):
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor
        mock_bind_manager.return_value.find_by_distributor.return_value = [{
            'consumer_id':
            'foo',
            'repo_id':
            'repo-foo',
            'distributor_id':
            'dist-id',
            'notify_agent':
            True,
            'binding_config': {
                'conf': 'baz'
            }
        }]
        side_effect_exception = PulpException('foo')
        mock_bind.side_effect = side_effect_exception

        result = repository.distributor_update('foo-id', 'bar-id', {}, None)

        self.assertTrue(isinstance(result.error, PulpException))
        self.assertEquals(result.error.error_code, error_codes.PLP0002)
        self.assertEquals(result.error.child_exceptions[0],
                          side_effect_exception)
Beispiel #2
0
 def test_distributor_update_with_auto_publish(self, mock_dist_manager, mock_bind_manager):
     config = {}
     delta = {'auto_publish': True}
     result = repository.distributor_update('foo-id', 'bar-id', {}, delta)
     mock_dist_manager.return_value.update_distributor_config. \
         assert_called_with('foo-id', 'bar-id', config, True)
     self.assertTrue(isinstance(result, TaskResult))
Beispiel #3
0
    def test_distributor_update_with_bindings(self, mock_dist_manager,
                                              mock_bind_manager, mock_bind):
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor
        mock_bind_manager.return_value.find_by_distributor.return_value = [{
            'consumer_id':
            'foo',
            'repo_id':
            'repo-foo',
            'distributor_id':
            'dist-id',
            'notify_agent':
            True,
            'binding_config': {
                'conf': 'baz'
            }
        }]

        mock_bind.return_value = TaskResult(
            spawned_tasks=[{
                'task_id': 'foo-request-id'
            }])

        result = repository.distributor_update('foo-id', 'bar-id', {}, None)
        self.assertEquals(None, result.error)
        mock_bind.assert_called_once_with('foo', 'repo-foo', 'dist-id', True,
                                          {'conf': 'baz'}, ANY)
        self.assertEquals(result.spawned_tasks[0],
                          {'task_id': 'foo-request-id'})
Beispiel #4
0
 def test_distributor_update_with_auto_publish(self, mock_dist_manager,
                                               mock_bind_manager):
     config = {}
     delta = {'auto_publish': True}
     result = repository.distributor_update('foo-id', 'bar-id', {}, delta)
     mock_dist_manager.return_value.update_distributor_config. \
         assert_called_with('foo-id', 'bar-id', config, True)
     self.assertTrue(isinstance(result, TaskResult))
Beispiel #5
0
    def test_distributor_update_no_bindings(self, mock_dist_manager, mock_bind_manager):
        config = {'configvalue': 'baz'}
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor

        #Use None for the delta value to ensure it doesn't throw an exception
        result = repository.distributor_update('foo-id', 'bar-id', config, None)

        mock_dist_manager.return_value.update_distributor_config. \
            assert_called_with('foo-id', 'bar-id', config, None)
        self.assertTrue(isinstance(result, TaskResult))
        util.compare_dict(generated_distributor, result.return_value)
        self.assertEquals(None, result.error)
Beispiel #6
0
    def test_distributor_update_with_bindings(self, mock_dist_manager, mock_bind_manager,
                                              mock_bind):
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor
        mock_bind_manager.return_value.find_by_distributor.return_value = [
            {'consumer_id': 'foo', 'repo_id': 'repo-foo', 'distributor_id': 'dist-id',
             'notify_agent': True, 'binding_config': {'conf': 'baz'}}]

        mock_bind.return_value = TaskResult(spawned_tasks=[{'task_id': 'foo-request-id'}])

        result = repository.distributor_update('foo-id', 'bar-id', {}, None)
        self.assertEquals(None, result.error)
        mock_bind.assert_called_once_with('foo', 'repo-foo', 'dist-id', True, {'conf': 'baz'}, ANY)
        self.assertEquals(result.spawned_tasks[0], {'task_id': 'foo-request-id'})
Beispiel #7
0
    def test_distributor_update_with_agent_errors(self, mock_dist_manager, mock_bind_manager,
                                                  mock_bind):
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor
        mock_bind_manager.return_value.find_by_distributor.return_value = [
            {'consumer_id': 'foo', 'repo_id': 'repo-foo', 'distributor_id': 'dist-id',
             'notify_agent': True, 'binding_config': {'conf': 'baz'}}]
        side_effect_exception = PulpException('foo')
        mock_bind.side_effect = side_effect_exception

        result = repository.distributor_update('foo-id', 'bar-id', {}, None)

        self.assertTrue(isinstance(result.error, PulpException))
        self.assertEquals(result.error.error_code, error_codes.PLP0002)
        self.assertEquals(result.error.child_exceptions[0], side_effect_exception)
Beispiel #8
0
    def test_distributor_update_no_bindings(self, mock_dist_manager,
                                            mock_bind_manager):
        config = {'configvalue': 'baz'}
        generated_distributor = {'foo': 'bar'}
        mock_dist_manager.return_value.update_distributor_config.return_value = \
            generated_distributor

        # Use None for the delta value to ensure it doesn't throw an exception
        result = repository.distributor_update('foo-id', 'bar-id', config,
                                               None)

        mock_dist_manager.return_value.update_distributor_config. \
            assert_called_with('foo-id', 'bar-id', config, None)
        self.assertTrue(isinstance(result, TaskResult))
        util.compare_dict(generated_distributor, result.return_value)
        self.assertEquals(None, result.error)
Beispiel #9
0
    def update_repo_and_plugins(repo_id, repo_delta, importer_config,
                                distributor_configs):
        """
        Aggregate method that will update one or more of the following:
        * Repository metadata
        * Importer config
        * Zero or more distributors on the repository

        All of the above pieces do not need to be specified. If a piece is
        omitted it's configuration is not touched, nor is it removed from
        the repository. The same holds true for the distributor_configs dict,
        not every distributor must be represented.

        This call will attempt the updates in the order listed above. If an
        exception occurs during any of these steps, the updates stop and the
        exception is immediately raised. Any updates that have already taken
        place are not rolled back.

        This call will call out to RepoImporterManager.update_importer_config.
        Documentation for that method, especially possible exceptions, should be
        consulted for more information.

        Distributor updates will happen asynchronously as there could be a
        very large number of consumers to update and the repo update call
        is usually made synchronously.

        :param repo_id: unique identifier for the repo
        :type  repo_id: str

        :param repo_delta: list of attributes and their new values to change;
               if None, no attempt to update the repo's metadata will be made
        :type  repo_delta: dict, None

        :param importer_config: new configuration to use for the repo's importer;
               if None, no attempt will be made to update the importer
        :type  importer_config: dict, None

        :param distributor_configs: mapping of distributor ID to the new configuration
               to set for it
        :type  distributor_configs: dict, None

        :return: updated repository object, same as returned from update_repo
        :rtype: TaskResult
        """

        # Repo Update
        if repo_delta is None:
            repo_delta = {}
        repo = RepoManager.update_repo(repo_id, repo_delta)

        # Importer Update
        if importer_config is not None:
            importer_manager = manager_factory.repo_importer_manager()
            importer_manager.update_importer_config(repo_id, importer_config)

        errors = []
        additional_tasks = []
        # Distributor Update
        if distributor_configs is not None:
            for dist_id, dist_config in distributor_configs.items():
                update_result = repository.distributor_update(repo_id, dist_id, dist_config, None)
                additional_tasks.extend(update_result.spawned_tasks)
                errors.append(update_result.error)

        error = None
        if len(errors) > 0:
            error = PulpCodedException(error_code=error_codes.PLP0006,
                                       repo_id=repo_id)
            error.child_exceptions = errors
        return TaskResult(repo, error, additional_tasks)