Exemplo n.º 1
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
        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))
        self.assertEqual('repo-1', entries[0]['repo_id'])
        self.assertEqual('dist-1', entries[0]['distributor_id'])
        self.assertEqual('mock-distributor', entries[0]['distributor_type_id'])
        self.assertTrue(entries[0]['started'] is not None)
        self.assertTrue(entries[0]['completed'] is not None)
        self.assertEqual(RepoPublishResult.RESULT_FAILED, entries[0]['result'])
        self.assertTrue(entries[0]['summary'] is not None)
        self.assertTrue(entries[0]['details'] is not None)
        self.assertTrue(entries[0]['error_message'] is None)
        self.assertTrue(entries[0]['exception'] is None)
        self.assertTrue(entries[0]['traceback'] is None)

        # Cleanup
        mock_plugins.reset()
Exemplo n.º 2
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
        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))
        self.assertEqual("repo-1", entries[0]["repo_id"])
        self.assertEqual("dist-1", entries[0]["distributor_id"])
        self.assertEqual("mock-distributor", entries[0]["distributor_type_id"])
        self.assertTrue(entries[0]["started"] is not None)
        self.assertTrue(entries[0]["completed"] is not None)
        self.assertEqual(RepoPublishResult.RESULT_FAILED, entries[0]["result"])
        self.assertTrue(entries[0]["summary"] is not None)
        self.assertTrue(entries[0]["details"] is not None)
        self.assertTrue(entries[0]["error_message"] is None)
        self.assertTrue(entries[0]["exception"] is None)
        self.assertTrue(entries[0]["traceback"] is None)

        # Cleanup
        mock_plugins.reset()
Exemplo n.º 3
0
 def tearDown(self):
     base.PulpWebserviceTests.tearDown(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 4
0
 def tearDown(self):
     PulpItineraryTests.tearDown(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 5
0
 def tearDown(self):
     super(BindManagerTests, self).tearDown()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 6
0
 def tearDown(self):
     super(ConsumerTest, self).tearDown()
     Consumer.get_collection().remove(safe=True)
     Repo.get_collection().remove(safe=True)
     RepoDistributor.get_collection().remove(safe=True)
     Bind.get_collection().remove(safe=True)
     mock_plugins.reset()
Exemplo n.º 7
0
    def test_sync_with_graceful_fail(self):
        # Setup
        sync_config = {'bruce': 'hulk', 'tony': 'ironman'}
        self.repo_manager.create_repo('repo-1')
        self.importer_manager.set_importer('repo-1', 'mock-importer',
                                           sync_config)

        mock_plugins.MOCK_IMPORTER.sync_repo.return_value = SyncReport(
            False, 10, 5, 1, 'Summary of the sync', 'Details of the sync')

        # Test
        self.assertRaises(PulpExecutionException, self.sync_manager.sync,
                          'repo-1')

        # Verify
        history = list(RepoSyncResult.get_collection().find(
            {'repo_id': 'repo-1'}))
        self.assertEqual(1, len(history))
        self.assertEqual('repo-1', history[0]['repo_id'])
        self.assertEqual(RepoSyncResult.RESULT_FAILED, history[0]['result'])
        self.assertEqual('mock-importer', history[0]['importer_id'])
        self.assertEqual('mock-importer', history[0]['importer_type_id'])
        self.assertTrue(history[0]['started'] is not None)
        self.assertTrue(history[0]['completed'] is not None)

        # Cleanup
        mock_plugins.reset()
Exemplo n.º 8
0
    def clean(self):
        super(RepoPublishConduitTests, self).clean()

        mock_plugins.reset()

        Repo.get_collection().remove()
        RepoDistributor.get_collection().remove()
Exemplo n.º 9
0
 def tearDown(self):
     super(ConsumerTest, self).tearDown()
     Consumer.get_collection().remove(safe=True)
     Repo.get_collection().remove(safe=True)
     RepoDistributor.get_collection().remove(safe=True)
     Bind.get_collection().remove(safe=True)
     mock_plugins.reset()
Exemplo n.º 10
0
 def tearDown(self):
     base.PulpWebserviceTests.tearDown(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 11
0
    def clean(self):
        super(RepoPublishConduitTests, self).clean()

        mock_plugins.reset()

        Repo.get_collection().remove()
        RepoDistributor.get_collection().remove()
Exemplo n.º 12
0
 def tearDown(self):
     super(BindManagerTests, self).tearDown()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 13
0
 def tearDown(self):
     super(ScheduleTests, self).tearDown()
     mock_plugins.reset()
     self._repo_manager = None
     self._distributor_manager = None
     self._importer_manager = None
     self.schedule_manager = None
Exemplo n.º 14
0
 def tearDown(self):
     super(TestDoSync, self).tearDown()
     mock_plugins.reset()
     manager_factory.reset()
     Repo.get_collection().remove()
     RepoImporter.get_collection().remove()
     RepoSyncResult.get_collection().remove()
     MockRepoPublishManager.reset()
Exemplo n.º 15
0
 def tearDown(self):
     super(TestDoSync, self).tearDown()
     mock_plugins.reset()
     manager_factory.reset()
     Repo.get_collection().remove()
     RepoImporter.get_collection().remove()
     RepoSyncResult.get_collection().remove()
     MockRepoPublishManager.reset()
Exemplo n.º 16
0
 def tearDown(self):
     super(self.__class__, self).tearDown()
     Consumer.get_collection().remove()
     ConsumerGroup.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 17
0
 def tearDown(self):
     super(BindManagerTests, self).tearDown()
     Consumer.get_collection().remove()
     model.Repository.objects.delete()
     model.Distributor.objects.delete()
     Bind.get_collection().remove()
     ConsumerHistoryEvent.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 18
0
 def tearDown(self):
     super(BaseProfilerConduitTests, self).tearDown()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     typedb.clean()
     factory.reset()
     mock_plugins.reset()
Exemplo n.º 19
0
 def tearDown(self):
     super(BaseProfilerConduitTests, self).tearDown()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     typedb.clean()
     factory.reset()
     mock_plugins.reset()
Exemplo n.º 20
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()
Exemplo n.º 21
0
    def test_sync_with_graceful_fail(self):
        # Setup
        sync_config = {'bruce' : 'hulk', 'tony' : 'ironman'}
        self.repo_manager.create_repo('repo-1')
        self.importer_manager.set_importer('repo-1', 'mock-importer', sync_config)

        mock_plugins.MOCK_IMPORTER.sync_repo.return_value = SyncReport(False, 10, 5, 1, 'Summary of the sync', 'Details of the sync')

        # Test
        self.assertRaises(PulpExecutionException, self.sync_manager.sync, 'repo-1')

        # Verify
        history = list(RepoSyncResult.get_collection().find({'repo_id' : 'repo-1'}))
        self.assertEqual(1, len(history))
        self.assertEqual('repo-1', history[0]['repo_id'])
        self.assertEqual(RepoSyncResult.RESULT_FAILED, history[0]['result'])
        self.assertEqual('mock-importer', history[0]['importer_id'])
        self.assertEqual('mock-importer', history[0]['importer_type_id'])
        self.assertTrue(history[0]['started'] is not None)
        self.assertTrue(history[0]['completed'] is not None)

        # Cleanup
        mock_plugins.reset()
Exemplo n.º 22
0
 def tearDown(self):
     super(RepoGroupDistributorManagerTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 23
0
    def tearDown(self):
        super(RepoSyncManagerTests, self).tearDown()
        mock_plugins.reset()

        # Reset the manager factory
        manager_factory.reset()
Exemplo n.º 24
0
 def tearDown(self):
     super(RepoPublishConduitTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 25
0
    def tearDown(self):
        super(RepoSyncConduitTests, self).tearDown()

        types_database.clean()
        mock_plugins.reset()
Exemplo n.º 26
0
class RepoSyncManagerTests(base.PulpServerTests):
    def setUp(self):
        super(RepoSyncManagerTests, self).setUp()
        mock_plugins.install()

        # Create the manager instances for testing
        self.repo_manager = repo_manager.RepoManager()
        self.distributor_manager = distributor_manager.RepoDistributorManager()
        self.publish_manager = publish_manager.RepoPublishManager()

    def tearDown(self):
        super(RepoSyncManagerTests, self).tearDown()
        mock_plugins.reset()

    def clean(self):
        super(RepoSyncManagerTests, self).clean()
        Repo.get_collection().remove()
        RepoDistributor.get_collection().remove()
        RepoPublishResult.get_collection().remove()

    @mock.patch(
        'pulp.server.managers.repo.publish.publish.apply_async_with_reservation'
    )
    def test_queue_publish(self, mock_publish_task):
        repo_id = 'foo'
        distributor_id = 'bar'
        overrides = {'baz': 1}
        self.publish_manager.queue_publish(repo_id, distributor_id, overrides)
        kwargs = {
            'repo_id': repo_id,
            'distributor_id': distributor_id,
            'publish_config_override': overrides
        }
        tags = [
            resource_tag(RESOURCE_REPOSITORY_TYPE, repo_id),
            action_tag('publish')
        ]
        mock_publish_task.assert_called_with(RESOURCE_REPOSITORY_TYPE,
                                             repo_id,
                                             tags=tags,
                                             kwargs=kwargs)

    @mock.patch('pulp.server.managers.repo._common.get_working_directory',
                return_value="/var/cache/pulp/mock_worker/mock_task_id")
    @mock.patch(
        'pulp.server.managers.event.fire.EventFireManager.fire_repo_publish_started'
    )
    @mock.patch(
        'pulp.server.managers.event.fire.EventFireManager.fire_repo_publish_finished'
    )
    def test_publish(self, mock_finished, mock_started,
                     mock_get_working_directory):
        """
        Tests publish under normal conditions when everything is configured
        correctly.
        """

        # 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')
        self.distributor_manager.add_distributor('repo-1',
                                                 'mock-distributor-2',
                                                 publish_config,
                                                 False,
                                                 distributor_id='dist-2')

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

        # Verify

        #   Database
        repo_distributor = RepoDistributor.get_collection().find_one({
            'repo_id':
            'repo-1',
            'id':
            'dist-1'
        })
        self.assertTrue(repo_distributor['last_publish'] is not None)
        self.assertTrue(assert_last_sync_time(
            repo_distributor['last_publish']))

        #   History
        entries = list(RepoPublishResult.get_collection().find(
            {'repo_id': 'repo-1'}))
        self.assertEqual(1, len(entries))
        self.assertEqual('repo-1', entries[0]['repo_id'])
        self.assertEqual('dist-1', entries[0]['distributor_id'])
        self.assertEqual('mock-distributor', entries[0]['distributor_type_id'])
        self.assertTrue(entries[0]['started'] is not None)
        self.assertTrue(entries[0]['completed'] is not None)
        self.assertEqual(RepoPublishResult.RESULT_SUCCESS,
                         entries[0]['result'])
        self.assertTrue(entries[0]['summary'] is not None)
        self.assertTrue(entries[0]['details'] is not None)
        self.assertTrue(entries[0]['error_message'] is None)
        self.assertTrue(entries[0]['exception'] is None)
        self.assertTrue(entries[0]['traceback'] is None)

        #   Call into the correct distributor
        call_args = mock_plugins.MOCK_DISTRIBUTOR.publish_repo.call_args[0]

        self.assertEqual('repo-1', call_args[0].id)
        self.assertTrue(call_args[1] is not None)
        self.assertEqual({}, call_args[2].plugin_config)
        self.assertEqual(publish_config, call_args[2].repo_plugin_config)
        self.assertEqual({}, call_args[2].override_config)

        self.assertEqual(
            0, mock_plugins.MOCK_DISTRIBUTOR_2.publish_repo.call_count)

        self.assertEqual(1, mock_started.call_count)
        self.assertEqual('repo-1', mock_started.call_args[0][0])

        self.assertEqual(1, mock_finished.call_count)
        self.assertEqual('repo-1', mock_finished.call_args[0][0]['repo_id'])

    @mock.patch('pulp.server.managers.repo._common.get_working_directory',
                return_value="/var/cache/pulp/mock_worker/mock_task_id")
    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)

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

        check_me = entries[0]
        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_ERROR, check_me['result'])
        self.assertTrue(check_me['error_message'] is not None)
        self.assertTrue(check_me['exception'] is not None)
        self.assertTrue(check_me['traceback'] is not None)

        # Cleanup
        mock_plugins.reset()
Exemplo n.º 27
0
    def clean(self):
        super(RepoPublishConduitTests, self).clean()

        mock_plugins.reset()
        model.Repository.objects.delete()
        model.Distributor.objects.delete()
Exemplo n.º 28
0
 def tearDown(self):
     super(RepoManagerTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 29
0
 def tearDown(self):
     super(RepoGroupPublishManagerTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 30
0
    def tearDown(self):
        super(RepoSyncManagerTests, self).tearDown()
        mock_plugins.reset()

        # Reset the manager factory
        manager_factory.reset()
Exemplo n.º 31
0
 def tearDown(self):
     super(ImporterScratchPadMixinTests, self).tearDown()
     manager_factory.reset()
     mock_plugins.reset()
Exemplo n.º 32
0
    def clean(self):
        super(RepoPublishConduitTests, self).clean()

        mock_plugins.reset()
        model.Repository.objects.delete()
        model.Distributor.objects.delete()
Exemplo n.º 33
0
 def tearDown(self):
     super(TestDoPublish, self).tearDown()
     mock_plugins.reset()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     RepoPublishResult.get_collection().remove()
Exemplo n.º 34
0
 def tearDown(self):
     super(DistributorScratchpadMixinTests, self).tearDown()
     manager_factory.reset()
     mock_plugins.reset()
Exemplo n.º 35
0
    def tearDown(self):
        super(RepoSyncConduitTests, self).tearDown()

        types_database.clean()
        mock_plugins.reset()
Exemplo n.º 36
0
    def tearDown(self):
        base.PulpServerTests.tearDown(self)
        mock_plugins.reset()

        upload_storage_dir = self.upload_manager._upload_storage_dir()
        shutil.rmtree(upload_storage_dir)
Exemplo n.º 37
0
 def tearDown(self):
     PulpItineraryTests.tearDown(self)
     Consumer.get_collection().remove()
     mock_plugins.reset()
Exemplo n.º 38
0
 def tearDown(self):
     super(RepoGroupPublishManagerTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 39
0
 def tearDown(self):
     super(RepoPublishConduitTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 40
0
 def tearDown(self):
     super(ContentsTest, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 41
0
    def tearDown(self):
        super(DependencyManagerTests, self).tearDown()

        mock_plugins.reset()
Exemplo n.º 42
0
 def tearDown(self):
     super(RepoUnitAssociationManagerTests, self).tearDown()
     mock_plugins.reset()
     manager_factory.reset()
Exemplo n.º 43
0
 def tearDown(self):
     super(RepoConfigConduitTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 44
0
 def tearDown(self):
     super(RepoManagerTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 45
0
 def tearDown(self):
     super(ProfileManagerTests, self).tearDown()
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     mock_plugins.reset()
 def tearDown(self):
     super(DistributorScratchpadMixinTests, self).tearDown()
     manager_factory.reset()
     mock_plugins.reset()
Exemplo n.º 47
0
 def tearDown(self):
     super(RepoGroupCUDTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 48
0
    def tearDown(self):
        super(DependencyManagerTests, self).tearDown()

        mock_plugins.reset()
Exemplo n.º 49
0
 def tearDown(self):
     super(TestDoPublish, self).tearDown()
     mock_plugins.reset()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     RepoPublishResult.get_collection().remove()
Exemplo n.º 50
0
 def tearDown(self):
     super(RepoUnitAssociationManagerTests, self).tearDown()
     mock_plugins.reset()
     manager_factory.reset()
Exemplo n.º 51
0
 def tearDown(self):
     super(ContentsTest, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 52
0
 def tearDown(self):
     super(RepoGroupCUDTests, self).tearDown()
     mock_plugins.reset()
Exemplo n.º 53
0
    def tearDown(self):
        super(RepoGroupDistributorTests, self).tearDown()

        mock_plugins.reset()