Beispiel #1
0
    def _do_publish(self, group, distributor_id, distributor_instance, conduit, call_config):

        distributor_coll = RepoGroupDistributor.get_collection()
        publish_result_coll = RepoGroupPublishResult.get_collection()
        group_id = group.id

        # Perform the publish
        publish_start_timestamp = _now_timestamp()
        try:
            report = distributor_instance.publish_group(group, conduit, call_config)
        except Exception, e:
            publish_end_timestamp = _now_timestamp()

            # Reload the distributor in case the scratchpad is changed by the plugin
            distributor = distributor_coll.find_one({'id' : distributor_id, 'repo_group_id' : group_id})
            distributor['last_publish'] = publish_end_timestamp
            distributor_coll.save(distributor)

            # Add a publish history entry for the run
            result = RepoGroupPublishResult.error_result(group_id, distributor_id,
                     distributor['distributor_type_id'], publish_start_timestamp,
                     publish_end_timestamp, e, sys.exc_info()[2])
            publish_result_coll.save(result, safe=True)

            _LOG.exception('Exception caught from plugin during publish call for group [%s]' % group_id)
            raise PulpExecutionException(e), None, sys.exc_info()[2]
Beispiel #2
0
    def _do_publish(group, distributor_id, distributor_instance, conduit,
                    call_config):

        distributor_coll = RepoGroupDistributor.get_collection()
        publish_result_coll = RepoGroupPublishResult.get_collection()
        group_id = group.id

        # Perform the publish
        publish_start_timestamp = _now_timestamp()
        try:
            report = distributor_instance.publish_group(
                group, conduit, call_config)
        except Exception, e:
            publish_end_timestamp = _now_timestamp()

            # Reload the distributor in case the scratchpad is changed by the plugin
            distributor = distributor_coll.find_one({
                'id': distributor_id,
                'repo_group_id': group_id
            })
            distributor['last_publish'] = publish_end_timestamp
            distributor_coll.save(distributor)

            # Add a publish history entry for the run
            result = RepoGroupPublishResult.error_result(
                group_id, distributor_id, distributor['distributor_type_id'],
                publish_start_timestamp, publish_end_timestamp, e,
                sys.exc_info()[2])
            publish_result_coll.save(result)

            raise
Beispiel #3
0
    def _do_publish(group, distributor_id, distributor_instance, conduit, call_config):

        distributor_coll = RepoGroupDistributor.get_collection()
        publish_result_coll = RepoGroupPublishResult.get_collection()
        group_id = group.id

        # Perform the publish
        publish_start_timestamp = _now_timestamp()
        try:
            report = distributor_instance.publish_group(group, conduit, call_config)
        except Exception, e:
            publish_end_timestamp = _now_timestamp()

            # Reload the distributor in case the scratchpad is changed by the plugin
            distributor = distributor_coll.find_one({"id": distributor_id, "repo_group_id": group_id})
            distributor["last_publish"] = publish_end_timestamp
            distributor_coll.save(distributor)

            # Add a publish history entry for the run
            result = RepoGroupPublishResult.error_result(
                group_id,
                distributor_id,
                distributor["distributor_type_id"],
                publish_start_timestamp,
                publish_end_timestamp,
                e,
                sys.exc_info()[2],
            )
            publish_result_coll.save(result, safe=True)

            raise
Beispiel #4
0
    def test_publish_with_plugin_no_report(self):
        # Test
        self.publish_manager.publish(self.group_id, self.distributor_id)

        # Verify
        history_entries = list(RepoGroupPublishResult.get_collection().find())
        self.assertEqual(1, len(history_entries))
        self.assertEqual(history_entries[0]['result'], RepoGroupPublishResult.RESULT_SUCCESS)
Beispiel #5
0
    def test_publish_with_plugin_no_report(self, mock_get_working_directory):
        # Test
        self.publish_manager.publish(self.group_id, self.distributor_id)

        # Verify
        history_entries = list(RepoGroupPublishResult.get_collection().find())
        self.assertEqual(1, len(history_entries))
        self.assertEqual(history_entries[0]['result'], RepoGroupPublishResult.RESULT_SUCCESS)
Beispiel #6
0
    def test_publish_with_plugin_no_report(self):
        # 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_SUCCESS)
Beispiel #7
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
Beispiel #8
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
    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
        self.publish_manager.publish(self.group_id, self.distributor_id)

        # 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
Beispiel #10
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
    def test_publish_with_plugin_exception(self):
        # Setup
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.side_effect = Exception()

        # Test
        self.assertRaises(PulpExecutionException, self.publish_manager.publish, self.group_id, self.distributor_id)

        # Verify
        history_entries = list(RepoGroupPublishResult.get_collection().find())
        self.assertEqual(1, len(history_entries))
        self.assertEqual(history_entries[0]['result'], RepoGroupPublishResult.RESULT_ERROR)
        self.assertTrue(history_entries[0]['error_message'] is not None)
        self.assertTrue(history_entries[0]['exception'] is not None)
        self.assertTrue(history_entries[0]['traceback'] is not None)
        self.assertTrue(history_entries[0]['summary'] is None)
        self.assertTrue(history_entries[0]['details'] is None)

        # Clean Up
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.side_effect = None
Beispiel #12
0
    def test_publish_with_plugin_exception(self):
        # Setup
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.side_effect = Exception()

        # Test
        distributor, instance, config = self.publish_manager._get_distributor_instance_and_config(self.group_id, self.distributor_id)
        self.assertRaises(PulpExecutionException, 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_ERROR)
        self.assertTrue(history_entries[0]['error_message'] is not None)
        self.assertTrue(history_entries[0]['exception'] is not None)
        self.assertTrue(history_entries[0]['traceback'] is not None)
        self.assertTrue(history_entries[0]['summary'] is None)
        self.assertTrue(history_entries[0]['details'] is None)

        # Clean Up
        mock_plugins.MOCK_GROUP_DISTRIBUTOR.publish_group.side_effect = None
Beispiel #13
0
    def clean(self):
        super(RepoGroupPublishManagerTests, self).clean()

        RepoGroup.get_collection().remove()
        RepoGroupDistributor.get_collection().remove()
        RepoGroupPublishResult.get_collection().remove()