Exemplo n.º 1
0
 def setUp(self):
     super(QueryTests, self).setUp()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     self.define_plugins()
     plugin_api._create_manager()
     plugin_api._MANAGER.importers.add_plugin(constants.HTTP_IMPORTER, NodesHttpImporter, {})
Exemplo n.º 2
0
 def setUp(self):
     ServerTests.setUp(self)
     self.parentfs = self.tmpdir('parent-')
     self.childfs = self.tmpdir('child-')
     self.alias = (self.parentfs, self.parentfs)
     self.temp_dir = tempfile.mkdtemp()
     Consumer.get_collection().remove()
     Bind.get_collection().remove()
     model.Repository.objects.delete()
     model.Distributor.objects.delete()
     model.Importer.objects.delete()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     self.define_plugins()
     plugin_api._create_manager()
     imp_conf = dict(strategy=constants.MIRROR_STRATEGY)
     plugin_api._MANAGER.importers.add_plugin(constants.HTTP_IMPORTER,
                                              NodesHttpImporter, imp_conf)
     plugin_api._MANAGER.distributors.add_plugin(constants.HTTP_DISTRIBUTOR,
                                                 NodesHttpDistributor, {})
     plugin_api._MANAGER.distributors.add_plugin(FAKE_DISTRIBUTOR,
                                                 FakeDistributor,
                                                 FAKE_DISTRIBUTOR_CONFIG)
     plugin_api._MANAGER.profilers.add_plugin(constants.PROFILER_ID,
                                              NodeProfiler, {})
Exemplo n.º 3
0
 def setUp(self):
     super(QueryTests, self).setUp()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     self.define_plugins()
     plugin_api._create_manager()
     plugin_api._MANAGER.importers.add_plugin(constants.HTTP_IMPORTER, NodesHttpImporter, {})
Exemplo n.º 4
0
 def setUp(self):
     super(ConsumerTest, self).setUp()
     Consumer.get_collection().remove(safe=True)
     Repo.get_collection().remove(safe=True)
     RepoDistributor.get_collection().remove(safe=True)
     Bind.get_collection().remove(safe=True)
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 5
0
    def setUp(self):
        super(RepoManagerTests, self).setUp()

        plugin_api._create_manager()
        mock_plugins.install()

        # Create the manager instance to test
        self.manager = managers.RepoManager()
Exemplo n.º 6
0
 def setUp(self):
     base.PulpWebserviceTests.setUp(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 7
0
 def setUp(self):
     base.PulpWebserviceTests.setUp(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 8
0
 def setUp(self):
     super(BindManagerTests, self).setUp()
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 9
0
 def setUp(self):
     super(BindManagerTests, self).setUp()
     Consumer.get_collection().remove()
     model.Distributor.objects.delete()
     Bind.get_collection().remove()
     ConsumerHistoryEvent.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 10
0
 def setUp(self):
     super(ScheduledUnitInstallTests, self).setUp()
     plugin_api._create_manager()
     mock_plugins.install()
     mock_agent.install()
     self.consumer_id = 'test-consumer'
     self.consumer_manager = factory.consumer_manager()
     self.consumer_manager.register(self.consumer_id)
Exemplo n.º 11
0
    def setUp(self):
        super(RepoManagerTests, self).setUp()

        plugin_api._create_manager()
        mock_plugins.install()

        # Create the manager instance to test
        self.manager = repo_manager.RepoManager()
Exemplo n.º 12
0
def install():
    """
    Install the plugin loader monkey patch dummy plugins for testing.
    """
    global IMPORTER_MAPPINGS, DISTRIBUTOR_MAPPINGS, GROUP_DISTRIBUTOR_MAPPINGS, \
           _ORIG_GET_IMPORTER_BY_ID, _ORIG_GET_DISTRIBUTOR_BY_ID, _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID

    # update plugin loader inventory

    plugin_api._create_manager()
    plugin_api._MANAGER.importers.add_plugin('dummy-importer', DummyImporter,
                                             {})
    plugin_api._MANAGER.distributors.add_plugin('dummy-distributor',
                                                DummyDistributor, {})
    plugin_api._MANAGER.distributors.add_plugin('dummy-distributor-2',
                                                DummyDistributor, {})
    plugin_api._MANAGER.group_distributors.add_plugin(
        'dummy-group-distributor', DummyGroupDistributor, {})

    # setup the importer/distributor mappings that return the dummy instances

    IMPORTER_MAPPINGS = {'dummy-importer': DUMMY_IMPORTER}
    DISTRIBUTOR_MAPPINGS = {
        'dummy-distributor': DUMMY_DISTRIBUTOR,
        'dummy-distributor-2': DUMMY_DISTRIBUTOR_2
    }
    GROUP_DISTRIBUTOR_MAPPINGS = {
        'dummy-group-distributor': DUMMY_GROUP_DISTRIBUTOR
    }

    # save state of original plugin so it can be reverted

    _ORIG_GET_IMPORTER_BY_ID = plugin_api.get_importer_by_id
    _ORIG_GET_DISTRIBUTOR_BY_ID = plugin_api.get_distributor_by_id
    _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID = plugin_api.get_group_distributor_by_id

    # monkey-patch methods to return the dummy instances

    def dummy_get_importer_by_id(id):
        if id not in IMPORTER_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return IMPORTER_MAPPINGS[id], {}

    def dummy_get_distributor_by_id(id):
        if id not in DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return DISTRIBUTOR_MAPPINGS[id], {}

    def dummy_get_group_distributor_by_id(id):
        if id not in GROUP_DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return GROUP_DISTRIBUTOR_MAPPINGS[id], {}

    # monkey-patch in the dummy methods

    plugin_api.get_importer_by_id = dummy_get_importer_by_id
    plugin_api.get_distributor_by_id = dummy_get_distributor_by_id
    plugin_api.get_group_distributor_by_id = dummy_get_group_distributor_by_id
Exemplo n.º 13
0
 def setUp(self):
     PulpItineraryTests.setUp(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
     mock_agent.install()
Exemplo n.º 14
0
 def setUp(self):
     PulpItineraryTests.setUp(self)
     Consumer.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
     mock_agent.install()
Exemplo n.º 15
0
 def setUp(self):
     super(self.__class__, self).setUp()
     Consumer.get_collection().remove()
     ConsumerGroup.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 16
0
 def setUp(self):
     super(ContainerTest, self).setUp()
     ContentCatalog.get_collection().remove()
     self.tmp_dir = mkdtemp()
     self.downloaded = os.path.join(self.tmp_dir, 'downloaded')
     os.makedirs(self.downloaded)
     self.add_sources()
     plugins._create_manager()
     plugins._MANAGER.catalogers.add_plugin('yum', FakeCataloger, {})
Exemplo n.º 17
0
 def setUp(self):
     super(self.__class__, self).setUp()
     Consumer.get_collection().remove()
     ConsumerGroup.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 18
0
 def setUp(self):
     super(ContainerTest, self).setUp()
     ContentCatalog.get_collection().remove()
     self.tmp_dir = mkdtemp()
     self.downloaded = os.path.join(self.tmp_dir, 'downloaded')
     os.makedirs(self.downloaded)
     self.add_sources()
     plugins._create_manager()
     plugins._MANAGER.catalogers.add_plugin('yum', FakeCataloger, {})
Exemplo n.º 19
0
    def setUp(self):
        super(PluginControllerTests, self).setUp()

        plugin_api._create_manager()
        types_db.clean()

        # Configure content manager
        plugin_api._MANAGER.importers.add_plugin('MockImporter', MockImporter, {})
        plugin_api._MANAGER.distributors.add_plugin('MockDistributor', MockDistributor, {})
Exemplo n.º 20
0
 def setUp(self):
     super(BaseProfilerConduitTests, self).setUp()
     Consumer.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugin_api._create_manager()
     typedb.update_database([self.TYPE_1_DEF, self.TYPE_2_DEF])
     mock_plugins.install()
Exemplo n.º 21
0
 def setUp(self):
     base.PulpWebserviceTests.setUp(self)
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugin_api._create_manager()
     mock_plugins.install()
     profiler = plugin_api.get_profiler_by_type('errata')[0]
     profiler.unit_applicable = \
         mock.Mock(side_effect=lambda i,u,c,x:
             ApplicabilityReport(u, True, self.SUMMARY, self.DETAILS))
Exemplo n.º 22
0
 def setUp(self):
     base.PulpServerTests.setUp(self)
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugins._create_manager()
     mock_plugins.install()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.units_applicable = \
         Mock(side_effect=lambda i,r,t,u,c,x:
              [ApplicabilityReport('mysummary', 'mydetails')])
Exemplo n.º 23
0
 def setUp(self):
     super(BaseProfilerConduitTests, self).setUp()
     Consumer.get_collection().remove()
     RepoDistributor.get_collection().remove()
     Bind.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugin_api._create_manager()
     typedb.update_database([self.TYPE_1_DEF, self.TYPE_2_DEF])
     mock_plugins.install()
Exemplo n.º 24
0
 def setUp(self):
     super(QueryTests, self).setUp()
     Repo.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     for type_id in ALL_TYPES:
         unit_db.type_definition = Mock(return_value=dict(id=type_id, unit_key=UNIT_METADATA))
     unit_db.type_units_unit_key = Mock(return_value=['A', 'B', 'C', 'N'])
     plugin_api._create_manager()
     plugin_api._MANAGER.importers.add_plugin(constants.HTTP_IMPORTER, NodesHttpImporter, {})
Exemplo n.º 25
0
 def setUp(self):
     base.PulpServerTests.setUp(self)
     Consumer.get_collection().remove()
     UnitProfile.get_collection().remove()
     plugins._create_manager()
     mock_plugins.install()
     profiler, cfg = plugins.get_profiler_by_type('rpm')
     profiler.find_applicable_units = \
         Mock(side_effect=lambda i,r,t,u,c,x:
              [ApplicabilityReport('mysummary', 'mydetails')])
Exemplo n.º 26
0
 def setUp(self):
     TestCase.setUp(self)
     api._MANAGER = None
     api._create_manager()
     api._MANAGER.importers.add_plugin(IMPORTER_ID, MockImporter, {})
     api._MANAGER.group_importers.add_plugin(GRP_IMPORTER_ID, MockGroupImporter, {})
     api._MANAGER.distributors.add_plugin(DISTRIBUTOR_ID, MockDistributor, {})
     api._MANAGER.group_distributors.add_plugin(GRP_DISTRIBUTOR_ID, MockGroupDistributor, {})
     api._MANAGER.profilers.add_plugin(PROFILER_ID, MockProfiler, {}, TYPES)
     api._MANAGER.catalogers.add_plugin(CATALOGER_ID, MockCataloger, {})
Exemplo n.º 27
0
    def setUp(self):
        super(PluginControllerTests, self).setUp()

        plugin_api._create_manager()
        types_db.clean()

        # Configure content manager
        plugin_api._MANAGER.importers.add_plugin('MockImporter', MockImporter,
                                                 {})
        plugin_api._MANAGER.distributors.add_plugin('MockDistributor',
                                                    MockDistributor, {})
Exemplo n.º 28
0
 def setUp(self):
     PulpAsyncServerTests.setUp(self)
     ContentCatalog.get_collection().remove()
     self.tmp_dir = mkdtemp()
     self.downloaded = os.path.join(self.tmp_dir, 'downloaded')
     os.makedirs(self.downloaded)
     self.add_sources()
     MockListener.download_started.reset_mock()
     MockListener.download_succeeded.reset_mock()
     MockListener.download_failed.reset_mock()
     plugins._create_manager()
     plugins._MANAGER.catalogers.add_plugin('yum', MockCataloger, {})
Exemplo n.º 29
0
    def setUp(self):
        super(PluginManagerTests, self).setUp()

        plugin_api._create_manager()

        # Configure content manager
        plugin_api._MANAGER.importers.add_plugin('MockImporter', MockImporter, {})
        plugin_api._MANAGER.distributors.add_plugin('MockDistributor', MockDistributor, {})
        plugin_api._MANAGER.profilers.add_plugin('MockProfiler', MockProfiler, {})
        plugin_api._MANAGER.catalogers.add_plugin('MockCataloger', MockCataloger, {})

        # Create the manager instance to test
        self.manager = plugin_manager.PluginManager()
Exemplo n.º 30
0
def install():
    """
    Install the plugin loader monkey patch dummy plugins for testing.
    """
    global IMPORTER_MAPPINGS, DISTRIBUTOR_MAPPINGS, GROUP_DISTRIBUTOR_MAPPINGS, \
           _ORIG_GET_IMPORTER_BY_ID, _ORIG_GET_DISTRIBUTOR_BY_ID, _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID

    # update plugin loader inventory

    plugin_api._create_manager()
    plugin_api._MANAGER.importers.add_plugin('dummy-importer', DummyImporter, {})
    plugin_api._MANAGER.distributors.add_plugin('dummy-distributor', DummyDistributor, {})
    plugin_api._MANAGER.distributors.add_plugin('dummy-distributor-2', DummyDistributor, {})
    plugin_api._MANAGER.group_distributors.add_plugin('dummy-group-distributor', DummyGroupDistributor, {})

    # setup the importer/distributor mappings that return the dummy instances

    IMPORTER_MAPPINGS = {'dummy-importer': DUMMY_IMPORTER}
    DISTRIBUTOR_MAPPINGS = {'dummy-distributor': DUMMY_DISTRIBUTOR,
                            'dummy-distributor-2': DUMMY_DISTRIBUTOR_2}
    GROUP_DISTRIBUTOR_MAPPINGS = {'dummy-group-distributor' : DUMMY_GROUP_DISTRIBUTOR}

    # save state of original plugin so it can be reverted

    _ORIG_GET_IMPORTER_BY_ID = plugin_api.get_importer_by_id
    _ORIG_GET_DISTRIBUTOR_BY_ID = plugin_api.get_distributor_by_id
    _ORIG_GET_GROUP_DISTRIBUTOR_BY_ID = plugin_api.get_group_distributor_by_id

    # monkey-patch methods to return the dummy instances

    def dummy_get_importer_by_id(id):
        if id not in IMPORTER_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return IMPORTER_MAPPINGS[id], {}

    def dummy_get_distributor_by_id(id):
        if id not in DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return DISTRIBUTOR_MAPPINGS[id], {}

    def dummy_get_group_distributor_by_id(id):
        if id not in GROUP_DISTRIBUTOR_MAPPINGS:
            raise plugin_exceptions.PluginNotFound()
        return GROUP_DISTRIBUTOR_MAPPINGS[id], {}

    # monkey-patch in the dummy methods

    plugin_api.get_importer_by_id = dummy_get_importer_by_id
    plugin_api.get_distributor_by_id = dummy_get_distributor_by_id
    plugin_api.get_group_distributor_by_id = dummy_get_group_distributor_by_id
Exemplo n.º 31
0
 def setUp(self):
     WebTest.setUp(self)
     self.upfs = self.tmpdir('upstream-')
     self.downfs = self.tmpdir('downstream-')
     self.alias = (self.upfs, self.upfs)
     Consumer.get_collection().remove()
     Bind.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     RepoImporter.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     plugin_api._create_manager()
     plugin_api._MANAGER.importers.add_plugin(CITRUS_IMPORTER, CitrusHttpImporter, {})
     plugin_api._MANAGER.distributors.add_plugin(CITRUS_DISTRUBUTOR, CitrusHttpDistributor, {})
     unit_db.type_definition = \
         Mock(return_value=dict(id=self.TYPEDEF_ID, unit_key=self.UNIT_METADATA))
     unit_db.type_units_unit_key = \
         Mock(return_value=['A', 'B', 'N'])
Exemplo n.º 32
0
 def setUp(self):
     WebTest.setUp(self)
     self.parentfs = self.tmpdir('parent-')
     self.childfs = self.tmpdir('child-')
     self.alias = (self.parentfs, self.parentfs)
     Consumer.get_collection().remove()
     Bind.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     RepoImporter.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     self.define_plugins()
     plugin_api._create_manager()
     imp_conf = dict(strategy=constants.MIRROR_STRATEGY)
     plugin_api._MANAGER.importers.add_plugin(constants.HTTP_IMPORTER, NodesHttpImporter, imp_conf)
     plugin_api._MANAGER.distributors.add_plugin(constants.HTTP_DISTRIBUTOR, NodesHttpDistributor, {})
     plugin_api._MANAGER.distributors.add_plugin(FAKE_DISTRIBUTOR, FakeDistributor, FAKE_DISTRIBUTOR_CONFIG)
     plugin_api._MANAGER.profilers.add_plugin(constants.PROFILER_ID, NodeProfiler, {})
Exemplo n.º 33
0
 def setUp(self):
     WebTest.setUp(self)
     self.parentfs = self.tmpdir('parent-')
     self.childfs = self.tmpdir('child-')
     self.alias = (self.parentfs, self.parentfs)
     Consumer.get_collection().remove()
     Bind.get_collection().remove()
     Repo.get_collection().remove()
     RepoDistributor.get_collection().remove()
     RepoImporter.get_collection().remove()
     RepoContentUnit.get_collection().remove()
     unit_db.clean()
     plugin_api._create_manager()
     plugin_api._MANAGER.importers.add_plugin(HTTP_IMPORTER, NodesHttpImporter, {})
     plugin_api._MANAGER.distributors.add_plugin(HTTP_DISTRIBUTOR, NodesHttpDistributor, {})
     plugin_api._MANAGER.distributors.add_plugin(FAKE_DISTRIBUTOR, FakeDistributor, {})
     unit_db.type_definition = \
         Mock(return_value=dict(id=self.TYPEDEF_ID, unit_key=self.UNIT_METADATA))
     unit_db.type_units_unit_key = \
         Mock(return_value=['A', 'B', 'N'])
Exemplo n.º 34
0
 def setUp(self):
     super(ContentsTest, self).setUp()
     plugin_api._create_manager()
     mock_plugins.install()
Exemplo n.º 35
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'])
Exemplo n.º 36
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 i, p, c, x: p)
        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.units_applicable = mock.Mock(
            side_effect=lambda i, r, t, u, c, x: [ApplicabilityReport("mocked-summary", "mocked-details")]
        )
Exemplo n.º 37
0
 def setUp(self):
     super(ContentsTest, self).setUp()
     plugin_api._create_manager()
     mock_plugins.install()