当前位置: 首页>>代码示例>>Python>>正文


Python Worker.save方法代码示例

本文整理汇总了Python中pulp.server.db.model.Worker.save方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.save方法的具体用法?Python Worker.save怎么用?Python Worker.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp.server.db.model.Worker的用法示例。


在下文中一共展示了Worker.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_resource_in_resource_map

# 需要导入模块: from pulp.server.db.model import Worker [as 别名]
# 或者: from pulp.server.db.model.Worker 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(name=WORKER_1, last_heartbeat=now)
        worker_1.save()
        worker_2 = Worker(name=WORKER_2, last_heartbeat=now)
        worker_2.save()
        # Set up two reserved resources
        reserved_resource_1 = ReservedResource(task_id=str(uuid.uuid4()),
                                               worker_name=worker_1.name, resource_id='resource_1')
        reserved_resource_1.save()
        reserved_resource_2 = ReservedResource(task_id=str(uuid.uuid4()),
                                               worker_name=worker_2.name, resource_id='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
        self.assertEqual(ReservedResource.objects.count(), 1)
        rr_1 = ReservedResource.objects.get(task_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')
开发者ID:zjhuntin,项目名称:pulp,代码行数:29,代码来源:test_tasks.py

示例2: test_resource_not_in_resource_map

# 需要导入模块: from pulp.server.db.model import Worker [as 别名]
# 或者: from pulp.server.db.model.Worker 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(str(uuid.uuid4()), worker_1.name, 'resource_1')
        reserved_resource_1.save()
        reserved_resource_2 = ReservedResource(str(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
        self.assertEqual(ReservedResource.objects.count(), 2)
        rr_1 = ReservedResource.objects.get(task_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 = ReservedResource.objects.get(task_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')
开发者ID:credativ,项目名称:pulp,代码行数:36,代码来源:test_tasks.py


注:本文中的pulp.server.db.model.Worker.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。