def test_update_missing_no_error(self): """ Tests that updating a previously loaded database with some missing definitions does not throw an error. """ # Setup defs = [DEF_1, DEF_2, DEF_3] types_db.update_database(defs) # Test new_defs = [DEF_4] types_db.update_database(new_defs) # Verify all_collection_names = types_db.all_type_collection_names() self.assertEqual(len(defs) + len(new_defs), len(all_collection_names)) # old are not deleted for d in defs: self.assertTrue(types_db.unit_collection_name(d.id) in all_collection_names) # Quick sanity check on the indexes collection = types_db.type_units_collection(d.id) all_indexes = collection.index_information() total_index_count = 1 + 1 + len(d.search_indexes) # _id + unit key + all search self.assertEqual(total_index_count, len(all_indexes))
def setUp(self): super(Migration0004Tests, self).setUp() # Special way to import modules that start with a number self.migration = _import_all_the_way( 'pulp_rpm.plugins.migrations.0004_pkg_group_category_repoid') factory.initialize() types_db.update_database([TYPE_DEF_GROUP, TYPE_DEF_CATEGORY]) # Create the repositories necessary for the tests self.source_repo_id = 'source-repo' # where units were copied from with the bad code self.dest_repo_id = 'dest-repo' # where bad units were copied to source_repo = Repo(self.source_repo_id, '') Repo.get_collection().insert(source_repo, safe=True) dest_repo = Repo(self.dest_repo_id, '') Repo.get_collection().insert(dest_repo, safe=True) source_importer = RepoImporter(self.source_repo_id, 'yum_importer', 'yum_importer', {}) RepoImporter.get_collection().insert(source_importer, safe=True) dest_importer = RepoImporter(self.dest_repo_id, 'yum_importer', 'yum_importer', {}) RepoImporter.get_collection().insert(dest_importer, safe=True)
def setUp(self): super(RepoUnitAssociationManagerTests, self).setUp() database.update_database([TYPE_1_DEF, TYPE_2_DEF, MOCK_TYPE_DEF]) mock_plugins.install() self.manager = association_manager.RepoUnitAssociationManager() self.repo_manager = repo_manager.RepoManager() self.importer_manager = importer_manager.RepoImporterManager() self.content_manager = content_cud_manager.ContentManager() # Set up a valid configured repo for the tests self.repo_id = 'associate-repo' self.repo_manager.create_repo(self.repo_id) self.importer_manager.set_importer(self.repo_id, 'mock-importer', {}) # Create units that can be associated to a repo self.unit_type_id = 'mock-type' self.unit_id = 'test-unit-id' self.unit_key = {'key-1': 'test-unit'} self.content_manager.add_content_unit(self.unit_type_id, self.unit_id, self.unit_key) self.unit_id_2 = 'test-unit-id-2' self.unit_key_2 = {'key-1': 'test-unit-2'} self.content_manager.add_content_unit(self.unit_type_id, self.unit_id_2, self.unit_key_2)
def test_update_no_changes(self): """ Tests the common use case of loading type definitions that have been loaded already and have not changed. """ # Setup defs = [DEF_1, DEF_2, DEF_3, DEF_4] types_db.update_database(defs) # Test same_defs = [ DEF_4, DEF_3, DEF_2, DEF_1 ] # no real reason for this, just felt better than using the previous list types_db.update_database(same_defs) # Verify all_collection_names = types_db.all_type_collection_names() self.assertEqual(len(same_defs), len(all_collection_names)) for d in defs: self.assertTrue( types_db.unit_collection_name(d.id) in all_collection_names) # Quick sanity check on the indexes collection = types_db.type_units_collection(d.id) all_indexes = collection.index_information() total_index_count = 1 + 1 + len( d.search_indexes) # _id + unit key + all search self.assertEqual(total_index_count, len(all_indexes))
def init_types(self): database.clean() fp = open(self.TYPES_PATH) td = TypeDescriptor(os.path.basename(self.TYPES_PATH), fp.read()) fp.close() definitions = parser.parse([td]) database.update_database(definitions)
def setUp(self): super(UnitAssociationQueryTests, self).setUp() database.update_database(_QUERY_TYPES) self.manager = association_query_manager.RepoUnitAssociationQueryManager() self.association_manager = association_manager.RepoUnitAssociationManager() self.content_manager = content_cud_manager.ContentManager() self._populate()
def test_update_missing_no_error(self): """ Tests that updating a previously loaded database with some missing definitions does not throw an error. """ # Setup defs = [DEF_1, DEF_2, DEF_3] types_db.update_database(defs) # Test new_defs = [DEF_4] types_db.update_database(new_defs) # Verify all_collection_names = types_db.all_type_collection_names() self.assertEqual(len(defs) + len(new_defs), len(all_collection_names)) # old are not deleted for d in defs: self.assertTrue( types_db.unit_collection_name(d.id) in all_collection_names) # Quick sanity check on the indexes collection = types_db.type_units_collection(d.id) all_indexes = collection.index_information() total_index_count = 1 + 1 + len( d.search_indexes) # _id + unit key + all search self.assertEqual(total_index_count, len(all_indexes))
def setUp(self): super(RepoUnitAssociationManagerTests, self).setUp() database.update_database([TYPE_1_DEF, TYPE_2_DEF, MOCK_TYPE_DEF]) mock_plugins.install() self.manager = association_manager.RepoUnitAssociationManager() self.content_manager = content_cud_manager.ContentManager() # Set up a valid configured repo for the tests self.repo_id = 'associate-repo' with mock.patch('pulp.server.controllers.importer.model.Repository'): importer_controller.set_importer(self.repo_id, 'mock-importer', {}) # Create units that can be associated to a repo self.unit_type_id = 'mock-type' self.unit_id = 'test-unit-id' self.unit_key = {'key-1': 'test-unit'} self.content_manager.add_content_unit(self.unit_type_id, self.unit_id, self.unit_key) self.unit_id_2 = 'test-unit-id-2' self.unit_key_2 = {'key-1': 'test-unit-2'} self.content_manager.add_content_unit(self.unit_type_id, self.unit_id_2, self.unit_key_2)
def setUp(self): super(Migration0004Tests, self).setUp() # Special way to import modules that start with a number self.migration = _import_all_the_way( 'pulp_rpm.plugins.migrations.0004_pkg_group_category_repoid') factory.initialize() api.initialize(False) types_db.update_database([TYPE_DEF_GROUP, TYPE_DEF_CATEGORY]) # Create the repositories necessary for the tests self.source_repo_id = 'source-repo' # where units were copied from with the bad code self.dest_repo_id = 'dest-repo' # where bad units were copied to source_repo = model.Repository(repo_id=self.source_repo_id) source_repo.save() dest_repo = model.Repository(repo_id=self.dest_repo_id) dest_repo.save() source_importer = model.Importer(self.source_repo_id, 'yum_importer', {}) source_importer.save() dest_importer = model.Importer(self.dest_repo_id, 'yum_importer', {}) dest_importer.save()
def test_update_no_changes(self): """ Tests the common use case of loading type definitions that have been loaded already and have not changed. """ # Setup defs = [DEF_1, DEF_2, DEF_3, DEF_4] types_db.update_database(defs) # Test same_defs = [DEF_4, DEF_3, DEF_2, DEF_1] # no real reason for this, just felt better than using the previous list types_db.update_database(same_defs) # Verify all_collection_names = types_db.all_type_collection_names() self.assertEqual(len(same_defs), len(all_collection_names)) for d in defs: self.assertTrue(types_db.unit_collection_name(d.id) in all_collection_names) # Quick sanity check on the indexes collection = types_db.type_units_collection(d.id) all_indexes = collection.index_information() total_index_count = 1 + 1 + len(d.search_indexes) # _id + unit key + all search self.assertEqual(total_index_count, len(all_indexes))
def load_content_types(types_dir=_TYPES_DIR, dry_run=False, drop_indices=False): """ Check or update database with content unit types information. :param types_dir: path to content unit type JSON files, currently used only for node.json :type types_dir: str :param dry_run: if True, no modifications to database will be made, defaults to False :type dry_run: bool :param drop_indices: if True, indices for the collections of modified unit types will be dropped, defaults to False :type drop_indices: bool :return: None if dry_run is set to False, list of content unit types to be created or updated, if dry_run is set to True :rtype: None or list of TypeDefinition """ if not os.access(types_dir, os.F_OK | os.R_OK): msg = _('Cannot load types: path does not exist or cannot be read: %(p)s') _logger.critical(msg % {'p': types_dir}) raise IOError(msg % {'p': types_dir}) # to handle node.json only descriptors = _load_type_descriptors(types_dir) pre_mongoengine_definitions = parser.parse(descriptors) # get information about content unit types from entry points mongoengine_definitions = _generate_plugin_definitions() if dry_run: return _check_content_definitions(pre_mongoengine_definitions + mongoengine_definitions) else: database.update_database(pre_mongoengine_definitions, drop_indices=drop_indices, create_indexes=True) database.update_database(mongoengine_definitions, drop_indices=drop_indices, create_indexes=False)
def setUp(self): super(GetUnitsByTypeStressTest, self).setUp() database.update_database(_QUERY_TYPES) self.manager = association_query_manager.RepoUnitAssociationQueryManager( ) self.association_manager = association_query_manager.RepoUnitAssociationQueryManager( ) self.content_manager = content_cud_manager.ContentManager()
def setUp(self): super(UnitAssociationQueryTests, self).setUp() database.update_database(_QUERY_TYPES) self.manager = association_query_manager.RepoUnitAssociationQueryManager() self.association_manager = association_manager.RepoUnitAssociationManager() self.content_manager = content_cud_manager.ContentManager() # so we don't try to refresh the unit count on non-existing repos manager_factory._CLASSES[manager_factory.TYPE_REPO] = mock.MagicMock() self._populate()
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()
def setUp(self): super(RepoUnitAssociationManagerTests, self).setUp() database.update_database([TYPE_1_DEF, TYPE_2_DEF, MOCK_TYPE_DEF]) mock_plugins.install() # so we don't try to refresh the unit count on non-existing repos manager_factory._CLASSES[manager_factory.TYPE_REPO] = mock.MagicMock() self.manager = association_manager.RepoUnitAssociationManager() self.repo_manager = repo_manager.RepoManager() self.importer_manager = importer_manager.RepoImporterManager() self.content_manager = content_cud_manager.ContentManager()
def setUp(self): super(DependencyManagerTests, self).setUp() mock_plugins.install() database.update_database([TYPE_1_DEF]) self.repo_id = 'dep-repo' self.manager = manager_factory.dependency_manager() manager_factory.repo_manager().create_repo(self.repo_id) manager_factory.repo_importer_manager().set_importer(self.repo_id, 'mock-importer', {})
def setUp(self, mock_repo_qs, mock_imp_qs, mock_remove): super(RepoSyncConduitTests, self).setUp() mock_plugins.install() types_database.update_database([TYPE_1_DEF, TYPE_2_DEF]) self.association_manager = association_manager.RepoUnitAssociationManager() self.association_query_manager = association_query_manager.RepoUnitAssociationQueryManager() self.content_manager = content_manager.ContentManager() self.query_manager = query_manager.ContentQueryManager() self.conduit = RepoSyncConduit('repo-1', 'test-importer', 'abc123') importer_controller.set_importer('repo-1', 'mock-importer', {})
def setUp(self): super(DependencyManagerTests, self).setUp() mock_plugins.install() database.update_database([TYPE_1_DEF]) self.repo_id = 'dep-repo' self.manager = manager_factory.dependency_manager() manager_factory.repo_manager().create_repo(self.repo_id) manager_factory.repo_importer_manager().set_importer( self.repo_id, 'mock-importer', {})
def test_all_type_definitions(self): """ Tests retrieving all type definitions from the database. """ # Setup defs = [DEF_1, DEF_2, DEF_3, DEF_4] types_db.update_database(defs) # Test all_defs = types_db.all_type_definitions() # Verify self.assertEqual(4, len(all_defs))
def setUp(self): super(RepoSyncConduitTests, self).setUp() mock_plugins.install() types_database.update_database([TYPE_1_DEF, TYPE_2_DEF]) self.repo_manager = repo_manager.RepoManager() self.importer_manager = importer_manager.RepoImporterManager() self.sync_manager = sync_manager.RepoSyncManager() self.association_manager = association_manager.RepoUnitAssociationManager() self.association_query_manager = association_query_manager.RepoUnitAssociationQueryManager() self.content_manager = content_manager.ContentManager() self.query_manager = query_manager.ContentQueryManager() self.repo_manager.create_repo('repo-1') self.conduit = RepoSyncConduit('repo-1', 'test-importer', 'importer', 'importer-id')
def setUp(self): super(RepoSyncConduitTests, self).setUp() mock_plugins.install() types_database.update_database([TYPE_1_DEF, TYPE_2_DEF]) self.repo_manager = repo_manager.RepoManager() self.importer_manager = importer_manager.RepoImporterManager() self.sync_manager = sync_manager.RepoSyncManager() self.association_manager = association_manager.RepoUnitAssociationManager() self.association_query_manager = association_query_manager.RepoUnitAssociationQueryManager() self.content_manager = content_manager.ContentManager() self.query_manager = query_manager.ContentQueryManager() self.repo_manager.create_repo('repo-1') self.importer_manager.set_importer('repo-1', 'mock-importer', {}) self.conduit = RepoSyncConduit('repo-1', 'test-importer', 'importer', 'importer-id')
def test_update_failed_create(self): """ Simulates a failure to create a collection by passing in a bad ID for the definition. """ # Setup busted = TypeDefinition('!@#$%^&*()', 'Busted', 'Busted', None, None, []) defs = [DEF_1, busted] # Tests try: types_db.update_database(defs) self.fail('Update with a failed create did not raise exception') except types_db.UpdateFailed, e: self.assertEqual(1, len(e.type_definitions)) self.assertEqual(busted, e.type_definitions[0]) print(e)
def load_content_types(types_dir=_TYPES_DIR, dry_run=False, drop_indices=False): """ Check or update database with content unit types information. :param types_dir: path to content unit type JSON files, currently used only for node.json :type types_dir: str :param dry_run: if True, no modifications to database will be made, defaults to False :type dry_run: bool :param drop_indices: if True, indices for the collections of modified unit types will be dropped, defaults to False :type drop_indices: bool :return: None if dry_run is set to False, list of content unit types to be created or updated, if dry_run is set to True :rtype: None or list of TypeDefinition """ if not os.access(types_dir, os.F_OK | os.R_OK): msg = _( 'Cannot load types: path does not exist or cannot be read: %(p)s') _logger.critical(msg % {'p': types_dir}) raise IOError(msg % {'p': types_dir}) # to handle node.json only descriptors = _load_type_descriptors(types_dir) pre_mongoengine_definitions = parser.parse(descriptors) # get information about content unit types from entry points mongoengine_definitions = _generate_plugin_definitions() if dry_run: return _check_content_definitions(pre_mongoengine_definitions + mongoengine_definitions) else: database.update_database(pre_mongoengine_definitions, drop_indices=drop_indices, create_indexes=True) database.update_database(mongoengine_definitions, drop_indices=drop_indices, create_indexes=False)
def test_update_missing_with_error(self): """ Tests that updating a previously loaded database with some missing definitions correctly throws an error when requested. """ # Setup defs = [DEF_1, DEF_2, DEF_3] types_db.update_database(defs) # Test new_defs = [DEF_4] try: types_db.update_database(new_defs, error_on_missing_definitions=True) self.fail('MissingDefinitions exception expected') except types_db.MissingDefinitions, e: self.assertEqual(3, len(e.missing_type_ids)) self.assertTrue(DEF_1.id in e.missing_type_ids) self.assertTrue(DEF_2.id in e.missing_type_ids) self.assertTrue(DEF_3.id in e.missing_type_ids) print(e) # used to test the __str__ impl
def test_update_clean_database(self): """ Tests calling update on a completely clean types database. """ # Test defs = [DEF_1, DEF_2, DEF_3, DEF_4] types_db.update_database(defs) # Verify all_collection_names = types_db.all_type_collection_names() self.assertEqual(len(defs), len(all_collection_names)) for d in defs: self.assertTrue(types_db.unit_collection_name(d.id) in all_collection_names) # Quick sanity check on the indexes collection = types_db.type_units_collection(d.id) all_indexes = collection.index_information() total_index_count = 1 + 1 + len(d.search_indexes) # _id + unit key + all search self.assertEqual(total_index_count, len(all_indexes))
def setUp(self): super(OrphanManagerTests, self).setUp() content_type_db.update_database([PHONY_TYPE_1, PHONY_TYPE_2]) self.content_root = tempfile.mkdtemp(prefix='content_orphan_manager_unittests-') self.orphan_manager = OrphanManager()
def setUp(self): super(PulpContentTests, self).setUp() database.update_database([TYPE_1_DEF, TYPE_2_DEF]) self.cud_manager = ContentManager() self.query_manager = ContentQueryManager()
def _load_type_definitions(descriptors): """ @type descriptors: list [L{TypeDescriptor}, ...] """ definitions = parser.parse(descriptors) database.update_database(definitions)
def _load_type_definitions(descriptors, drop_indices=False): """ :type descriptors: list [TypeDescriptor, ...] """ definitions = parser.parse(descriptors) database.update_database(definitions, drop_indices=drop_indices)
def setUp(self): super(OrphanManagerTests, self).setUp() content_type_db.update_database([PHONY_TYPE_1, PHONY_TYPE_2]) self.content_root = tempfile.mkdtemp( prefix='content_orphan_manager_unittests-') self.orphan_manager = OrphanManager()
def _load_type_definitions(descriptors): """ :type descriptors: list [TypeDescriptor, ...] """ definitions = parser.parse(descriptors) database.update_database(definitions)
def setUp(self): super(GetUnitsByTypeStressTest, self).setUp() database.update_database(_QUERY_TYPES) self.manager = association_query_manager.RepoUnitAssociationQueryManager() self.association_manager = association_query_manager.RepoUnitAssociationQueryManager() self.content_manager = content_cud_manager.ContentManager()