Skip to content

Commit

Permalink
Fixed PR Comments, Moved Failed Objects below Table
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayasimha Raghavan authored and Jayasimha Raghavan committed Sep 15, 2023
1 parent 3f53f7c commit 3d8e7d0
Showing 1 changed file with 74 additions and 53 deletions.
127 changes: 74 additions & 53 deletions unskript-ctl/unskript-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def load_or_create_global_configuration():
else:
_f_path = Path(GLOBAL_CONFIG_PATH)
_f_path.touch()
with open(GLOBAL_CONFIG_PATH, 'w') as f:
f.write('globals:')


def insert_first_and_last_cell(nb: nbformat.NotebookNode) -> nbformat.NotebookNode:
Expand Down Expand Up @@ -125,11 +127,12 @@ def insert_first_and_last_cell(nb: nbformat.NotebookNode) -> nbformat.NotebookNo
nbParamsObj = nbparams.NBParams(paramsJson)
{runbook_variables}
'''
for k,v in UNSKRIPT_GLOBALS.get('globals').items():
if isinstance(v,str) is True:
first_cell_content += f'{k} = \"{v}\"' + '\n'
else:
first_cell_content += f'{k} = {v}' + '\n'
if UNSKRIPT_GLOBALS.get('globals') and len(UNSKRIPT_GLOBALS.get('globals')):
for k,v in UNSKRIPT_GLOBALS.get('globals').items():
if isinstance(v,str) is True:
first_cell_content += f'{k} = \"{v}\"' + '\n'
else:
first_cell_content += f'{k} = {v}' + '\n'

first_cell_content += f'''
w = Workflow(env, secret_store_cfg, None, global_vars=globals(), check_uuids={ids})'''
Expand Down Expand Up @@ -162,7 +165,6 @@ def insert_first_and_last_cell(nb: nbformat.NotebookNode) -> nbformat.NotebookNo
if cells[0].get('cell_type') == 'code':
tags = None
if cells[0].get('metadata').get('tags') is not None:

if len(cells[0].get('metadata').get('tags')) != 0:
tags = cells[0].get('metadata').get('tags')[0]

Expand Down Expand Up @@ -237,7 +239,6 @@ def run_ipynb(filename: str, status_list_of_dict: list = None):
client = NotebookClient(nb=nb, kernel_name="python3")

try:

execution = client.execute()
except CellExecutionError as e:
raise e
Expand Down Expand Up @@ -312,6 +313,9 @@ def run_ipynb(filename: str, status_list_of_dict: list = None):
'FAIL'
])
elif ids and CheckOutputStatus(payload.get('status')) == CheckOutputStatus.RUN_EXCEPTION:
if payload.get('error') != None:

Check failure on line 316 in unskript-ctl/unskript-client.py

View workflow job for this annotation

GitHub Actions / Pylint

unskript-ctl/unskript-client.py#L316

Comparison 'payload.get('error') != None' should be 'payload.get('error') is not None' (singleton-comparison, C0121)
failed_objects = payload.get('error')
failed_result[get_action_name_from_id(ids[idx], nb.dict())] = failed_objects
result_table.append([
get_action_name_from_id(ids[idx], nb.dict()),
TBL_CELL_CONTENT_ERROR,
Expand All @@ -324,8 +328,6 @@ def run_ipynb(filename: str, status_list_of_dict: list = None):
get_connector_name_from_id(ids[idx], nb.dict()),
'ERROR'
])
else:
print("ELSE STATEMENT")
except Exception:
pass
if ids:
Expand All @@ -336,19 +338,11 @@ def run_ipynb(filename: str, status_list_of_dict: list = None):
CheckOutputStatus(payload.get('status')),
failed_result)
idx += 1
else:
print("")
print(tabulate(result_table, headers='firstrow', tablefmt='fancy_grid'))
print("")
print(tabulate(result_table, headers='firstrow', tablefmt='fancy_grid'))

if failed_result_available is True:
print("")
print("FAILED RESULTS")
for k, v in failed_result.items():
check_name = '\x1B[1;4m' + k + '\x1B[0m'
print(check_name)
print("Failed Objects:")
pprint.pprint(v)
print('\x1B[1;4m', '\x1B[0m')
UNSKRIPT_GLOBALS['failed_result'] = failed_result

print("")
status_list_of_dict.append(status_dict)
Expand Down Expand Up @@ -390,7 +384,17 @@ def run_checks(filter: str):
run_ipynb(rb, status_of_runs)

update_audit_trail(status_of_runs)
print_run_summary(status_of_runs)
#print_run_summary(status_of_runs)
if UNSKRIPT_GLOBALS.get('failed_result') and len(UNSKRIPT_GLOBALS.get('failed_result')):
print("")
print('\x1B[1;4m' + "FAILED RESULTS" + '\x1B[0m')
print("")
for k, v in UNSKRIPT_GLOBALS.get('failed_result').items():
check_name = '\x1B[1;4m' + k + '\x1B[0m'
print(check_name)
print("Failed Objects:")
pprint.pprint(v)
print('\x1B[1;4m', '\x1B[0m')


def run_suites(suite_name: str):
Expand Down Expand Up @@ -422,6 +426,16 @@ def run_suites(suite_name: str):

update_audit_trail(status_of_runs)
print_run_summary(status_of_runs)
if UNSKRIPT_GLOBALS.get('failed_result') and len(UNSKRIPT_GLOBALS.get('failed_result')):
print("")
print('\x1B[1;4m' + "FAILED RESULTS" + '\x1B[0m')
print("")
for k, v in UNSKRIPT_GLOBALS.get('failed_result').items():
check_name = '\x1B[1;4m' + k + '\x1B[0m'
print(check_name)
print("Failed Objects:")
pprint.pprint(v)
print('\x1B[1;4m', '\x1B[0m')


def print_run_summary(status_list_of_dict):
Expand Down Expand Up @@ -456,13 +470,13 @@ def print_run_summary(status_list_of_dict):
else:
p = f = e = -1

if UNSKRIPT_GLOBALS.get('skipped'):
s = len(UNSKRIPT_GLOBALS.get('skipped'))

summary_table.append([
sd.get('runbook'),
str(str(p) + ' / ' + str(f) + ' / ' + str(e) + ' ( ' + str(p+f+e) + ' ) / ( ' + str(s) + ' )')
])
if UNSKRIPT_GLOBALS.get('skipped'):
s = len(UNSKRIPT_GLOBALS.get('skipped'))
summary_table.append([
sd.get('runbook'),
str(str(p) + ' / ' + str(f) + ' / ' + str(e) + ' ( ' + str(p+f+e) + ' ) / ( ' + str(s) + ' )')
])

s = '\x1B[1;20;46m' + "~~ Summary ~~" + '\x1B[0m'
print(s)
Expand Down Expand Up @@ -497,7 +511,7 @@ def update_current_execution(status, id: str, content: dict):

# If failed directory does not exists, lets create it
if os.path.exists(os.environ.get('EXECUTION_DIR').strip('"') + '/workspace') is False:
os.mkdir(os.makedirs(os.environ.get('EXECUTION_DIR').strip('"') + '/workspace'))
os.makedirs(os.environ.get('EXECUTION_DIR').strip('"') + '/workspace')

prev_status = None
es = {}
Expand Down Expand Up @@ -549,24 +563,26 @@ def update_current_execution(status, id: str, content: dict):
def replace_input_with_globals(inputSchema: str):
if not inputSchema:
return None

input_json_start_line = '''
retval = ''
if UNSKRIPT_GLOBALS.get('globals') and len(UNSKRIPT_GLOBALS.get('globals')):
input_json_start_line = '''
task.configure(inputParamsJson=\'\'\'{
'''
input_json_end_line = '''}\'\'\')
'''
input_json_line = ''
try:
schema = inputSchema[0]
if schema.get('properties'):
for key in schema.get('properties').keys():
if key in UNSKRIPT_GLOBALS.get('globals').keys():
input_json_line += f"\"{key}\": \"{key}\" ,"
except Exception as e:
print(f"EXCEPTION {e}")
pass
'''
input_json_end_line = '''}\'\'\')
'''
input_json_line = ''
try:
schema = inputSchema[0]
if schema.get('properties'):
for key in schema.get('properties').keys():
if key in UNSKRIPT_GLOBALS.get('globals').keys():
input_json_line += f"\"{key}\": \"{key}\" ,"
except Exception as e:
print(f"EXCEPTION {e}")
pass

retval = input_json_start_line + input_json_line.rstrip(',') + '\n' + input_json_end_line
retval = input_json_start_line + input_json_line.rstrip(',') + '\n' + input_json_end_line

return retval


Expand All @@ -584,7 +600,10 @@ def create_jit_runbook(check_list: list):
:rtype: None
"""
nb = nbformat.v4.new_notebook()
failed_notebook = os.environ.get('EXECUTION_DIR', '/unskript/data').strip('"') + '/workspace/' + str(uuid.uuid4()) + '.ipynb'
if os.path.exists(os.environ.get('EXECUTION_DIR') + '/workspace') == False:

Check failure on line 603 in unskript-ctl/unskript-client.py

View workflow job for this annotation

GitHub Actions / Pylint

unskript-ctl/unskript-client.py#L603

Comparison 'os.path.exists(os.environ.get('EXECUTION_DIR') + '/workspace') == False' should be 'os.path.exists(os.environ.get('EXECUTION_DIR') + '/workspace') is False' if checking for the singleton value False, or 'not os.path.exists(os.environ.get('EXECUTION_DIR') + '/workspace')' if testing for falsiness (singleton-comparison, C0121)
os.makedirs(os.environ.get('EXECUTION_DIR') + '/workspace')

failed_notebook = os.environ.get('EXECUTION_DIR', '/unskript/data/execution').strip('"') + '/workspace/' + str(uuid.uuid4()) + '.ipynb'
for check in check_list:
s_connector = check.get('metadata').get('action_type')
s_connector = s_connector.replace('LEGO', 'CONNECTOR')
Expand Down Expand Up @@ -1539,10 +1558,12 @@ def stop_debug():
if __name__ == "__main__":
try:
if os.environ.get('EXECUTION_DIR') is None:
os.environ['EXECUTION_DIR'] = '/unskript/data/execution'
os.environ['EXECUTION_DIR'] = '/unskript/data/execution'
if os.path.exists(os.environ.get('EXECUTION_DIR')) == False:

Check failure on line 1562 in unskript-ctl/unskript-client.py

View workflow job for this annotation

GitHub Actions / Pylint

unskript-ctl/unskript-client.py#L1562

Comparison 'os.path.exists(os.environ.get('EXECUTION_DIR')) == False' should be 'os.path.exists(os.environ.get('EXECUTION_DIR')) is False' if checking for the singleton value False, or 'not os.path.exists(os.environ.get('EXECUTION_DIR'))' if testing for falsiness (singleton-comparison, C0121)
os.makedirs(os.environ.get('EXECUTION_DIR'))

create_creds_mapping()
load_or_create_global_configuration()
create_creds_mapping()
except Exception as error:
raise error

Expand All @@ -1560,8 +1581,8 @@ def stop_debug():
help='Run the given runbook FILENAME [-RUNBOOK_PARM1 VALUE1] etc..')
parser.add_argument('-rc', '--run-checks', type=str,
help='Run all available checks [all | connector | failed]')
# parser.add_argument('-rs', '--run-suites', type=str,
# help='Run Health Check Suites (as defined in the unskript_config.yaml file)')
#parser.add_argument('-rs', '--run-suites', type=str,
# help='Run Health Check Suites (as defined in the unskript_config.yaml file)')
parser.add_argument('-df', '--display-failed-checks',
help='Display Failed Checks [all | connector]')
parser.add_argument('-lc', '--list-checks', type=str,
Expand Down Expand Up @@ -1596,8 +1617,8 @@ def stop_debug():
parse_runbook_param(args.run_runbook)
elif args.run_checks not in ('', None):
run_checks(args.run_checks)
# elif args.run_suites not in ('', None):
# run_suites(args.run_suites)
#elif args.run_suites not in ('', None):
# run_suites(args.run_suites)
elif args.display_failed_checks not in ('', None):
display_failed_checks(args.display_failed_checks)
elif args.list_checks not in ('', None):
Expand All @@ -1618,4 +1639,4 @@ def stop_debug():
elif args.stop_debug is True:
stop_debug()
else:
parser.print_help()
parser.print_help()

0 comments on commit 3d8e7d0

Please sign in to comment.