Esempio n. 1
0
 def send_task(self,
               task_name,
               queue,
               deployment_id=None,
               args=None,
               kwargs=None,
               timeout=10,
               execution_env=None):
     cloudify_context = test_utils.op_context(task_name,
                                              task_target=queue,
                                              plugin_name=PLUGIN_NAME,
                                              execution_env=execution_env,
                                              deployment_id=deployment_id)
     kwargs = kwargs or {}
     kwargs['__cloudify_context'] = cloudify_context
     handler = amqp_client.BlockingRequestResponseHandler(exchange=queue)
     client = amqp_client.get_client()
     client.add_handler(handler)
     with client:
         task = {'cloudify_task': {'kwargs': kwargs}}
         result = handler.publish(task, routing_key='operation',
                                  timeout=timeout)
     error = result.get('error')
     if error:
         raise deserialize_known_exception(error)
     else:
         return result.get('result')
Esempio n. 2
0
 def send_task(self,
               task_name,
               queue,
               deployment_id=None,
               args=None,
               kwargs=None,
               timeout=10,
               execution_env=None):
     cloudify_context = test_utils.op_context(task_name,
                                              task_target=queue,
                                              plugin_name=PLUGIN_NAME,
                                              execution_env=execution_env,
                                              deployment_id=deployment_id)
     kwargs = kwargs or {}
     kwargs['__cloudify_context'] = cloudify_context
     handler = amqp_client.BlockingRequestResponseHandler(queue)
     client = amqp_client.get_client()
     client.add_handler(handler)
     with client:
         task = {'cloudify_task': {'kwargs': kwargs}}
         result = handler.publish(task,
                                  routing_key='operation',
                                  timeout=timeout)
     error = result.get('error')
     if error:
         raise deserialize_known_exception(error)
     else:
         return result.get('result')
Esempio n. 3
0
def _assert_task_not_runnable(task_name,
                              deployment_id=None,
                              package_name=plugins.PACKAGE_NAME,
                              package_version=None):
    pytest.raises(
        cloudify_exceptions.NonRecoverableError, dispatch.dispatch,
        test_utils.op_context(task_name,
                              plugin_name=plugins.PLUGIN_NAME,
                              deployment_id=deployment_id,
                              package_name=package_name,
                              package_version=package_version))
Esempio n. 4
0
def _assert_task_runnable(task_name,
                          expected_return=None,
                          package_name=plugins.PACKAGE_NAME,
                          package_version=None,
                          deployment_id=None):
    assert (dispatch.dispatch(
        test_utils.op_context(task_name,
                              plugin_name=plugins.PLUGIN_NAME,
                              package_name=package_name,
                              package_version=package_version,
                              deployment_id=deployment_id))) == expected_return
Esempio n. 5
0
 def _assert_task_not_runnable(self, task_name,
                               deployment_id=None,
                               package_name=None,
                               package_version=None):
     self.assertRaises(
         cloudify_exceptions.NonRecoverableError,
         dispatch.dispatch,
         test_utils.op_context(task_name,
                               plugin_name=PLUGIN_NAME,
                               deployment_id=deployment_id,
                               package_name=package_name,
                               package_version=package_version))
Esempio n. 6
0
 def _assert_task_runnable(self, task_name,
                           expected_return=None,
                           package_name=None,
                           package_version=None,
                           deployment_id=None):
     self.assertEqual(
         dispatch.dispatch(test_utils.op_context(
             task_name,
             plugin_name=PLUGIN_NAME,
             package_name=package_name,
             package_version=package_version,
             deployment_id=deployment_id)),
         expected_return)
Esempio n. 7
0
 def _assert_task_runnable(self, task_name,
                           expected_return=None,
                           package_name=None,
                           package_version=None,
                           deployment_id=None):
     self.assertEqual(
         dispatch.dispatch(test_utils.op_context(
             task_name,
             plugin_name=PLUGIN_NAME,
             package_name=package_name,
             package_version=package_version,
             deployment_id=deployment_id)),
         expected_return)
Esempio n. 8
0
 def send_task(self,
               task_name,
               queue,
               deployment_id=None,
               args=None,
               kwargs=None,
               timeout=10,
               execution_env=None):
     cloudify_context = test_utils.op_context(task_name,
                                              task_target=queue,
                                              plugin_name=PLUGIN_NAME,
                                              execution_env=execution_env,
                                              deployment_id=deployment_id)
     kwargs = kwargs or {}
     kwargs['__cloudify_context'] = cloudify_context
     return self.celery.send_task(name='cloudify.dispatch.dispatch',
                                  queue=queue,
                                  args=args,
                                  kwargs=kwargs).get(timeout=timeout)
Esempio n. 9
0
 def send_task(self,
               task_name,
               queue,
               deployment_id=None,
               args=None,
               kwargs=None,
               timeout=10,
               execution_env=None):
     cloudify_context = test_utils.op_context(task_name,
                                              task_target=queue,
                                              plugin_name=PLUGIN_NAME,
                                              execution_env=execution_env,
                                              deployment_id=deployment_id)
     kwargs = kwargs or {}
     kwargs['__cloudify_context'] = cloudify_context
     return self.celery.send_task(
         name='cloudify.dispatch.dispatch',
         queue=queue,
         args=args,
         kwargs=kwargs).get(timeout=timeout)