本文整理汇总了Python中pulp.server.db.model.resources.ReservedResource.save方法的典型用法代码示例。如果您正苦于以下问题:Python ReservedResource.save方法的具体用法?Python ReservedResource.save怎么用?Python ReservedResource.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.resources.ReservedResource
的用法示例。
在下文中一共展示了ReservedResource.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__reserve_resource_with_existing_reservation
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__reserve_resource_with_existing_reservation(self):
"""
Test _reserve_resource() with a resource that has an existing reservation in the database.
It should return the queue listed in the database, and increment the reservation counter.
"""
# Set up an available queue with a reservation count of 1
now = datetime.utcnow()
available_queue_1 = AvailableQueue(RESERVED_WORKER_1, now, 1)
available_queue_1.save()
# Set up a resource reservation, using our available_queue from above
reserved_resource_1 = ReservedResource('resource_1', available_queue_1.name,
available_queue_1.num_reservations)
reserved_resource_1.save()
# This should increase the reserved_resource_1 num_reservations to 2, and should also
# increase available_queue_1's num_reservations to 2. available_queue_1's name should be
# returned
queue = tasks._reserve_resource('resource_1')
self.assertEqual(queue, RESERVED_WORKER_1)
# Make sure that the AvailableQueue is correct
aqc = AvailableQueue.get_collection()
self.assertEqual(aqc.count(), 1)
aq_1 = aqc.find_one({'_id': available_queue_1.name})
self.assertEqual(aq_1['num_reservations'], 2)
# Make sure the ReservedResource is also correct
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], RESERVED_WORKER_1)
self.assertEqual(rr_1['num_reservations'], 2)
示例2: test_resource_not_in_resource_map
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test_resource_not_in_resource_map(self):
"""
Test _release_resource() with a resource that is not in the database. This should be
gracefully handled, and result in no changes to the database.
"""
# Set up two workers
worker_1 = Worker(WORKER_1, datetime.utcnow())
worker_1.save()
worker_2 = Worker(WORKER_2, datetime.utcnow())
worker_2.save()
# Set up two resource reservations, using our workers from above
reserved_resource_1 = ReservedResource(uuid.uuid4(), worker_1.name, 'resource_1')
reserved_resource_1.save()
reserved_resource_2 = ReservedResource(uuid.uuid4(), worker_2.name, 'resource_2')
reserved_resource_2.save()
# This should not raise any Exception, but should also not alter either the Worker
# collection or the ReservedResource collection
tasks._release_resource('made_up_resource_id')
# Make sure that the workers collection has not been altered
self.assertEqual(Worker.objects().count(), 2)
worker_1 = Worker.objects().get(name=worker_1.name)
self.assertTrue(worker_1)
worker_2 = Worker.objects().get(name=worker_2.name)
self.assertTrue(worker_2)
# Make sure that the reserved resources collection has not been altered
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 2)
rr_1 = rrc.find_one({'_id': reserved_resource_1.task_id})
self.assertEqual(rr_1['worker_name'], reserved_resource_1.worker_name)
self.assertEqual(rr_1['resource_id'], 'resource_1')
rr_2 = rrc.find_one({'_id': reserved_resource_2.task_id})
self.assertEqual(rr_2['worker_name'], reserved_resource_2.worker_name)
self.assertEqual(rr_2['resource_id'], 'resource_2')
示例3: test_resource_in_resource_map
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test_resource_in_resource_map(self):
"""
Test _release_resource() with a valid resource. This should remove the resource from the
database.
"""
# Set up two workers
now = datetime.utcnow()
worker_1 = Worker(WORKER_1, now)
worker_1.save()
worker_2 = Worker(WORKER_2, now)
worker_2.save()
# Set up two reserved resources
reserved_resource_1 = ReservedResource(uuid.uuid4(), worker_1.name, 'resource_1')
reserved_resource_1.save()
reserved_resource_2 = ReservedResource(uuid.uuid4(), worker_2.name, 'resource_2')
reserved_resource_2.save()
# This should remove resource_2 from the _resource_map.
tasks._release_resource(reserved_resource_2.task_id)
# resource_2 should have been removed from the database
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.task_id})
self.assertEqual(rr_1['worker_name'], reserved_resource_1.worker_name)
self.assertEqual(rr_1['resource_id'], 'resource_1')
示例4: test__release_resource_task_count_two
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_task_count_two(self):
"""
Test _release_resource() with a resource that has a task count of two. This should simply
decrement the task_count for the resource, but should not remove it from the database.
"""
# Set up two workers
now = datetime.utcnow()
worker_1 = Worker(WORKER_1, now)
worker_1.save()
worker_2 = Worker(WORKER_2, now)
worker_2.save()
# Set up two resource reservations, using our workers from above
reserved_resource_1 = ReservedResource('resource_1', worker_1.name, 7)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', worker_2.name, 2)
reserved_resource_2.save()
# This should reduce the reserved_resource_2 num_reservations to 1.
tasks._release_resource('resource_2')
# Make sure the ReservedResources are also correct
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 2)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
rr_2 = rrc.find_one({'_id': reserved_resource_2.name})
self.assertEqual(rr_2['assigned_queue'], reserved_resource_2.assigned_queue)
self.assertEqual(rr_2['num_reservations'], 1)
示例5: test__release_resource_task_count_one
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_task_count_one(self):
"""
Test _release_resource() with a resource that has a task count of one. This should remove
the resource from the database.
"""
# Set up two workers
now = datetime.utcnow()
worker_1 = Worker(WORKER_1, now)
worker_1.save()
worker_2 = Worker(WORKER_2, now)
worker_2.save()
# Set up two reserved resources
reserved_resource_1 = ReservedResource('resource_1', worker_1.name, 7)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', worker_2.name, 1)
reserved_resource_2.save()
# This should remove resource_2 from the _resource_map.
tasks._release_resource('resource_2')
# resource_2 should have been removed from the database
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
示例6: test__release_resource_task_count_two
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_task_count_two(self):
"""
Test _release_resource() with a resource that has a task count of two. This should simply
decrement the task_count for the resource, but should not remove it from the database.
"""
# Set up two available queues
now = datetime.utcnow()
available_queue_1 = AvailableQueue(RESERVED_WORKER_1, now, 7)
available_queue_1.save()
available_queue_2 = AvailableQueue(RESERVED_WORKER_2, now, 2)
available_queue_2.save()
# Set up two resource reservations, using our available_queues from above
reserved_resource_1 = ReservedResource('resource_1', available_queue_1.name,
available_queue_1.num_reservations)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', available_queue_2.name,
available_queue_2.num_reservations)
reserved_resource_2.save()
# This should reduce the reserved_resource_2 num_reservations to 1, and should also reduce
# available_queue_2's num_reservations to 1.
tasks._release_resource('resource_2')
# Make sure that the AvailableQueues are correct
aqc = AvailableQueue.get_collection()
self.assertEqual(aqc.count(), 2)
aq_1 = aqc.find_one({'_id': available_queue_1.name})
self.assertEqual(aq_1['num_reservations'], 7)
aq_2 = aqc.find_one({'_id': available_queue_2.name})
self.assertEqual(aq_2['num_reservations'], 1)
# Make sure the ReservedResources are also correct
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 2)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
rr_2 = rrc.find_one({'_id': reserved_resource_2.name})
self.assertEqual(rr_2['assigned_queue'], reserved_resource_2.assigned_queue)
self.assertEqual(rr_2['num_reservations'], 1)
示例7: test_create
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test_create(self):
"""
Test for the case when the requested resource does not exist.
"""
# Let's add an ReservedResource just to make sure that it doesn't return any existing
# resource.
rr_1 = ReservedResource('resource_1')
rr_1.save()
rr_2 = resources.get_or_create_reserved_resource('resource_2')
# Assert that the returned instance is correct
self.assertEqual(type(rr_2), ReservedResource)
self.assertEqual(rr_2.name, 'resource_2')
# By default, the assigned_queue should be set to None
self.assertEqual(rr_2.assigned_queue, None)
# A new resource should default to 1 reservations
self.assertEqual(rr_2.num_reservations, 1)
# Now we need to assert that it made it to the database as well
rrc = rr_2.get_collection()
self.assertEqual(rrc.find_one({'_id': 'resource_2'})['num_reservations'], 1)
self.assertEqual(rrc.find_one({'_id': 'resource_2'})['assigned_queue'], None)
示例8: test__release_resource_not_in__resource_map
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_not_in__resource_map(self):
"""
Test _release_resource() with a resource that is not in the database. This should be
gracefully handled, and result in no changes to the database.
"""
# Set up two available queues
available_queue_1 = AvailableQueue(RESERVED_WORKER_1, datetime.utcnow(), 7)
available_queue_1.save()
available_queue_2 = AvailableQueue(RESERVED_WORKER_2, datetime.utcnow(), 3)
available_queue_2.save()
# Set up two resource reservations, using our available_queues from above
reserved_resource_1 = ReservedResource('resource_1', available_queue_1.name,
available_queue_1.num_reservations)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', available_queue_2.name,
available_queue_2.num_reservations)
reserved_resource_2.save()
# This should not raise any Exception, but should also not alter either the AvailableQueue
# collection or the ReservedResource collection
tasks._release_resource('made_up_resource_id')
# Make sure that the available queues collection has not been altered
aqc = AvailableQueue.get_collection()
self.assertEqual(aqc.count(), 2)
aq_1 = aqc.find_one({'_id': available_queue_1.name})
self.assertEqual(aq_1['num_reservations'], 7)
aq_2 = aqc.find_one({'_id': available_queue_2.name})
self.assertEqual(aq_2['num_reservations'], 3)
# Make sure that the reserved resources collection has not been altered
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 2)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
rr_2 = rrc.find_one({'_id': reserved_resource_2.name})
self.assertEqual(rr_2['assigned_queue'], reserved_resource_2.assigned_queue)
self.assertEqual(rr_2['num_reservations'], 3)
示例9: test_get
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test_get(self):
"""
Test for the case when the requested resource does exist.
"""
# Let's add two ReservedResources just to make sure that it doesn't return the wrong
# resource.
rr_1 = ReservedResource('resource_1')
rr_1.save()
rr_2 = ReservedResource('resource_2', 'some_queue', 7)
rr_2.save()
rr_2 = resources.get_or_create_reserved_resource('resource_2')
# Assert that the returned instance is correct
self.assertEqual(type(rr_2), ReservedResource)
self.assertEqual(rr_2.name, 'resource_2')
self.assertEqual(rr_2.assigned_queue, 'some_queue')
# The resource should have 7 reservations
self.assertEqual(rr_2.num_reservations, 7)
# Now we need to assert that the DB is still correct
rrc = rr_2.get_collection()
self.assertEqual(rrc.find_one({'_id': 'resource_2'})['num_reservations'], 7)
self.assertEqual(rrc.find_one({'_id': 'resource_2'})['assigned_queue'], 'some_queue')
示例10: test__release_resource_task_count_one
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_task_count_one(self):
"""
Test _release_resource() with a resource that has a task count of one. This should remove
the resource from the database.
"""
# Set up two available queues
now = datetime.utcnow()
available_queue_1 = AvailableQueue(RESERVED_WORKER_1, now, 7)
available_queue_1.save()
available_queue_2 = AvailableQueue(RESERVED_WORKER_2, now, 1)
available_queue_2.save()
# Set up two reserved resources
reserved_resource_1 = ReservedResource('resource_1', available_queue_1.name,
available_queue_1.num_reservations)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', available_queue_2.name,
available_queue_2.num_reservations)
reserved_resource_2.save()
# This should remove resource_2 from the _resource_map, and should reduce the queue's task
# count to 0.
tasks._release_resource('resource_2')
# available_queue_2 should have had its num_reservations reduced to 0, and the other one
# should have remained the same
aqc = AvailableQueue.get_collection()
self.assertEqual(aqc.count(), 2)
aq_1 = aqc.find_one({'_id': available_queue_1.name})
self.assertEqual(aq_1['num_reservations'], 7)
aq_2 = aqc.find_one({'_id': available_queue_2.name})
self.assertEqual(aq_2['num_reservations'], 0)
# resource_2 should have been removed from the database
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
示例11: test__release_resource_queue_task_count_zero
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__release_resource_queue_task_count_zero(self):
"""
Test _release_resource() with a resource that has a queue with a task count of zero. This
should not decrement the queue task count into the negative range.
"""
# Set up two available queues, the second with a task count of 0
now = datetime.utcnow()
available_queue_1 = AvailableQueue(RESERVED_WORKER_1, now, 7)
available_queue_1.save()
available_queue_2 = AvailableQueue(RESERVED_WORKER_2, now, 0)
available_queue_2.save()
# Set up two reserved resources, and let's make it so the second one is out of sync with its
# queue's task count by setting its num_reservations to 1
reserved_resource_1 = ReservedResource('resource_1', available_queue_1.name,
available_queue_1.num_reservations)
reserved_resource_1.save()
reserved_resource_2 = ReservedResource('resource_2', available_queue_2.name, 1)
reserved_resource_2.save()
# This should remove resource_2 from the _resource_map, but should leave the queue's task
# count at 0.
tasks._release_resource('resource_2')
# The _available_queue_task_counts should remain as they were before, since we don't want
# queue lengths below zero
aqc = AvailableQueue.get_collection()
self.assertEqual(aqc.count(), 2)
aq_1 = aqc.find_one({'_id': available_queue_1.name})
self.assertEqual(aq_1['num_reservations'], 7)
aq_2 = aqc.find_one({'_id': available_queue_2.name})
self.assertEqual(aq_2['num_reservations'], 0)
# resource_2 should have been removed from the database
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], reserved_resource_1.assigned_queue)
self.assertEqual(rr_1['num_reservations'], 7)
示例12: test__reserve_resource_with_existing_reservation
# 需要导入模块: from pulp.server.db.model.resources import ReservedResource [as 别名]
# 或者: from pulp.server.db.model.resources.ReservedResource import save [as 别名]
def test__reserve_resource_with_existing_reservation(self):
"""
Test _reserve_resource() with a resource that has an existing reservation in the database.
It should return the queue listed in the database, and increment the reservation counter.
"""
# Set up a worker with a reservation count of 1
now = datetime.utcnow()
worker_1 = Worker(WORKER_1, now)
worker_1.save()
# Set up a resource reservation, using our worker from above
reserved_resource_1 = ReservedResource('resource_1', worker_1.queue_name, 1)
reserved_resource_1.save()
# This should increase the reserved_resource_1 num_reservations to 2. worker_1's name should
# be returned
queue = tasks._reserve_resource('resource_1')
self.assertEqual(queue, WORKER_1_QUEUE)
# Make sure the ReservedResource is correct
rrc = ReservedResource.get_collection()
self.assertEqual(rrc.count(), 1)
rr_1 = rrc.find_one({'_id': reserved_resource_1.name})
self.assertEqual(rr_1['assigned_queue'], WORKER_1_QUEUE)
self.assertEqual(rr_1['num_reservations'], 2)