def load(cls): """Load all possible Pulp content models and register them as the CLI --model choices. :returns: None """ pm = manager.PluginManager() for model_name in pm.unit_models: cls.add_model(model_name, pm.unit_models[model_name])
def test_load_unit_models_non_content_unit(self, mock_entry_points_iter): """ Test loading of the unit models that don't subclass ContentUnit raise PLP0039 """ req = pkg_resources.Requirement.parse('pulp-devel') dist = pkg_resources.working_set.find(req) entry_string = 'foo=unit.plugins.loader.test_manager:BadContentUnit' entry1 = pkg_resources.EntryPoint.parse(entry_string, dist=dist) mock_entry_points_iter.return_value = [entry1] try: manager.PluginManager() self.fail("This should have raised PLP0039") except exceptions.PulpCodedException, e: self.assertEquals(e.error_code, error_codes.PLP0039)
def test_load_unit_models(self, mock_entry_points_iter, mock_signals): """ Test loading of the unit models entry points """ req = pkg_resources.Requirement.parse('pulp-devel') dist = pkg_resources.working_set.find(req) entry_string = 'foo=unit.plugins.loader.test_manager:ContentUnitHelper' entry = pkg_resources.EntryPoint.parse(entry_string, dist=dist) mock_entry_points_iter.return_value = [entry] plugin_manager = manager.PluginManager() self.assertTrue('foo' in plugin_manager.unit_models) test_model = ContentUnitHelper found_model = plugin_manager.unit_models.get('foo') self.assertTrue(test_model == found_model) mock_signals.assert_called_once_with()
def test_load_unit_models_non_content_unit(self, mock_entry_points_iter): """ Test loading of the unit models that don't subclass ContentUnit raise TypeError """ req = pkg_resources.Requirement.parse('pulp-devel') dist = pkg_resources.working_set.find(req) entry_string = 'foo=unit.plugins.loader.test_manager:BadContentUnit' entry1 = pkg_resources.EntryPoint.parse(entry_string, dist=dist) mock_entry_points_iter.return_value = [entry1] try: manager.PluginManager() self.fail("This should have raised TypeError") except TypeError, e: msg = "The unit model with the id foo failed to register." \ " The class __builtin__.type is not a subclass of ContentUnit." self.assertEquals(e.message, msg)
def test_load_unit_models_id_reused(self, mock_entry_points_iter): """ Test loading of the unit models when the same model id is used twice raises PLP0038 """ req = pkg_resources.Requirement.parse('pulp-devel') dist = pkg_resources.working_set.find(req) entry_string = 'foo=unit.plugins.loader.test_manager:ContentUnitHelper' entry1 = pkg_resources.EntryPoint.parse(entry_string, dist=dist) entry_string = 'foo=unit.plugins.loader.test_manager:ContentUnitHelper' entry2 = pkg_resources.EntryPoint.parse(entry_string, dist=dist) mock_entry_points_iter.return_value = [entry1, entry2] try: manager.PluginManager() self.fail("This should have raised PLP0038") except exceptions.PulpCodedException, e: self.assertEquals(e.error_code, error_codes.PLP0038)
for unit_type, unit_type_factory in MODEL_SOLVABLE_FACTORY_MAPPING.items() } if __name__ == '__main__': argparser = argparse.ArgumentParser() argparser.add_argument('--source-repo', default='zoo') argparser.add_argument('--unit', default='penguin') argparser.add_argument('--target-repo', default='zoo') argparser.add_argument('--ignore-recommends', action='store_true') argparser.add_argument('--debuglevel', choices=[0, 1, 2, 3], type=int, default=0) args = argparser.parse_args() pm = manager.PluginManager() db_initialize() pool = solv.Pool() pool.set_debuglevel(args.debuglevel) pool.setarch() # pretend nothing has been installed so far target_repo = pool.add_repo('@System') target_unit_solvable_factory_mapping = repo_unit_type_factory_mapping(target_repo) load_repo_units(pm, args.target_repo, target_unit_solvable_factory_mapping) pool.installed = target_repo # load the Pulp repo provided on the CLI source_repo = pool.add_repo(args.source_repo) source_unit_solvable_factory_mapping = repo_unit_type_factory_mapping(source_repo)
def setUp(self): super(LoaderTest, self).setUp() self.loader = manager.PluginManager()
def test_loader_instantiation(self): try: l = manager.PluginManager() except Exception, e: self.fail('\n'.join((repr(e), traceback.format_exc())))