Skip to content

Commit

Permalink
Fixed UT fixes for missing checks in report (#1036)
Browse files Browse the repository at this point in the history
Co-authored-by: shloka-bhalgat-unskript <[email protected]>
  • Loading branch information
1 parent 8a4c885 commit 138872f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
23 changes: 18 additions & 5 deletions unskript-ctl/templates/last_cell_content.j2
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
from unskript.legos.utils import CheckOutput, CheckOutputStatus
global w

all_outputs = []
other_outputs = []
try:
if 'w' in globals():
if w.check_run:
for id,output in w.check_output.items():
output = json.loads(output)
output['id'] = id
print(json.dumps(output))
all_outputs.append(output)
# Lets check if we have errored_checks or timeout_checks
# exists, if yes then lets dump the output
if hasattr(w, 'check_uuid_entry_function_map'):
if hasattr(w, 'timeout_checks') and len(w.timeout_checks):
for name, err_msg in w.timeout_checks.items():
_id = w.check_uuid_entry_function_map.get(name)
print(json.dumps({
other_outputs.append({
"status": 3,
"objects": None,
"error": err_msg,
"id": str(_id)
}))
})
if hasattr(w, 'errored_checks') and len(w.errored_checks):
for name, err_msg in w.errored_checks.items():
_id = w.check_uuid_entry_function_map.get(name)
print(json.dumps({
other_outputs.append({
"status": 3,
"objects": None,
"error": err_msg,
"id": str(_id)
}))
})
if other_outputs:
for _other in other_outputs:
for _output in all_outputs:
# Lets eliminate duplicate entries in the output
# We could have double accounted failed and error timeout
# case
if _other.get('id') == _output.get('id'):
_output = _other

for _output in all_outputs:
print(json.dumps(_output))
else:
print(json.dumps("Not a check run"))
else:
Expand Down
2 changes: 1 addition & 1 deletion unskript-ctl/unskript_ctl_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def critical(self, msg, *args, **kwargs):
def dump_to_file(self, msg):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(self.log_file_name, 'a') as f:
f.write(timestamp + ' : ' + msg + '\n')
f.write(timestamp + ' : ' + str(msg) + '\n')

# This is the Base class, Abstract class that shall be used by all the other
# classes that are implemented. This class is implemented as a Singleton class
Expand Down
24 changes: 15 additions & 9 deletions unskript-ctl/unskript_ctl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, **kwargs):
self.script_to_check_mapping = {}
# Prioritized checks to uuid mapping
self.prioritized_checks_to_id_mapping = {}
self.map_entry_function_to_check_name = {}

for k,v in self.checks_globals.items():
os.environ[k] = json.dumps(v)
Expand Down Expand Up @@ -103,7 +104,6 @@ def run(self, **kwargs):
self.logger.error("Output is None from check's output")
self._error('OUTPUT IS EMPTY FROM CHECKS RUN!')
sys.exit(0)

with open(output_file, 'w', encoding='utf-8') as f:
f.write(json.dumps(outputs))
if len(outputs) == 0:
Expand Down Expand Up @@ -179,33 +179,36 @@ def display_check_result(self, checks_output):
_action_uuid = payload.get('id')
if _action_uuid:
c_name = self.connector_types[idx] + ':' + self.prioritized_checks_to_id_mapping[_action_uuid]
p_check_name = self.prioritized_checks_to_id_mapping[_action_uuid]
else:
c_name = self.connector_types[idx] + ':' + self.check_names[idx]

p_check_name = self.check_names[idx]
if p_check_name in self.check_entry_functions:
p_check_name = self.map_entry_function_to_check_name.get(p_check_name)
if ids and CheckOutputStatus(payload.get('status')) == CheckOutputStatus.SUCCESS:
result_table.append([
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
self.TBL_CELL_CONTENT_PASS,
0,
'N/A'
])
checks_per_priority_per_result_list[priority]['PASS'].append([
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
ids[idx],
self.connector_types[idx]]
)
elif ids and CheckOutputStatus(payload.get('status')) == CheckOutputStatus.FAILED:
failed_objects = payload.get('objects')
failed_result[c_name] = failed_objects
result_table.append([
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
self.TBL_CELL_CONTENT_FAIL,
len(failed_objects),
self.parse_failed_objects(failed_object=failed_objects)
])
failed_result_available = True
checks_per_priority_per_result_list[priority]['FAIL'].append([
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
ids[idx],
self.connector_types[idx]
])
Expand All @@ -219,14 +222,14 @@ def display_check_result(self, checks_output):
failed_result_available = True
error_msg = payload.get('error') if payload.get('error') else self.parse_failed_objects(failed_object=failed_objects)
result_table.append([
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
self.TBL_CELL_CONTENT_ERROR,
0,
pprint.pformat(error_msg, width=30)
])
checks_per_priority_per_result_list[priority]['ERROR'].append([
# self.check_names[idx],
self.prioritized_checks_to_id_mapping[payload.get('id')],
p_check_name,
ids[idx],
self.connector_types[idx]
])
Expand Down Expand Up @@ -337,9 +340,12 @@ def _create_jit_script(self, checks_list: list = None):
for idx,c in enumerate(checks_list[:]):
_entry_func = c.get('metadata', {}).get('action_entry_function', '')
_action_uuid = c.get('metadata', {}).get('action_uuid', '')
_check_name = c.get('metadata', {}).get('action_title', '')
idx += 1
self.script_to_check_mapping[f"check_{idx}"] = _entry_func
self.prioritized_checks_to_id_mapping[str(_action_uuid)] = _entry_func
self.map_entry_function_to_check_name[_entry_func] = _check_name

exec_timeout = per_check_timeout.get(_entry_func, execution_timeout)
f.write(f"@timeout(seconds={exec_timeout}, error_message=\"Check check_{idx} timed out\")\n")
check_name = f"def check_{idx}():"
Expand Down Expand Up @@ -905,4 +911,4 @@ def create_checks_for_matrix_argument(self, list_of_actions: list):
if self.info_globals and len(self.info_globals):
action_list = self._common.create_checks_for_matrix_argument(actions=list_of_actions,
matrix=self.matrix)
return action_list
return action_list

0 comments on commit 138872f

Please sign in to comment.