Example #1
0
    def build_cancel_report(self, summary, details):
        """
        Creates the PublishReport instance that needs to be returned to the Pulp
        server at the end of the publish_repo call. The report built in this
        fashion will indicate the publish operation has been cancelled.

        @param summary: short log of the publish; may be None but probably shouldn't be
        @type  summary: any serializable

        @param details: potentially longer log of the publish; may be None
        @type  details: any serializable
        """
        r = PublishReport(False, summary, details)
        r.canceled_flag = True
        return r
Example #2
0
File: mixins.py Project: omps/pulp
    def build_cancel_report(self, summary, details):
        """
        Creates the PublishReport instance that needs to be returned to the Pulp
        server at the end of the publish_repo call. The report built in this
        fashion will indicate the publish operation has been cancelled.

        @param summary: short log of the publish; may be None but probably shouldn't be
        @type  summary: any serializable

        @param details: potentially longer log of the publish; may be None
        @type  details: any serializable
        """
        r = PublishReport(False, summary, details)
        r.canceled_flag = True
        return r
Example #3
0
    def test_publish(self):
        # Setup
        summary = 'summary'
        details = 'details'
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.return_value = PublishReport(
            True, summary, details)

        # Test
        override_config = {'o': 'o'}
        self.publish_manager.publish(self.group_id,
                                     self.distributor_id,
                                     publish_config_override=override_config)

        # Verify

        # Plugin Call
        self.assertEqual(
            1, mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.call_count)
        call_args = mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.call_args[
            0]

        self.assertTrue(isinstance(call_args[0], RepositoryGroup))
        self.assertEqual(call_args[0].id, self.group_id)

        self.assertTrue(isinstance(call_args[1], RepoGroupPublishConduit))
        self.assertEqual(call_args[1].group_id, self.group_id)
        self.assertEqual(call_args[1].distributor_id, self.distributor_id)

        self.assertTrue(isinstance(call_args[2], PluginCallConfiguration))
        self.assertEqual(call_args[2].override_config, override_config)

        # History Entry
        history_entries = list(RepoGroupPublishResult.get_collection().find())
        self.assertEqual(1, len(history_entries))
        self.assertEqual(history_entries[0]['group_id'], self.group_id)
        self.assertEqual(history_entries[0]['distributor_id'],
                         self.distributor_id)
        self.assertEqual(history_entries[0]['distributor_type_id'],
                         'mock-group-distributor')
        self.assertTrue(history_entries[0]['started'] is not None)
        self.assertTrue(history_entries[0]['completed'] is not None)
        self.assertEqual(history_entries[0]['result'],
                         RepoGroupPublishResult.RESULT_SUCCESS)
        self.assertTrue(history_entries[0]['error_message'] is None)
        self.assertTrue(history_entries[0]['exception'] is None)
        self.assertTrue(history_entries[0]['traceback'] is None)
        self.assertEqual(history_entries[0]['summary'], summary)
        self.assertEqual(history_entries[0]['details'], details)

        # Distributor Update
        distributor = self.distributor_manager.get_distributor(
            self.group_id, self.distributor_id)
        self.assertTrue(distributor['last_publish'] is not None)

        # Clean Up
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.return_value = None
Example #4
0
File: mixins.py Project: omps/pulp
    def build_success_report(self, summary, details):
        """
        Creates the PublishReport instance that needs to be returned to the Pulp
        server at the end of the publish_repo call.

        @param summary: short log of the publish; may be None but probably shouldn't be
        @type  summary: any serializable

        @param details: potentially longer log of the publish; may be None
        @type  details: any serializable
        """
        r = PublishReport(True, summary, details)
        return r
Example #5
0
File: mixins.py Project: omps/pulp
    def build_failure_report(self, summary, details):
        """
        Creates the PublishReport instance that needs to be returned to the Pulp
        server at the end of the publish_repo call. The report built in this
        fashion will indicate the publish operation has gracefully failed
        (as compared to an unexpected exception bubbling up).

        @param summary: short log of the publish; may be None but probably shouldn't be
        @type  summary: any serializable

        @param details: potentially longer log of the publish; may be None
        @type  details: any serializable
        """
        r = PublishReport(False, summary, details)
        return r
Example #6
0
    def test_publish_with_plugin_failure_report(self):
        # Setup
        summary = 'summary'
        details = 'details'
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.return_value = PublishReport(False, summary, details)

        # Test
        distributor, instance, config = self.publish_manager._get_distributor_instance_and_config(self.group_id, self.distributor_id)
        self.publish_manager.publish(self.group_id, self.distributor_id, distributor, instance, config)

        # Verify
        history_entries = list(RepoGroupPublishResult.get_collection().find())
        self.assertEqual(1, len(history_entries))
        self.assertEqual(history_entries[0]['result'], RepoGroupPublishResult.RESULT_FAILED)
        self.assertEqual(history_entries[0]['summary'], summary)
        self.assertEqual(history_entries[0]['details'], details)

        # Clean Up
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.return_value = None
Example #7
0
    def test_publish_failure_report(self):
        """
        Tests a publish call that indicates a graceful failure.
        """
        # Setup
        publish_config = {'foo': 'bar'}
        self.repo_manager.create_repo('repo-1')
        self.distributor_manager.add_distributor('repo-1',
                                                 'mock-distributor',
                                                 publish_config,
                                                 False,
                                                 distributor_id='dist-1')

        mock_plugins.MOCK_DISTRIBUTOR.publish_repo.return_value = PublishReport(
            False, 'Summary of the publish', 'Details of the publish')

        # Test
        report = self.publish_manager.publish('repo-1', 'dist-1', None)

        # Verify
        entries = list(RepoPublishResult.get_collection().find(
            {'repo_id': 'repo-1'}))
        self.assertEqual(1, len(entries))

        for check_me in entries[0], report:
            self.assertEqual('repo-1', check_me['repo_id'])
            self.assertEqual('dist-1', check_me['distributor_id'])
            self.assertEqual('mock-distributor',
                             check_me['distributor_type_id'])
            self.assertTrue(check_me['started'] is not None)
            self.assertTrue(check_me['completed'] is not None)
            self.assertEqual(RepoPublishResult.RESULT_FAILED,
                             check_me['result'])
            self.assertTrue(check_me['summary'] is not None)
            self.assertTrue(check_me['details'] is not None)
            self.assertTrue(check_me['error_message'] is None)
            self.assertTrue(check_me['exception'] is None)
            self.assertTrue(check_me['traceback'] is None)

        # Cleanup
        mock_plugins.reset()
Example #8
0
    def test_publish_failure_report(self, mock_get_working_directory):
        """
        Tests a publish call that indicates a graceful failure.
        """
        # Setup
        publish_config = {'foo': 'bar'}
        self.repo_manager.create_repo('repo-1')
        self.distributor_manager.add_distributor('repo-1',
                                                 'mock-distributor',
                                                 publish_config,
                                                 False,
                                                 distributor_id='dist-1')

        mock_plugins.MOCK_DISTRIBUTOR.publish_repo.return_value = PublishReport(
            False, 'Summary of the publish', 'Details of the publish')

        # Test
        try:
            self.publish_manager.publish('repo-1', 'dist-1', None)
            self.fail("This should have raised a PulpCodedException")
        except PulpCodedException, data_exception:
            self.assertEquals(data_exception.error_code, error_codes.PLP0034)
 def build_failure_report(self, summary, details):
     return PublishReport(False, summary, details)
 def build_success_report(self, summary, details):
     return PublishReport(True, summary, details)
Example #11
0
def install():
    """
    Called during test setup to monkey patch the plugin loader for testing.
    """

    # -- update plugin loader inventory ---------------------------------------

    plugin_api._create_manager()

    plugin_api._MANAGER.importers.add_plugin('mock-importer', MockImporter, {})
    plugin_api._MANAGER.group_importers.add_plugin('mock-group-importer', MockGroupImporter, {})
    plugin_api._MANAGER.distributors.add_plugin('mock-distributor', MockDistributor, {})
    plugin_api._MANAGER.distributors.add_plugin('mock-distributor-2', MockDistributor, {})
    plugin_api._MANAGER.group_distributors.add_plugin('mock-group-distributor', MockGroupDistributor, {})
    plugin_api._MANAGER.group_distributors.add_plugin('mock-group-distributor-2', MockGroupDistributor, {})
    plugin_api._MANAGER.profilers.add_plugin('mock-profiler', MockProfiler, {})
    plugin_api._MANAGER.profilers.add_plugin('mock-rpm-profiler', MockRpmProfiler, {})

    # -- return mock instances instead of ephemeral ones ----------------------

    # Save the state of the original plugin loader so it can be reverted
    global _ORIG_GET_DISTRIBUTOR_BY_ID
    global _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID
    global _ORIG_GET_IMPORTER_BY_ID
    global _ORIG_GET_GROUP_IMPORTER_BY_ID
    global _ORIG_GET_PROFILER_BY_TYPE

    _ORIG_GET_DISTRIBUTOR_BY_ID = plugin_api.get_distributor_by_id
    _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID = plugin_api.get_group_distributor_by_id
    _ORIG_GET_IMPORTER_BY_ID = plugin_api.get_importer_by_id
    _ORIG_GET_GROUP_IMPORTER_BY_ID = plugin_api.get_group_importer_by_id
    _ORIG_GET_PROFILER_BY_TYPE = plugin_api.get_profiler_by_type

    # Setup the importer/distributor mappings that return the mock instances
    global DISTRIBUTOR_MAPPINGS
    DISTRIBUTOR_MAPPINGS = {
            'mock-distributor' : MOCK_DISTRIBUTOR,
            'mock-distributor-2' : MOCK_DISTRIBUTOR_2,
    }

    global GROUP_DISTRIBUTOR_MAPPINGS
    GROUP_DISTRIBUTOR_MAPPINGS = {
        'mock-group-distributor' : MOCK_GROUP_DISTRIBUTOR,
        'mock-group-distributor-2' : MOCK_GROUP_DISTRIBUTOR_2,
    }

    global IMPORTER_MAPPINGS
    IMPORTER_MAPPINGS = {
        'mock-importer' : MOCK_IMPORTER
    }

    global GROUP_IMPORTER_MAPPINGS
    GROUP_IMPORTER_MAPPINGS = {
        'mock-group-importer' : MOCK_GROUP_IMPORTER
    }

    global PROFILER_MAPPINGS
    PROFILER_MAPPINGS = {}
    for profiler in MOCK_PROFILERS:
        for t in profiler.metadata()['types']:
            PROFILER_MAPPINGS[t] = profiler

    # Return the mock instance; eventually can enhance this to support
    # multiple IDs and instances
    def mock_get_distributor_by_id(id):
        if id not in DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()

        return DISTRIBUTOR_MAPPINGS[id], {}

    def mock_get_group_distributor_by_id(id):
        if id not in GROUP_DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()

        return GROUP_DISTRIBUTOR_MAPPINGS[id], {}

    def mock_get_importer_by_id(id):
        if id not in IMPORTER_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()

        return IMPORTER_MAPPINGS[id], {}

    def mock_get_group_importer_by_id(id):
        if id not in GROUP_IMPORTER_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()

        return GROUP_IMPORTER_MAPPINGS[id], {}

    def mock_get_profiler_by_type(type):
        if type not in PROFILER_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()

        return PROFILER_MAPPINGS[type], {}

    # Monkey patch in the mock methods
    plugin_api.get_distributor_by_id = mock_get_distributor_by_id
    plugin_api.get_group_distributor_by_id = mock_get_group_distributor_by_id
    plugin_api.get_importer_by_id = mock_get_importer_by_id
    plugin_api.get_group_importer_by_id = mock_get_group_importer_by_id
    plugin_api.get_profiler_by_type = mock_get_profiler_by_type

    # -- configure the mock instances -----------------------------------------

    # By default, have the plugins indicate configurations are valid
    MOCK_IMPORTER.validate_config.return_value = True, None
    MOCK_IMPORTER.sync_repo.return_value = SyncReport(True, 10, 5, 1, 'Summary of the sync', 'Details of the sync')

    MOCK_GROUP_IMPORTER.validate_config.return_value = True, None

    MOCK_DISTRIBUTOR.validate_config.return_value = True, None
    MOCK_DISTRIBUTOR.publish_repo.return_value = PublishReport(True, 'Summary of the publish', 'Details of the publish')

    MOCK_DISTRIBUTOR_2.validate_config.return_value = True, None
    MOCK_DISTRIBUTOR_2.publish_repo.return_value = PublishReport(True, 'Summary of the publish', 'Details of the publish')

    MOCK_GROUP_DISTRIBUTOR.validate_config.return_value = True, None
    MOCK_GROUP_DISTRIBUTOR_2.validate_config.return_value = True, None

    for profiler in MOCK_PROFILERS:
        profiler.update_profile = \
            mock.Mock(side_effect=lambda consumer,content_type,profile,config: profile)
        profiler.install_units = \
            mock.Mock(side_effect=lambda i,u,o,c,x: sorted(u))
        profiler.update_units = \
            mock.Mock(side_effect=lambda i,u,o,c,x: sorted(u))
        profiler.uninstall_units = \
            mock.Mock(side_effect=lambda i,u,o,c,x: sorted(u))
        profiler.calculate_applicable_units = \
            mock.Mock(side_effect=lambda t,p,r,c,x: ['mocked-unit1', 'mocked-unit2'])
Example #12
0
 def publish_group(self, *args, **kwargs):
     return PublishReport(True, 'Summary of the publish',
                          'Details of the publish')