本文整理汇总了Python中pulp.server.db.model.content.ContentCatalog.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python ContentCatalog.get_collection方法的具体用法?Python ContentCatalog.get_collection怎么用?Python ContentCatalog.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.content.ContentCatalog
的用法示例。
在下文中一共展示了ContentCatalog.get_collection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
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, {})
示例2: setUp
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
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, {})
示例3: purge
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def purge(self, source_id):
"""
Purge (delete) entries from the content catalog belonging
to the specified content source by ID.
:param source_id: A content source ID.
:type source_id: str
"""
collection = ContentCatalog.get_collection()
query = {'source_id': source_id}
collection.remove(query, safe=True)
示例4: populate_catalog
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def populate_catalog(self, source_id, n_start, n_units, checksum="0xAA"):
_dir = self.populate_content(source_id, n_start, n_units)
collection = ContentCatalog.get_collection()
entry_list = []
for n in range(n_start, n_start + n_units):
unit_key = {"name": "unit_%d" % n, "version": "1.0.%d" % n, "release": "1", "checksum": checksum}
url = "file://%s/unit_%d" % (_dir, n)
entry = ContentCatalog(source_id, EXPIRES, TYPE_ID, unit_key, url)
entry_list.append(entry)
for entry in entry_list:
collection.insert(entry)
return _dir, entry_list
示例5: purge_orphans
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def purge_orphans(self, valid_ids):
"""
Purge orphan entries from the content catalog.
Entries are orphaned when the content source to which they belong
is no longer loaded.
:param valid_ids: The list of valid (loaded) content source IDs.
:type valid_ids: list
"""
collection = ContentCatalog.get_collection()
for source_id in collection.distinct('source_id'):
if source_id not in valid_ids:
self.purge(source_id)
示例6: test_purge_orphans
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def test_purge_orphans(self):
_dir, cataloged = self.populate_catalog(ORPHANED, 0, 10)
_dir, cataloged = self.populate_catalog(UNDERGROUND, 0, 10)
_dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 10)
collection = ContentCatalog.get_collection()
self.assertEqual(collection.find().count(), 30)
container = ContentContainer(path=self.tmp_dir)
container.purge_orphans()
self.assertEqual(collection.find().count(), 20)
self.assertEqual(collection.find({'source_id': ORPHANED}).count(), 0)
self.assertEqual(collection.find({'source_id': UNDERGROUND}).count(), 10)
self.assertEqual(collection.find({'source_id': UNIT_WORLD}).count(), 10)
示例7: test_add
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def test_add(self):
units = self.units(0, 10)
manager = ContentCatalogManager()
for unit_key, url in units:
manager.add_entry(SOURCE_ID, EXPIRATION, TYPE_ID, unit_key, url)
collection = ContentCatalog.get_collection()
self.assertEqual(len(units), collection.find().count())
for unit_key, url in units:
locator = ContentCatalog.get_locator(TYPE_ID, unit_key)
entry = collection.find_one({'locator': locator})
self.assertEqual(entry['type_id'], TYPE_ID)
self.assertEqual(entry['unit_key'], unit_key)
self.assertEqual(entry['url'], url)
示例8: test_refresh_exception
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def test_refresh_exception(self, mock_refresh):
container = ContentContainer(path=self.tmp_dir)
event = Event()
report = container.refresh(event, force=True)
self.assertEqual(len(report), 2)
for r in report:
self.assertFalse(r.succeeded)
self.assertEqual(r.added_count, 0)
self.assertEqual(r.deleted_count, 0)
self.assertEqual(len(r.errors), 1)
collection = ContentCatalog.get_collection()
self.assertEqual(mock_refresh.call_count, 2)
self.assertEqual(collection.find().count(), 0)
示例9: purge
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def purge(self, source_id):
"""
Purge (delete) entries from the content catalog belonging
to the specified content source by ID.
:param source_id: A content source ID.
:type source_id: str
:return: The number of entries purged.
:rtype: int
"""
collection = ContentCatalog.get_collection()
query = {'source_id': source_id}
result = collection.remove(query)
return result['n']
示例10: purge_expired
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def purge_expired(self, grace_period=GRACE_PERIOD):
"""
Purge (delete) expired entries from the content catalog belonging
to the specified content source by ID.
:param grace_period: The grace period in seconds.
The grace_period defines how long an entry is permitted to remain
in the catalog after it has expired. The default is 1 hour.
:type grace_period: int
"""
collection = ContentCatalog.get_collection()
now = ContentCatalog.get_expiration(0)
timestamp = now - grace_period
query = {'expiration': {'$lt': timestamp}}
collection.remove(query, safe=True)
示例11: delete_entry
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def delete_entry(self, source_id, type_id, unit_key):
"""
Delete an entry from the content catalog.
:param source_id: A content source ID.
:type source_id: str
:param type_id: The unit type ID.
:type type_id: str
:param unit_key: The unit key.
:type unit_key: dict
"""
collection = ContentCatalog.get_collection()
locator = ContentCatalog.get_locator(type_id, unit_key)
query = {'source_id': source_id, 'locator': locator}
collection.remove(query, safe=True)
示例12: test_purge
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def test_purge(self):
source_a = 'A'
source_b = 'B'
manager = ContentCatalogManager()
for unit_key, url in self.units(0, 10):
manager.add_entry(source_a, EXPIRATION, TYPE_ID, unit_key, url)
for unit_key, url in self.units(0, 10):
manager.add_entry(source_b, EXPIRATION, TYPE_ID, unit_key, url)
collection = ContentCatalog.get_collection()
self.assertEqual(20, collection.find().count())
manager = ContentCatalogManager()
manager.purge(source_a)
self.assertEqual(collection.find({'source_id': source_a}).count(), 0)
self.assertEqual(collection.find({'source_id': source_b}).count(), 10)
示例13: test_refresh_failure
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def test_refresh_failure(self, mock_plugin):
container = ContentContainer(path=self.tmp_dir)
event = Event()
report = container.refresh(event, force=True)
self.assertEqual(len(report), 5)
for r in report:
self.assertFalse(r.succeeded)
self.assertEqual(r.added_count, 0)
self.assertEqual(r.deleted_count, 0)
self.assertEqual(len(r.errors), 1)
plugin = mock_plugin.return_value[0]
collection = ContentCatalog.get_collection()
self.assertEqual(plugin.refresh.call_count, 5)
self.assertEqual(collection.find().count(), 0)
示例14: has_entries
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def has_entries(self, source_id):
"""
Get whether the specified content source has entries in the catalog.
:param source_id: A content source ID.
:type source_id: str
:return: True if has entries.
:rtype: bool
"""
collection = ContentCatalog.get_collection()
query = {
'source_id': source_id,
'expiration': {'$gte': ContentCatalog.get_expiration(0)}
}
cursor = collection.find(query)
return cursor.count() > 0
示例15: populate_catalog
# 需要导入模块: from pulp.server.db.model.content import ContentCatalog [as 别名]
# 或者: from pulp.server.db.model.content.ContentCatalog import get_collection [as 别名]
def populate_catalog(self, source_id, n_start, n_units, checksum='0xAA'):
_dir = self.populate_content(source_id, n_start, n_units)
collection = ContentCatalog.get_collection()
entry_list = []
for n in range(n_start, n_start + n_units):
unit_key = {
'name': 'unit_%d' % n,
'version': '1.0.%d' % n,
'release': '1',
'checksum': checksum
}
url = 'file://%s/unit_%d' % (_dir, n)
entry = ContentCatalog(source_id, EXPIRES, TYPE_ID, unit_key, url)
entry_list.append(entry)
for entry in entry_list:
collection.insert(entry, safe=True)
return _dir, entry_list