Workflow:
---
version: "2.0"
test_ssh:
tasks:
t1:
action: std.ssh
input:
cmd: 'cd ~ && ls'
host: localhost
username: uzer
password: password
=====
Workflow execution is successful in Python 2.7.12 (virtualenv py27 created by mistral/tox.ini).
However, it fails in Python 3.5.2 (virtualenv py35 created by mistral/tox.ini) with following error.
Error from logs:
2018-07-13 13:08:19.357 9224 INFO mistral.engine.engine_server [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Received RPC request 'start_workflow'[workflow_identifier=test_ssh, workflow_input={}, description=, params={}]
2018-07-13 13:08:19.387 9224 INFO workflow_trace [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Starting workflow [name=test_ssh, input={}]
2018-07-13 13:08:19.403 9224 INFO workflow_trace [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Workflow 'test_ssh' [IDLE -> RUNNING, msg=None] (execution_id=0034f88e-cd3c-45fd-b356-154b0794b950)
2018-07-13 13:08:19.591 9224 INFO mistral.executors.executor_server [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Received RPC request 'run_action'[action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls_str=mistral.actions.std_actions.SSHAction, action_cls_attrs={}, params={'cmd': 'ls -l', 'password': 'password', 'username': 'uzer', 'host': 'localhost'}, timeout=None]
2018-07-13 13:08:19.596 9224 INFO mistral.engine.engine_server [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Received RPC request 'report_running_actions'[action_ex_ids=['d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef']]
2018-07-13 13:08:19.648 9224 INFO paramiko.transport [-] Connected (version 2.0, client OpenSSH_7.2p2)
2018-07-13 13:08:19.751 9224 INFO paramiko.transport [-] Authentication (publickey) failed.
2018-07-13 13:08:19.756 9224 INFO paramiko.transport [-] Authentication (publickey) failed.
2018-07-13 13:08:19.764 9224 INFO paramiko.transport [-] Authentication (password) successful!
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral.actions.action_factory.SSHAction'>', attributes='{}', params='{'cmd': 'ls -l', 'password': 'password', 'username': 'uzer', 'host': 'localhost'}']
Failed to execute ssh cmd 'ls -l' on ['localhost']
Exception: Can't convert 'bytes' object to str implicitly: mistral.exceptions.ActionException: Failed to execute ssh cmd 'ls -l' on ['localhost']
Exception: Can't convert 'bytes' object to str implicitly
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor Traceback (most recent call last):
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/actions/std_actions.py", line 394, in run
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor status_code, result = self._execute_cmd_method(**self.params)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/utils/ssh_utils.py", line 161, in execute_command
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor return _execute_command(ssh_client, cmd, get_stderr, raise_when_error)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/utils/ssh_utils.py", line 88, in _execute_command
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor stdout = _read_paramimko_stream(chan.recv)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/utils/ssh_utils.py", line 33, in _read_paramimko_stream
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor result += buf
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor TypeError: Can't convert 'bytes' object to str implicitly
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor During handling of the above exception, another exception occurred:
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor Traceback (most recent call last):
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/executors/default_executor.py", line 114, in run_action
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor result = action.run(action_ctx)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/actions/std_actions.py", line 406, in run
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor return raise_exc(parent_exc=e)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor File "/home/uzer/projects/mistral/mistral/actions/std_actions.py", line 383, in raise_exc
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor raise exc.ActionException(message)
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor mistral.exceptions.ActionException: Failed to execute ssh cmd 'ls -l' on ['localhost']
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor Exception: Can't convert 'bytes' object to str implicitly
2018-07-13 13:08:19.993 9224 ERROR mistral.executors.default_executor
2018-07-13 13:08:20.060 9224 INFO mistral.engine.engine_server [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Received RPC request 'on_action_complete'[action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, result=Result [data=None, error=Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral..., cancel=False]]
2018-07-13 13:08:20.075 9224 INFO workflow_trace [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Action 'std.ssh' (d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef)(task=t1) [RUNNING -> ERROR, error = Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral...]
2018-07-13 13:08:20.095 9224 INFO workflow_trace [req-15058054-1f2d-4805-a28f-3fb13d75bee1 - - - - -] Task 't1' (954dc494-5b69-4ba9-91b3-79f47c4d29cf) [RUNNING -> ERROR, msg=Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral.actions.action_factory.SSHAction'>', attributes='{}', params='{'cmd': 'ls -l', 'password': 'password', 'username': 'uzer', 'host': 'localhost'}']
Failed to execute ssh cmd 'ls -l' on ['localhost']
Exception: Can't convert 'bytes' object to str implicitly] (execution_id=0034f88e-cd3c-45fd-b356-154b0794b950)
2018-07-13 13:08:20.345 9224 INFO workflow_trace [req-46d64360-462f-4da7-a60c-6d2279ed1551 - - - - -] Workflow 'test_ssh' [RUNNING -> ERROR, msg=Failure caused by error in tasks: t1
t1 [task_ex_id=954dc494-5b69-4ba9-91b3-79f47c4d29cf] -> Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral.actions.action_factory.SSHAction'>', attributes='{}', params='{'cmd': 'ls -l', 'password': 'password', 'username': 'uzer', 'host': 'localhost'}']
Failed to execute ssh cmd 'ls -l' on ['localhost']
Exception: Can't convert 'bytes' object to str implicitly
[action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, idx=0]: Failed to run action [action_ex_id=d453ab4f-88ec-4d45-9b9b-1a7c4ae9d8ef, action_cls='<class 'mistral.actions.action_factory.SSHAction'>', attributes='{}', params='{'cmd': 'ls -l', 'password': 'password', 'username': 'uzer', 'host': 'localhost'}']
Failed to execute ssh cmd 'ls -l' on ['localhost']
Exception: Can't convert 'bytes' object to str implicitly
] (execution_id=0034f88e-cd3c-45fd-b356-154b0794b950)
=====
PS, Mistral documentation doesn't have an example of this action. It should be added, too.
Reviewed: https:/ /review. openstack. org/599347 /git.openstack. org/cgit/ openstack/ mistral/ commit/ ?id=f85e57da89e bdac9e89f96c49c 1ddf5a3a6734c2
Committed: https:/
Submitter: Zuul
Branch: master
commit f85e57da89ebdac 9e89f96c49c1ddf 5a3a6734c2
Author: hardikj <email address hidden>
Date: Mon Sep 3 16:03:51 2018 +0530
Fix SSHAction under python3
This patch fixes the bug in string handling in ssh_utils which
prevented SSHAction execution in Python 3 setup.
In Python 3, all strings are unicode by default and byte stream
no longer implicitly convert to str.
Py2: paramiko Channel.recv returns type `str`
Py3: paramiko Channel.recv returns type `byte`
Change-Id: I24971858039f28 7df24d39c19eccc 44916ecf580
Closes-Bug: #1781548