Skip to content

Commit

Permalink
[v1.10.0] [Bugfix] [zos_job_submit] Fix non-printable chars handling …
Browse files Browse the repository at this point in the history
…and testing in jobs (#1300)

* Update non-printable chars test

* Add support for handling JSON decode errors

Add support for when ZOAU v1.3.0 and later can't read and create JSON output from a job's output.
  • Loading branch information
rexemin authored Mar 13, 2024
1 parent ce2551a commit b4156f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
6 changes: 5 additions & 1 deletion plugins/module_utils/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import traceback
from time import sleep
from timeit import default_timer as timer
# Only importing this module so we can catch a JSONDecodeError that sometimes happens
# when a job's output has non-printable chars that conflict with JSON's control
# chars.
from json import decoder
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import (
BetterArgParser,
)
Expand Down Expand Up @@ -366,7 +370,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
single_dd["step_name"],
single_dd["dd_name"]
)
except UnicodeDecodeError:
except (UnicodeDecodeError, decoder.JSONDecodeError):
tmpcont = (
"Non-printable UTF-8 characters were present in this output. "
"Please access it manually."
Expand Down
55 changes: 34 additions & 21 deletions tests/functional/modules/test_zos_job_submit_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,36 +262,49 @@
C_SRC_INVALID_UTF8 = """#include <stdio.h>
int main()
{
unsigned char a=0x64;
unsigned char b=0x2A;
unsigned char c=0xB8;
unsigned char d=0xFF;
unsigned char e=0x81;
unsigned char f=0x82;
unsigned char g=0x83;
unsigned char h=0x00;
printf("Value of a: Hex: %X, character: %c",a,a);
printf("Value of b: Hex: %X, character: %c",b,b);
printf("Value of c: Hex: %X, character: %c",c,c);
printf("Value of d: Hex: %X, character: %c",d,d);
printf("Value of a: Hex: %X, character: %c",e,e);
printf("Value of b: Hex: %X, character: %c",f,f);
printf("Value of c: Hex: %X, character: %c",g,g);
printf("Value of d: Hex: %X, character: %c",h,h);
return 0;
unsigned char a=0x64;
unsigned char b=0x2A;
unsigned char c=0xB8;
unsigned char d=0xFF;
unsigned char e=0x81;
unsigned char f=0x82;
unsigned char g=0x83;
unsigned char h=0x00;
/* The following are non-printables from DBB. */
unsigned char nl=0x15;
unsigned char cr=0x0D;
unsigned char lf=0x25;
unsigned char shiftOut=0x0E;
unsigned char shiftIn=0x0F;
printf("Value of a: Hex: %X, character: %c",a,a);
printf("Value of b: Hex: %X, character: %c",b,b);
printf("Value of c: Hex: %X, character: %c",c,c);
printf("Value of d: Hex: %X, character: %c",d,d);
printf("Value of e: Hex: %X, character: %c",e,e);
printf("Value of f: Hex: %X, character: %c",f,f);
printf("Value of g: Hex: %X, character: %c",g,g);
printf("Value of h: Hex: %X, character: %c",h,h);
printf("Value of NL: Hex: %X, character: %c",nl,nl);
printf("Value of CR: Hex: %X, character: %c",cr,cr);
printf("Value of LF: Hex: %X, character: %c",lf,lf);
printf("Value of Shift-Out: Hex: %X, character: %c",shiftOut,shiftOut);
printf("Value of Shift-In: Hex: %X, character: %c",shiftIn,shiftIn);
return 0;
}
"""

JCL_INVALID_UTF8_CHARS_EXC = """//*
//******************************************************************************
//* Job that runs a C program that returns characters outside of the UTF-8 range
//* expected by Python. This job tests a bugfix present in ZOAU v1.3.0 onwards
//* that deals properly with these chars.
//* expected by Python. This job tests a bugfix present in ZOAU v1.3.0 and
//* later that deals properly with these chars.
//* The JCL needs to be formatted to give it the directory where the C program
//* is located.
//******************************************************************************
//NOEBCDIC JOB (T043JM,JM00,1,0,0,0),'NOEBCDIC - JRM',
// MSGCLASS=X,MSGLEVEL=1,NOTIFY=&SYSUID
// MSGCLASS=H,MSGLEVEL=1,NOTIFY=&SYSUID
//NOPRINT EXEC PGM=BPXBATCH
//STDPARM DD *
SH (
Expand Down Expand Up @@ -774,7 +787,7 @@ def test_zoau_bugfix_invalid_utf8_chars(ansible_zos_module):
hosts.all.shell(
cmd="echo {0} > {1}/noprint.c".format(quote(C_SRC_INVALID_UTF8), TEMP_PATH)
)
hosts.all.shell(cmd="xlc -o {0}/noprint {0}/noprint.c")
hosts.all.shell(cmd="xlc -o {0}/noprint {0}/noprint.c".format(TEMP_PATH))

# Create local JCL and submit it.
tmp_file = tempfile.NamedTemporaryFile(delete=True)
Expand Down

0 comments on commit b4156f8

Please sign in to comment.