本文整理汇总了Python中pulp.server.dispatch.call.CallRequest.add_control_hook方法的典型用法代码示例。如果您正苦于以下问题:Python CallRequest.add_control_hook方法的具体用法?Python CallRequest.add_control_hook怎么用?Python CallRequest.add_control_hook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.dispatch.call.CallRequest
的用法示例。
在下文中一共展示了CallRequest.add_control_hook方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_control_hooks
# 需要导入模块: from pulp.server.dispatch.call import CallRequest [as 别名]
# 或者: from pulp.server.dispatch.call.CallRequest import add_control_hook [as 别名]
def test_control_hooks(self):
call_request = CallRequest(function)
for key in dispatch_constants.CALL_CONTROL_HOOKS:
self.assertTrue(call_request.control_hooks[key] is None)
for key in dispatch_constants.CALL_CONTROL_HOOKS:
call_request.add_control_hook(key, function)
self.assertTrue(call_request.control_hooks[key] is function)
示例2: consumer_content_update_itinerary
# 需要导入模块: from pulp.server.dispatch.call import CallRequest [as 别名]
# 或者: from pulp.server.dispatch.call.CallRequest import add_control_hook [as 别名]
def consumer_content_update_itinerary(consumer_id, units, options):
"""
Create an itinerary for consumer content update.
@param consumer_id: unique id of the consumer
@type consumer_id: str
@param units: units to update
@type units: list or tuple
@param options: options to pass to the update manager
@type options: dict or None
@return: list of call requests
@rtype: list
"""
manager = managers_factory.consumer_agent_manager()
args = [consumer_id]
kwargs = {'units': units, 'options': options}
weight = pulp_config.config.getint('tasks', 'consumer_content_weight')
tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
action_tag('unit_update')]
call_request = CallRequest(
manager.update_content,
args,
kwargs,
weight=weight,
tags=tags,
archive=True,
asynchronous=True,
kwarg_blacklist=['options'])
call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, cancel_agent_request)
call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
return [call_request]
示例3: test_serialize_deserialize_with_control_hook
# 需要导入模块: from pulp.server.dispatch.call import CallRequest [as 别名]
# 或者: from pulp.server.dispatch.call.CallRequest import add_control_hook [as 别名]
def test_serialize_deserialize_with_control_hook(self):
key = dispatch_constants.CALL_CANCEL_CONTROL_HOOK
call_request = CallRequest(function)
call_request.add_control_hook(key, function)
data = call_request.serialize()
self.assertTrue(isinstance(data, dict))
call_request_2 = CallRequest.deserialize(data)
self.assertTrue(isinstance(call_request_2, CallRequest))
self.assertTrue(call_request_2.control_hooks[key] == function)
示例4: TaskTests
# 需要导入模块: from pulp.server.dispatch.call import CallRequest [as 别名]
# 或者: from pulp.server.dispatch.call.CallRequest import add_control_hook [as 别名]
class TaskTests(base.PulpServerTests):
def setUp(self):
super(TaskTests, self).setUp()
self.call_request = CallRequest(Call(), call_args, call_kwargs)
self.call_report = CallReport()
self.task = Task(self.call_request, self.call_report)
def tearDown(self):
super(TaskTests, self).tearDown()
self.call_request = None
self.call_report = None
self.task = None
def test_run(self):
self.assertTrue(self.call_report.state is dispatch_constants.CALL_WAITING_STATE)
self.task._run()
self.assertTrue(self.call_request.call.call_count == 1)
self.assertTrue(self.call_request.call.call_args[0] == call_args,
'%s != %s' % (str(self.call_request.call.call_args[0]), str(call_args)))
self.assertTrue(self.call_request.call.call_args[1] == call_kwargs)
self.assertTrue(self.call_report.state is dispatch_constants.CALL_FINISHED_STATE)
def test_complete(self):
now = datetime.datetime.now(dateutils.utc_tz())
self.task._run()
self.assertTrue(self.call_report.finish_time > now)
def test_complete_callback(self):
callback = mock.Mock()
self.task.complete_callback = callback
self.task._run()
self.assertTrue(callback.call_count == 1)
self.assertTrue(callback.call_args[0][0] is self.task)
def test_cancel_control_hook(self):
callback = mock.Mock()
self.call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback)
self.call_report.state = dispatch_constants.CALL_RUNNING_STATE
try:
self.task.cancel()
except:
self.fail(traceback.format_exc())
self.assertTrue(callback.call_count == 1)
self.assertTrue(callback.call_args[0][0] is self.call_request)
self.assertTrue(callback.call_args[0][1] is self.call_report)
self.assertTrue(self.call_report.state is dispatch_constants.CALL_CANCELED_STATE,
self.call_report.state)
def test_finish_execution_hook(self):
hooks = [mock.Mock(), mock.Mock()]
for h in hooks:
self.call_request.add_life_cycle_callback(dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h)
self.task._run()
for h in hooks:
self.assertTrue(h.call_count == 1)
self.assertTrue(h.call_args[0][0] is self.call_request)
self.assertTrue(h.call_args[0][1] is self.call_report)
def test_complete_execution_hook(self):
hooks = [mock.Mock(), mock.Mock()]
for h in hooks:
self.call_request.add_life_cycle_callback(dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h)
self.task._run()
for h in hooks:
self.assertTrue(h.call_count == 1)