Guest User

Untitled

a guest
Nov 6th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. # Tested environment
  2.  
  3. ```
  4. root@5a6e72caaa0d:~# dpkg -l | grep st2
  5. ii st2 3.0dev-38 amd64 StackStorm Event-driven automation
  6. ii st2chatops 3.0dev-1 amd64 St2Chatops - StackStorm ChatOps.
  7. ii st2mistral 3.0dev-4 amd64 st2 Mistral workflow service.
  8. ii st2web 3.0dev-9 amd64 St2Web - StackStorm Web UI.
  9. ```
  10.  
  11. # Notes
  12.  
  13. - core.local doesn't accept unicode at action level while core.remote seems to run without any problem
  14.  
  15. ```
  16. root@5a6e72caaa0d:/# st2 run core.local cmd="echo あ"
  17. .
  18. id: 5be19c5be78e2f06259cfc2c
  19. status: failed
  20. parameters:
  21. cmd: "echo あ"
  22. result:
  23. error: '''ascii'' codec can''t encode character u''あ'' in position 39: ordinal not in range(128)'
  24. traceback: " File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/container/base.py", line 127, in _do_run
  25. (status, result, context) = runner.run(action_params)
  26. File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/local_runner/local_shell_command_runner.py", line 49, in run
  27. return self._run(action=action)
  28. File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/local_runner/base.py", line 175, in _run
  29. read_stderr_buffer=stderr)
  30. File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/green/shell.py", line 109, in run_command
  31. env=env, cwd=cwd, shell=shell, preexec_fn=preexec_func)
  32. File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/eventlet/green/subprocess.py", line 58, in __init__
  33. subprocess_orig.Popen.__init__(self, args, 0, *argss, **kwds)
  34. File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
  35. errread, errwrite)
  36. File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
  37. raise child_exception
  38. "
  39. ```
  40.  
  41. ```
  42. root@5a6e72caaa0d:/# st2 run core.remote cmd="echo あ" hosts=192.168.33.10 username=vagrant password=vagrant
  43. .
  44. id: 5be19c8de78e2f06259cfc2f
  45. status: succeeded
  46. parameters:
  47. cmd: "echo あ"
  48. hosts: 192.168.33.10
  49. password: '********'
  50. username: vagrant
  51. result:
  52. 192.168.33.10:
  53. failed: false
  54. return_code: 0
  55. stderr: ''
  56. stdout: "あ"
  57. succeeded: true
  58. ```
  59.  
  60. # Test 0: Success
  61.  
  62. - Unicode character in workflow yaml
  63.  
  64. ```
  65. version: 1.0
  66.  
  67. tasks:
  68. task1:
  69. action: core.remote
  70. input:
  71. hosts: 192.168.33.10
  72. username: vagrant
  73. password: vagrant
  74. cwd: /vagrant
  75. cmd: echo あ
  76. ```
  77.  
  78. ```
  79. root@5a6e72caaa0d:/# st2 run demo.orquesta-unicode
  80. .
  81. id: 5be1ab57e78e2f08ae2ed9e6
  82. action.ref: demo.orquesta-unicode
  83. parameters: None
  84. status: succeeded
  85. start_timestamp: Tue, 06 Nov 2018 14:55:19 UTC
  86. end_timestamp: Tue, 06 Nov 2018 14:55:21 UTC
  87. result:
  88. output: null
  89. +--------------------------+------------------------+-------+-------------+-------------------------------+
  90. | id | status | task | action | start_timestamp |
  91. +--------------------------+------------------------+-------+-------------+-------------------------------+
  92. | 5be1ab58e78e2f06c4cba105 | succeeded (1s elapsed) | task1 | core.remote | Tue, 06 Nov 2018 14:55:20 UTC |
  93. +--------------------------+------------------------+-------+-------------+-------------------------------+
  94. root@5a6e72caaa0d:/# st2 execution get 5be1ab58e78e2f06c4cba105
  95. id: 5be1ab58e78e2f06c4cba105
  96. status: succeeded (1s elapsed)
  97. parameters:
  98. cmd: "echo あ"
  99. cwd: /vagrant
  100. hosts: 192.168.33.10
  101. password: '********'
  102. username: vagrant
  103. result:
  104. 192.168.33.10:
  105. failed: false
  106. return_code: 0
  107. stderr: ''
  108. stdout: "あ"
  109. succeeded: true
  110. ```
  111.  
  112. # Test 1: Success
  113.  
  114. - Unicode character in variable
  115.  
  116. ```
  117. version: 1.0
  118.  
  119. vars:
  120. - diff: あ
  121.  
  122. tasks:
  123. task1:
  124. action: core.remote
  125. input:
  126. hosts: 192.168.33.10
  127. username: vagrant
  128. password: vagrant
  129. cwd: /vagrant
  130. cmd: echo {{ ctx('diff') }}
  131. ```
  132.  
  133. ```
  134. root@5a6e72caaa0d:/# st2 run demo.orquesta-unicode
  135. .
  136. id: 5be1abb6e78e2f08ae2ed9e9
  137. action.ref: demo.orquesta-unicode
  138. parameters: None
  139. status: succeeded
  140. start_timestamp: Tue, 06 Nov 2018 14:56:54 UTC
  141. end_timestamp: Tue, 06 Nov 2018 14:56:56 UTC
  142. result:
  143. output: null
  144. +--------------------------+------------------------+-------+-------------+-------------------------------+
  145. | id | status | task | action | start_timestamp |
  146. +--------------------------+------------------------+-------+-------------+-------------------------------+
  147. | 5be1abb7e78e2f06c4cba108 | succeeded (0s elapsed) | task1 | core.remote | Tue, 06 Nov 2018 14:56:55 UTC |
  148. +--------------------------+------------------------+-------+-------------+-------------------------------+
  149. root@5a6e72caaa0d:/# st2 execution get 5be1abb7e78e2f06c4cba108
  150. id: 5be1abb7e78e2f06c4cba108
  151. status: succeeded (0s elapsed)
  152. parameters:
  153. cmd: "echo あ"
  154. cwd: /vagrant
  155. hosts: 192.168.33.10
  156. password: '********'
  157. username: vagrant
  158. result:
  159. 192.168.33.10:
  160. failed: false
  161. return_code: 0
  162. stderr: ''
  163. stdout: "あ"
  164. succeeded: true
  165. ```
  166.  
  167. # Test 2: Success
  168.  
  169. - Passing unicode character as an input to workflow
  170.  
  171. ```
  172. version: 1.0
  173.  
  174. input:
  175. - diff
  176.  
  177. tasks:
  178. task1:
  179. action: core.remote
  180. input:
  181. hosts: 192.168.33.10
  182. username: vagrant
  183. password: vagrant
  184. cwd: /vagrant
  185. cmd: echo {{ ctx().diff }}
  186. ```
  187.  
  188. ```
  189. root@5a6e72caaa0d:/# st2 run demo.orquesta-unicode diff=塩
  190. .
  191. id: 5be1ac0fe78e2f08ae2ed9ef
  192. action.ref: demo.orquesta-unicode
  193. parameters:
  194. diff: "塩"
  195. status: succeeded
  196. start_timestamp: Tue, 06 Nov 2018 14:58:23 UTC
  197. end_timestamp: Tue, 06 Nov 2018 14:58:24 UTC
  198. result:
  199. output: null
  200. +--------------------------+------------------------+-------+-------------+-------------------------------+
  201. | id | status | task | action | start_timestamp |
  202. +--------------------------+------------------------+-------+-------------+-------------------------------+
  203. | 5be1ac0fe78e2f06c4cba10b | succeeded (1s elapsed) | task1 | core.remote | Tue, 06 Nov 2018 14:58:23 UTC |
  204. +--------------------------+------------------------+-------+-------------+-------------------------------+
  205. root@5a6e72caaa0d:/# st2 execution get 5be1ac0fe78e2f06c4cba10b
  206. id: 5be1ac0fe78e2f06c4cba10b
  207. status: succeeded (1s elapsed)
  208. parameters:
  209. cmd: "echo 塩"
  210. cwd: /vagrant
  211. hosts: 192.168.33.10
  212. password: '********'
  213. username: vagrant
  214. result:
  215. 192.168.33.10:
  216. failed: false
  217. return_code: 0
  218. stderr: ''
  219. stdout: "塩"
  220. succeeded: true
  221. ```
  222.  
  223. # Test 3: Success
  224.  
  225. - Return output containing unicode character
  226.  
  227. ```
  228. version: 1.0
  229.  
  230. output:
  231. - diff: "{{ ctx().diff }}"
  232.  
  233. tasks:
  234. task1:
  235. action: core.remote
  236. input:
  237. hosts: 192.168.33.10
  238. username: vagrant
  239. password: vagrant
  240. cwd: /vagrant
  241. cmd: echo あ
  242. next:
  243. - when: "{{ succeeded() }}"
  244. publish: diff={{ result() | jsonpath_query('*.stdout') | first }}
  245. ```
  246.  
  247. ```
  248. root@5a6e72caaa0d:/# st2 run demo.orquesta-unicode
  249. ..
  250. id: 5be1ac51e78e2f08ae2ed9f5
  251. action.ref: demo.orquesta-unicode
  252. parameters: None
  253. status: succeeded
  254. start_timestamp: Tue, 06 Nov 2018 14:59:29 UTC
  255. end_timestamp: Tue, 06 Nov 2018 14:59:32 UTC
  256. result:
  257. output:
  258. diff: "あ"
  259. +--------------------------+------------------------+-------+-------------+-------------------------------+
  260. | id | status | task | action | start_timestamp |
  261. +--------------------------+------------------------+-------+-------------+-------------------------------+
  262. | 5be1ac52e78e2f06c4cba10e | succeeded (1s elapsed) | task1 | core.remote | Tue, 06 Nov 2018 14:59:30 UTC |
  263. +--------------------------+------------------------+-------+-------------+-------------------------------+
  264. ```
  265.  
  266. # Test4: Success
  267.  
  268. - Chain output that contains unicode character as an input to next action
  269.  
  270. ```
  271. version: 1.0
  272.  
  273. tasks:
  274. task1:
  275. action: core.remote
  276. input:
  277. hosts: 192.168.33.10
  278. username: vagrant
  279. password: vagrant
  280. cwd: /vagrant
  281. cmd: echo 塩
  282. next:
  283. - when: "{{ succeeded() }}"
  284. publish: diff={{ result() | jsonpath_query('*.stdout') | first }}
  285. do: task2
  286. task2:
  287. action: core.remote
  288. input:
  289. hosts: 192.168.33.10
  290. username: vagrant
  291. password: vagrant
  292. cwd: /vagrant
  293. cmd: echo {{ ctx().diff }}
  294. ```
  295.  
  296. ```
  297. root@5a6e72caaa0d:/# st2 run demo.orquesta-unicode
  298. ..
  299. id: 5be1ac87e78e2f08ae2ed9f8
  300. action.ref: demo.orquesta-unicode
  301. parameters: None
  302. status: succeeded
  303. start_timestamp: Tue, 06 Nov 2018 15:00:23 UTC
  304. end_timestamp: Tue, 06 Nov 2018 15:00:26 UTC
  305. result:
  306. output: null
  307. +--------------------------+------------------------+-------+-------------+-------------------------------+
  308. | id | status | task | action | start_timestamp |
  309. +--------------------------+------------------------+-------+-------------+-------------------------------+
  310. | 5be1ac88e78e2f06c4cba111 | succeeded (1s elapsed) | task1 | core.remote | Tue, 06 Nov 2018 15:00:24 UTC |
  311. | 5be1ac89e78e2f06c4cba114 | succeeded (1s elapsed) | task2 | core.remote | Tue, 06 Nov 2018 15:00:25 UTC |
  312. +--------------------------+------------------------+-------+-------------+-------------------------------+
  313. root@5a6e72caaa0d:/# st2 execution get 5be1ac89e78e2f06c4cba114
  314. id: 5be1ac89e78e2f06c4cba114
  315. status: succeeded (1s elapsed)
  316. parameters:
  317. cmd: "echo 塩"
  318. cwd: /vagrant
  319. hosts: 192.168.33.10
  320. password: '********'
  321. username: vagrant
  322. result:
  323. 192.168.33.10:
  324. failed: false
  325. return_code: 0
  326. stderr: ''
  327. stdout: "塩"
  328. succeeded: true
  329. ```
  330.  
  331. # Test 5: OK
  332.  
  333. - More practical example
  334.  
  335. ```
  336. version: 1.0
  337.  
  338. output:
  339. - slack_result: "{{ ctx('slack_result') }}"
  340.  
  341. tasks:
  342. task1:
  343. action: core.remote
  344. input:
  345. hosts: 192.168.33.10
  346. username: vagrant
  347. password: vagrant
  348. cwd: /vagrant
  349. cmd: diff -u text1 text2 || true
  350. next:
  351. - when: "{{ succeeded() }}"
  352. publish: diff={{ result() | jsonpath_query('*.stdout') | first }}
  353. do: task2
  354. task2:
  355. action: slack.files.upload
  356. input:
  357. channels: sandbox
  358. content: |
  359. 塩 塩 塩
  360. {{ ctx('diff') }}
  361. next:
  362. - when: "{{ succeeded() }}"
  363. publish:
  364. - slack_result:
  365. channel: "{{ result().result.file.channels | first }}"
  366. timestamp: "{{ result().result.file.timestamp }}"
  367. ```
Add Comment
Please, Sign In to add comment