From 4f52343cd9f4868f716566cf0438be697d56ab55 Mon Sep 17 00:00:00 2001 From: Alexandre Bortoluzzi Date: Thu, 22 Sep 2022 16:02:57 +0200 Subject: [PATCH 1/3] fix: host modal stdout when stdout is an array --- .../screens/Job/JobOutput/HostEventModal.js | 2 + .../Job/JobOutput/HostEventModal.test.js | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/awx/ui/src/screens/Job/JobOutput/HostEventModal.js b/awx/ui/src/screens/Job/JobOutput/HostEventModal.js index 19faa9d5e0..5ff72d6e22 100644 --- a/awx/ui/src/screens/Job/JobOutput/HostEventModal.js +++ b/awx/ui/src/screens/Job/JobOutput/HostEventModal.js @@ -40,6 +40,8 @@ const processCodeEditorValue = (value) => { codeEditorValue = ''; } else if (typeof value === 'string') { codeEditorValue = encode(value); + } else if (Array.isArray(value)) { + codeEditorValue = encode(value.join(' ')); } else { codeEditorValue = value; } diff --git a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js index 5872011874..dcb0b91c9f 100644 --- a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js +++ b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js @@ -52,6 +52,49 @@ const hostEvent = { }, }; +const hostEventWithArray = { + changed: true, + event: 'runner_on_ok', + event_data: { + host: 'foo', + play: 'all', + playbook: 'run_command.yml', + res: { + ansible_loop_var: 'item', + changed: true, + item: '1', + msg: 'This is a debug message: 1', + stdout: [ + ' total used free shared buff/cache available\nMem: 7973 3005 960 30 4007 4582\nSwap: 1023 0 1023', + ], + stderr: 'problems', + cmd: ['free', '-m'], + stderr_lines: [], + stdout_lines: [ + ' total used free shared buff/cache available', + 'Mem: 7973 3005 960 30 4007 4582', + 'Swap: 1023 0 1023', + ], + }, + task: 'command', + task_action: 'command', + }, + event_display: 'Host OK', + event_level: 3, + failed: false, + host: 1, + host_name: 'foo', + id: 123, + job: 4, + play: 'all', + playbook: 'run_command.yml', + stdout: `stdout: "changed: [localhost] => {"changed": true, "cmd": ["free", "-m"], "delta": "0:00:01.479609", "end": "2019-09-10 14:21:45.469533", "rc": 0, "start": "2019-09-10 14:21:43.989924", "stderr": "", "stderr_lines": [], "stdout": " total used free shared buff/cache available\nMem: 7973 3005 960 30 4007 4582\nSwap: 1023 0 1023", "stdout_lines": [" total used free shared buff/cache available", "Mem: 7973 3005 960 30 4007 4582", "Swap: 1023 0 1023"]}" + `, + task: 'command', + type: 'job_event', + url: '/api/v2/job_events/123/', +}; + /* eslint-disable no-useless-escape */ const jsonValue = `{ \"ansible_loop_var\": \"item\", @@ -281,4 +324,25 @@ describe('HostEventModal', () => { expect(codeEditor.prop('readOnly')).toBe(true); expect(codeEditor.prop('value')).toEqual('baz\nbar'); }); + + test('should display Standard Out array stdout content', () => { + const wrapper = shallow( + {}} + isOpen + /> + ); + + const handleTabClick = wrapper.find('Tabs').prop('onSelect'); + handleTabClick(null, 2); + wrapper.update(); + + const codeEditor = wrapper.find('Tab[eventKey=2] CodeEditor'); + expect(codeEditor.prop('mode')).toBe('javascript'); + expect(codeEditor.prop('readOnly')).toBe(true); + expect(codeEditor.prop('value')).toEqual( + hostEventWithArray.event_data.res.stdout.join(' ') + ); + }); }); From 8e2003a36b72a4db85dc9dca686a48147c9549d0 Mon Sep 17 00:00:00 2001 From: Alexandre Bortoluzzi Date: Thu, 22 Sep 2022 16:23:23 +0200 Subject: [PATCH 2/3] chore:add comment in test --- awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js index dcb0b91c9f..8a98a1b7e9 100644 --- a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js +++ b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js @@ -52,6 +52,10 @@ const hostEvent = { }, }; +/* +Some libraries return a list of string in stdout +Example: https://github.com/ansible-collections/cisco.ios/blob/main/plugins/modules/ios_command.py#L124-L128 +*/ const hostEventWithArray = { changed: true, event: 'runner_on_ok', From 5551874352ae43c071b9e9ca1a50271a4b8ec76d Mon Sep 17 00:00:00 2001 From: Alexandre Bortoluzzi Date: Tue, 27 Sep 2022 10:23:14 +0200 Subject: [PATCH 3/3] fix: HostEventModel test --- awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js index 8a98a1b7e9..96866c4b03 100644 --- a/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js +++ b/awx/ui/src/screens/Job/JobOutput/HostEventModal.test.js @@ -97,6 +97,13 @@ const hostEventWithArray = { task: 'command', type: 'job_event', url: '/api/v2/job_events/123/', + summary_fields: { + host: { + id: 1, + name: 'foo', + description: 'Bar', + }, + }, }; /* eslint-disable no-useless-escape */