def get_status_after_execution(exclude_labels=None): """ Set the environment status and assign it into ENV_STATUS_PRE dictionary. In addition compare the dict before the execution and after using DeepDiff Args: exclude_labels (list): App labels to ignore leftovers Raises: ResourceLeftoversException: In case there are leftovers in the environment after the execution """ get_environment_status(ENV_STATUS_POST, exclude_labels=exclude_labels) pod_diff = compare_dicts(ENV_STATUS_PRE["pod"], ENV_STATUS_POST["pod"]) sc_diff = compare_dicts(ENV_STATUS_PRE["sc"], ENV_STATUS_POST["sc"]) cephfs_diff = compare_dicts(ENV_STATUS_PRE["cephfs"], ENV_STATUS_POST["cephfs"]) cephbp_diff = compare_dicts(ENV_STATUS_PRE["cephbp"], ENV_STATUS_POST["cephbp"]) pv_diff = compare_dicts(ENV_STATUS_PRE["pv"], ENV_STATUS_POST["pv"]) pvc_diff = compare_dicts(ENV_STATUS_PRE["pvc"], ENV_STATUS_POST["pvc"]) namespace_diff = compare_dicts(ENV_STATUS_PRE["namespace"], ENV_STATUS_POST["namespace"]) diffs_dict = { "pods": pod_diff, "storageClasses": sc_diff, "cephfs": cephfs_diff, "cephbp": cephbp_diff, "pvs": pv_diff, "pvcs": pvc_diff, "namespaces": namespace_diff, } leftover_detected = False leftovers = {"Leftovers added": [], "Leftovers removed": []} for kind, kind_diff in diffs_dict.items(): if not kind_diff: continue if kind_diff[0]: leftovers["Leftovers added"].append( {f"***{kind}***": kind_diff[0]}) leftover_detected = True if kind_diff[1]: leftovers["Leftovers removed"].append( {f"***{kind}***": kind_diff[1]}) leftover_detected = True if leftover_detected: raise exceptions.ResourceLeftoversException( f"\nThere are leftovers in the environment after test case:" f"\nResources added:\n{yaml.dump(leftovers['Leftovers added'])}" f"\nResources " f"removed:\n {yaml.dump(leftovers['Leftovers removed'])}")
def get_status_after_execution(): """ Set the environment status and assign it into ENV_STATUS_PRE dictionary. In addition compare the dict before the execution and after using DeepDiff Raises: ResourceLeftoversException: In case there are leftovers in the environment after the execution """ get_environment_status(ENV_STATUS_POST) pod_diff = compare_dicts(ENV_STATUS_PRE['pod'], ENV_STATUS_POST['pod']) sc_diff = compare_dicts(ENV_STATUS_PRE['sc'], ENV_STATUS_POST['sc']) cephfs_diff = compare_dicts(ENV_STATUS_PRE['cephfs'], ENV_STATUS_POST['cephfs']) cephbp_diff = compare_dicts(ENV_STATUS_PRE['cephbp'], ENV_STATUS_POST['cephbp']) pv_diff = compare_dicts(ENV_STATUS_PRE['pv'], ENV_STATUS_POST['pv']) pvc_diff = compare_dicts(ENV_STATUS_PRE['pvc'], ENV_STATUS_POST['pvc']) secret_diff = compare_dicts(ENV_STATUS_PRE['secret'], ENV_STATUS_POST['secret']) namespace_diff = compare_dicts(ENV_STATUS_PRE['namespace'], ENV_STATUS_POST['namespace']) diffs_dict = { 'pods': pod_diff, 'storageClasses': sc_diff, 'cephfs': cephfs_diff, 'cephbp': cephbp_diff, 'pvs': pv_diff, 'pvcs': pvc_diff, 'secrets': secret_diff, 'namespaces': namespace_diff, } leftover_detected = False leftovers = {'Leftovers added': [], 'Leftovers removed': []} for kind, kind_diff in diffs_dict.items(): if kind_diff[0]: leftovers['Leftovers added'].append( {f"***{kind}***": kind_diff[0]}) leftover_detected = True if kind_diff[1]: leftovers['Leftovers removed'].append( {f"***{kind}***": kind_diff[1]}) leftover_detected = True if leftover_detected: raise exceptions.ResourceLeftoversException( f"\nThere are leftovers in the environment after test case:" f"\nResources added:\n{yaml.dump(leftovers['Leftovers added'])}" f"\nResources " f"removed:\n {yaml.dump(leftovers['Leftovers removed'])}")
def get_status_after_execution(): """ Set the environment status and assign it into ENV_STATUS_PRE dictionary. In addition compare the dict before the execution and after using DeepDiff Raises: ResourceLeftoversException: In case there are leftovers in the environment after the execution """ get_environment_status(ENV_STATUS_POST) pod_diff = DeepDiff(ENV_STATUS_PRE['pod'], ENV_STATUS_POST['pod']) sc_diff = DeepDiff(ENV_STATUS_PRE['sc'], ENV_STATUS_POST['sc']) cephfs_diff = DeepDiff(ENV_STATUS_PRE['cephfs'], ENV_STATUS_POST['cephfs']) cephbp_diff = DeepDiff(ENV_STATUS_PRE['cephbp'], ENV_STATUS_POST['cephbp']) pv_diff = DeepDiff(ENV_STATUS_PRE['pv'], ENV_STATUS_POST['pv']) pvc_diff = DeepDiff(ENV_STATUS_PRE['pvc'], ENV_STATUS_POST['pvc']) secret_diff = DeepDiff(ENV_STATUS_PRE['secret'], ENV_STATUS_POST['secret']) namespace_diff = DeepDiff(ENV_STATUS_PRE['namespace'], ENV_STATUS_POST['namespace']) diffs_dict = { 'pods': pod_diff, 'sc': sc_diff, 'cephfs': cephfs_diff, 'cephbp': cephbp_diff, 'pvs': pv_diff, 'pvcs': pvc_diff, 'secret': secret_diff, 'ns': namespace_diff, } leftover_detected = False leftovers = {'Leftovers added': [], 'Leftovers removed': []} for kind, kind_diff in diffs_dict.items(): if ADDED_RESOURCE in kind_diff: try: leftovers['Leftovers added'].append({ kind: kind_diff[ADDED_RESOURCE][''.join( kind_diff[ADDED_RESOURCE])] }) except KeyError: leftovers['Leftovers added'].append( {kind: kind_diff[ADDED_RESOURCE]}) leftover_detected = True if REMOVED_RESOURCE in kind_diff: try: leftovers['Leftovers added'].append({ kind: kind_diff[REMOVED_RESOURCE][''.join( kind_diff[REMOVED_RESOURCE])] }) except KeyError: leftovers['Leftovers added'].append( {kind: kind_diff[REMOVED_RESOURCE]}) leftover_detected = True if leftover_detected: raise exceptions.ResourceLeftoversException( f"\nThere are leftovers in the environment after test case:" f"\nResources added: {leftovers['Leftovers added']}" f"\nResources removed: {leftovers['Leftovers removed']}")