Ejemplo n.º 1
0
    def test_create_or_update_type_collection(self):
        """
        Tests the call to create a new type collection works.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'],
                                  ['name'], [])

        # Test
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(
            collection_name in pulp_db.database().collection_names())
Ejemplo n.º 2
0
    def test_create_or_update_existing_type_collection(self):
        """
        Tests calling create_or_update with a change to an existing type
        collection is successful.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'],
                                  ['name'], [])
        types_db._create_or_update_type(type_def)

        # Test
        type_def.display_name = 'new-name'
        type_def.description = 'new-description'
        type_def.unit_key = 'new-key'
        type_def.search_indexes = None
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(
            collection_name in pulp_db.database().collection_names())
Ejemplo n.º 3
0
    def test_create_or_update_existing_type_collection(self):
        """
        Tests calling create_or_update with a change to an existing type
        collection is successful.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'], ['name'], [])
        types_db._create_or_update_type(type_def)

        # Test
        type_def.display_name = 'new-name'
        type_def.description = 'new-description'
        type_def.unit_key = 'new-key'
        type_def.search_indexes = None
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(collection_name in pulp_db.database().collection_names())
Ejemplo n.º 4
0
    def test_create_or_update_type_collection(self):
        """
        Tests the call to create a new type collection works.
        """

        # Setup
        type_def = TypeDefinition('rpm', 'RPM', 'RPM Packages', ['name'], ['name'], [])

        # Test
        types_db._create_or_update_type(type_def)

        # Verify

        #   Present in types collection
        all_types = list(ContentType.get_collection().find())
        self.assertEqual(1, len(all_types))

        found = all_types[0]
        self.assertEqual(type_def.id, found['id'])
        self.assertEqual(type_def.display_name, found['display_name'])
        self.assertEqual(type_def.description, found['description'])
        self.assertEqual(type_def.unit_key, found['unit_key'])
        self.assertEqual(type_def.search_indexes, found['search_indexes'])

        #   Type collection exists
        collection_name = types_db.unit_collection_name(type_def.id)
        self.assertTrue(collection_name in pulp_db.database().collection_names())
Ejemplo n.º 5
0
def _create_or_update_type(type_def):

    # Make sure a collection exists for the type
    database = pulp_db.database()
    collection_name = unit_collection_name(type_def.id)

    if collection_name not in database.collection_names():
        pulp_db.get_collection(collection_name, create=True)

    # Add or update an entry in the types list
    content_type_collection = ContentType.get_collection()
    content_type = ContentType(type_def.id, type_def.display_name, type_def.description,
                               type_def.unit_key, type_def.search_indexes, type_def.referenced_types)
    # no longer rely on _id = id
    existing_type = content_type_collection.find_one({'id': type_def.id}, fields=[])
    if existing_type is not None:
        content_type._id = existing_type['_id']
    # XXX this still causes a potential race condition when 2 users are updating the same type
    content_type_collection.save(content_type, safe=True)
Ejemplo n.º 6
0
def clean():
    """
    Purges the database of all types and their associated collections. This
    isn't really meant to be run from Pulp server code but rather as a utility
    for test cases.
    """

    LOG.info('Purging the database of all content type definitions and collections')

    # Search the database instead of just going on what's in the type listing
    # just in case they got out of sync
    database = pulp_db.database()
    all_collection_names = database.collection_names()
    type_collection_names = [n for n in all_collection_names if n.startswith(TYPE_COLLECTION_PREFIX)]
    for drop_me in type_collection_names:
        database.drop_collection(drop_me)

    # Purge the types collection of all entries
    type_collection = ContentType.get_collection()
    type_collection.remove(safe=True)
Ejemplo n.º 7
0
def _create_or_update_type(type_def):

    # Make sure a collection exists for the type
    database = pulp_db.database()
    collection_name = unit_collection_name(type_def.id)

    if collection_name not in database.collection_names():
        pulp_db.get_collection(collection_name, create=True)

    # Add or update an entry in the types list
    content_type_collection = ContentType.get_collection()
    content_type = ContentType(type_def.id, type_def.display_name,
                               type_def.description, type_def.unit_key,
                               type_def.search_indexes,
                               type_def.referenced_types)
    # no longer rely on _id = id
    existing_type = content_type_collection.find_one({'id': type_def.id},
                                                     fields=[])
    if existing_type is not None:
        content_type._id = existing_type['_id']
    # XXX this still causes a potential race condition when 2 users are updating the same type
    content_type_collection.save(content_type, safe=True)
Ejemplo n.º 8
0
def clean():
    """
    Purges the database of all types and their associated collections. This
    isn't really meant to be run from Pulp server code but rather as a utility
    for test cases.
    """

    LOG.info(
        'Purging the database of all content type definitions and collections')

    # Search the database instead of just going on what's in the type listing
    # just in case they got out of sync
    database = pulp_db.database()
    all_collection_names = database.collection_names()
    type_collection_names = [
        n for n in all_collection_names if n.startswith(TYPE_COLLECTION_PREFIX)
    ]
    for drop_me in type_collection_names:
        database.drop_collection(drop_me)

    # Purge the types collection of all entries
    type_collection = ContentType.get_collection()
    type_collection.remove(safe=True)
Ejemplo n.º 9
0
    def test_comps_import_with_dots_in_pkg_names(self):
        # Test we are able to save problematic package groups/categories to mongo
        db = connection.database()
        dummy_collection_name = "unit_test_dummy_data"
        dummy_collection = getattr(db, dummy_collection_name)

        # Import from a CentOS 6 comps.xml containing:
        # http://mirror.centos.org/centos/6/os/x86_64/repodata/3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c724d098-c6-x86_64-comps.xml
        # <packagereq requires="openoffice.org-core" type="conditional">openoffice.org-langpack-en</packagereq>
        # We were seeing exceptions like below:
        #    InvalidDocument: key 'openoffice.org-langpack-en' must not contain '.'
        success = False
        try:
            repo_src_dir = os.path.join(self.data_dir, "test_comps_import_with_dots_in_pkg_names")
            avail_groups, avail_cats = comps.get_available(repo_src_dir)
            for grp in avail_groups.values():
                dummy_collection.save(grp, safe=True)
            for cat in avail_cats.values():
                dummy_collection.save(cat, safe=True)
            success = True
        finally:
            db.drop_collection(dummy_collection_name)
        self.assertTrue(success)