int32bit / mistral-actions

A simple tool to discover and manage custom actions for OpenStack Mistral
https://github.com/int32bit/mistral-actions
MIT License
15 stars 2 forks source link

TypeError thrown while creating client by "_create_client() " method #2

Open dineshbhor opened 7 years ago

dineshbhor commented 7 years ago

After fixing the issue [1] if you try to execute actions registered by mistral-actions the "_create_client() " method from mistral_actions.openstack.py gives TypeError.

Steps: 1] Fix the issue [1] 2] Try to execute any action registered by mistral-actions ex: mistral run-action int32bit.nova.servers.assert_status input.json

input.json: { "server_id": "1229b18b-120b-4382-87c3-c56f55f5b22e" }

Observed traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/server.py", line 160, in _process_incoming
    res = self.dispatcher.dispatch(message)
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 213, in dispatch
    return self._do_dispatch(endpoint, method, ctxt, args)
  File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 183, in _do_dispatch
    result = func(ctxt, **new_args)
 File "/opt/stack/mistral/mistral/engine/engine_server.py", line 128, in start_action
    **params
  File "/opt/stack/mistral/mistral/engine/action_queue.py", line 74, in decorate
    res = func(*args, **kw)
  File "/opt/stack/mistral/mistral/engine/default_engine.py", line 63, in start_action
    is_action_sync = action.is_sync(action_input)
  File "/opt/stack/mistral/mistral/engine/actions.py", line 276, in is_sync
    a = a_m.get_action_class(self.action_def.name)(**input_dict)
  File "/usr/local/lib/python2.7/dist-packages/mistral_actions/nova/servers.py", line 13, in __init__
    super(AssertStatus, self).__init__('nova')
  File "/usr/local/lib/python2.7/dist-packages/mistral_actions/openstack.py", line 8, in __init__
    self.client = self._get_client()
  File "/usr/local/lib/python2.7/dist-packages/mistral_actions/openstack.py", line 14, in _get_client
    return getattr(action_obj, '_create_client')()
TypeError: _create_client() takes exactly 2 arguments (1 given)

This issue can be fixed by providing mistral context to _create_client() method like below:

diff --git a/mistral_actions/openstack.py b/mistral_actions/openstack.py
index d6cd2dd..1432c52 100644
--- a/mistral_actions/openstack.py
+++ b/mistral_actions/openstack.py
@@ -1,5 +1,6 @@
 from mistral.actions.base import Action as action_base
 from mistral.actions.openstack import actions as os_actions
+from mistral import context

 class OpenstackBase(action_base):
@@ -11,6 +12,6 @@ class OpenstackBase(action_base):
         action_obj = getattr(os_actions, "%sAction" % self.service)()
         # New version use _create_client()
         if hasattr(action_obj, '_create_client'):
-            return getattr(action_obj, '_create_client')()
+            return getattr(action_obj, '_create_client')(context.ctx())
         # Fallback to _get_client()
         return action_obj._get_client()

[1] https://github.com/int32bit/mistral-actions/issues/1

int32bit commented 7 years ago

Thanks @dineshbhor, look forward to your PR.

dineshbhor commented 7 years ago

Hi @int32bit Please see my PR.