관리-도구
편집 파일: junit.cpython-39.pyc
a �����)g�5����������������������@���s����d�dl�mZmZmZ�eZdZd�dlZd�dlZd�dl Z d�dl mZ�d�dl mZmZ�d�dlmZ�d�dlmZmZmZmZmZ�G�dd ��d e�ZG�d d��d�ZG�dd ��d �ZdS�)�����)�absolute_import�division�print_functiona�� name: junit type: aggregate short_description: write playbook output to a JUnit file. version_added: historical description: - This callback writes playbook output to a JUnit formatted XML file. - "Tasks show up in the report as follows: 'ok': pass 'failed' with 'EXPECTED FAILURE' in the task name: pass 'failed' with 'TOGGLE RESULT' in the task name: pass 'ok' with 'TOGGLE RESULT' in the task name: failure 'failed' due to an exception: error 'failed' for other reasons: failure 'skipped': skipped" options: output_dir: name: JUnit output dir default: ~/.ansible.log description: Directory to write XML files to. env: - name: JUNIT_OUTPUT_DIR task_class: name: JUnit Task class default: False description: Configure the output to be one class per yaml file env: - name: JUNIT_TASK_CLASS task_relative_path: name: JUnit Task relative path default: none description: Configure the output to use relative paths to given directory version_added: "2.8" env: - name: JUNIT_TASK_RELATIVE_PATH replace_out_of_tree_path: name: Replace out of tree path default: none description: Replace the directory portion of an out-of-tree relative task path with the given placeholder version_added: "2.12.3" env: - name: JUNIT_REPLACE_OUT_OF_TREE_PATH fail_on_change: name: JUnit fail on change default: False description: Consider any tasks reporting "changed" as a junit test failure env: - name: JUNIT_FAIL_ON_CHANGE fail_on_ignore: name: JUnit fail on ignore default: False description: Consider failed tasks as a junit test failure even if ignore_on_error is set env: - name: JUNIT_FAIL_ON_IGNORE include_setup_tasks_in_report: name: JUnit include setup tasks in report default: True description: Should the setup tasks be included in the final report env: - name: JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT hide_task_arguments: name: Hide the arguments for a task default: False description: Hide the arguments for a task version_added: "2.8" env: - name: JUNIT_HIDE_TASK_ARGUMENTS test_case_prefix: name: Prefix to find actual test cases default: <empty> description: Consider a task only as test case if it has this value as prefix. Additionally failing tasks are recorded as failed test cases. version_added: "2.8" env: - name: JUNIT_TEST_CASE_PREFIX requirements: - enable in configuration N)� constants)�to_bytes�to_text)�CallbackBase)�TestCase� TestError�TestFailure� TestSuite� TestSuitesc�����������������������s����e�Zd�ZdZdZdZdZdZ��fdd�Zdd ��Z d d��Z dd ��Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zdd��Zdd��Zd)dd �Zd!d"��Zd#d$��Zd%d&��Zd'd(��Z���ZS�)*�CallbackModulea�� This callback writes playbook output to a JUnit formatted XML file. Tasks show up in the report as follows: 'ok': pass 'failed' with 'EXPECTED FAILURE' in the task name: pass 'failed' with 'TOGGLE RESULT' in the task name: pass 'ok' with 'TOGGLE RESULT' in the task name: failure 'failed' due to an exception: error 'failed' for other reasons: failure 'skipped': skipped This plugin makes use of the following environment variables: JUNIT_OUTPUT_DIR (optional): Directory to write XML files to. Default: ~/.ansible.log JUNIT_TASK_CLASS (optional): Configure the output to be one class per yaml file Default: False JUNIT_TASK_RELATIVE_PATH (optional): Configure the output to use relative paths to given directory Default: none JUNIT_FAIL_ON_CHANGE (optional): Consider any tasks reporting "changed" as a junit test failure Default: False JUNIT_FAIL_ON_IGNORE (optional): Consider failed tasks as a junit test failure even if ignore_on_error is set Default: False JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT (optional): Should the setup tasks be included in the final report Default: True JUNIT_HIDE_TASK_ARGUMENTS (optional): Hide the arguments for a task Default: False JUNIT_TEST_CASE_PREFIX (optional): Consider a task only as test case if it has this value as prefix. Additionally failing tasks are recorded as failed test cases. Default: <empty> g�������@Z aggregateZjunitTc��������������������s���t�t|������t�dtj�d��|�_t�dd����|�_ t�dd�|�_ t�dd����|�_t�dd����|�_t�d d ����|�_ t�dd����|�_t�dd�|�_t�d d��|�_d�|�_d�|�_d�|�_d�|�_d|�_i�|�_|�jd�ur�t|�j�|�_tj�|�j�s�t�|�j��d�S�)NZJUNIT_OUTPUT_DIRz~/.ansible.logZJUNIT_TASK_CLASS�FalseZJUNIT_TASK_RELATIVE_PATH��ZJUNIT_FAIL_ON_CHANGEZJUNIT_FAIL_ON_IGNOREZ#JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT�TrueZJUNIT_HIDE_TASK_ARGUMENTSZJUNIT_TEST_CASE_PREFIXZJUNIT_REPLACE_OUT_OF_TREE_PATHF)�superr����__init__�os�getenv�path� expanduser�_output_dir�lower�_task_class�_task_relative_path�_fail_on_change�_fail_on_ignore�_include_setup_tasks_in_report�_hide_task_arguments�_test_case_prefix�_replace_out_of_tree_path�_playbook_path�_playbook_name� _play_name� _task_dataZdisabledr����exists�makedirs)�self�� __class__���B/usr/lib/python3.9/site-packages/ansible/plugins/callback/junit.pyr�������s(���� zCallbackModule.__init__c�����������������C���s����|j�}||�jv�rdS�|�j}|������}|���}|j}|jsn|�jdkrnd� dd��|j ���D���}|rn|d|�7�}t|||||�|�j|<�dS�)z2 record the start of a task for one or more hosts N�falsez, c�����������������s���s���|�]}d�|�V��qdS�)z%s=%sNr+���)�.0�ar+���r+���r,���� <genexpr>���������z-CallbackModule._start_task.<locals>.<genexpr>� ) �_uuidr%���r$����get_name�stripZget_path�actionZno_logr����join�args�items�TaskData)r(����task�uuid�play�namer���r6���r8���r+���r+���r,����_start_task����s���� zCallbackModule._start_taskc�����������������C���s����|j�j}t|d�r$|jj}|jj}nd}d}|�j|�}|�jdkrZ|dkrZ|j�dd�rZd}|dkrrd|jv�rrd}n$d |jv�r�|dkr�d}n|dkr�d}|j� |�j �s�|dkr�|�t||||���d S�)z0 record the results of a task for a single host �_hostZinclude�true�okZchangedF�failedzEXPECTED FAILUREz TOGGLE RESULTN) Z_taskr3����hasattrr@���r>���r%���r����_result�get� startswithr ����add_host�HostData)r(����status�result� task_uuid� host_uuidZ host_name� task_datar+���r+���r,����_finish_task����s$���� zCallbackModule._finish_taskc�����������������C���s���d|j�|j|j�f�}|j|j�}|�jrL|jrLttj�t |j�t |�j���}n|j}|�j dur�|�d�r�|�j ttj�t |����}|�j dkr�t�dd|�}|jdkr�t|||t|j�d�S�|jj}|�d d �}|�j|d d�}|��|�}|jdkr�t||||d�S�t|||d �} |jdk�r�d|v��rV|d�����d�d�} |d�}| j�t| |d���n@d|v��r~|d�} | j�t| |d���n| j�td|�|d���n*|jdk�r�d|v��r�|d�} nd} | | _| S�)z7 build a TestCase from the given TaskData and HostData z[%s] %s: %sNz../rA���z \.yml:[0-9]+$r����included)r>���� classname�timeZ system_out�rcr���)�indentrB���)r>���rQ���rR���rC���� exception� ���)�message�output�msgzrc=%s�skippedZskip_reason) r>���r=����finish�startr���r���r���r����relpathr���r!���rG����basenamer����re�subrJ���r ����strrK���rE���rF���Z _dump_results�_cleanse_stringr5����split�errors�appendr ���Zfailuresr���r[���)r(���rN���� host_datar>���ZdurationZjunit_classname�resrS����dumpZ test_caserX���rY���r+���r+���r,����_build_test_case����sB���� zCallbackModule._build_test_casec�����������������C���s���t�t|dd�dd�S�)z] convert surrogate escapes to the unicode replacement character to avoid XML encoding errors �surrogateescape�re����replace)r���r���)r(����valuer+���r+���r,���rc��� ��s����zCallbackModule._cleanse_stringc�����������������C���s����g�}|�j����D�]F\}}|jtjv�r.|�jdkr.q|j���D�]\}}|�|��||���q8qt |�j |d�}t|gd�}|���}t j�|�jd|�j t���f��} t| d��"} | �t|dd���W�d����n1�s�0����Y��dS�) zF generate a TestSuite report from the collected TaskData and HostData r-���)r>���Zcases)Zsuitesz %s-%s.xml�wbZsurrogate_or_strictrl���N)r%���r9���r6����CZ _ACTION_SETUPr���rg���rf���rj���r���r#���r ���Z to_pretty_xmlr���r���r7���r���rR����open�writer���)r(���Z test_casesrL���rN���rM���rg���Z test_suiteZtest_suites�reportZoutput_fileZxmlr+���r+���r,����_generate_report ��s����zCallbackModule._generate_reportc�����������������C���s(���|j�|�_tj�tj�|�j��d�|�_d�S�)Nr���)Z _file_namer"���r���r����splitextr_���r#���)r(���Zplaybookr+���r+���r,����v2_playbook_on_start"��s����z#CallbackModule.v2_playbook_on_startc�����������������C���s���|����|�_d�S��N)r4���r$���)r(���r=���r+���r+���r,����v2_playbook_on_play_start&��s����z(CallbackModule.v2_playbook_on_play_startc�����������������C���s���|���|��d�S�rw����r?����r(���r;���r+���r+���r,����v2_runner_on_no_hosts)��s����z$CallbackModule.v2_runner_on_no_hostsc�����������������C���s���|���|��d�S�rw���ry���)r(���r;���Zis_conditionalr+���r+���r,����v2_playbook_on_task_start,��s����z(CallbackModule.v2_playbook_on_task_startc�����������������C���s���|���|��d�S�rw���ry���rz���r+���r+���r,����!v2_playbook_on_cleanup_task_start/��s����z0CallbackModule.v2_playbook_on_cleanup_task_startc�����������������C���s���|���|��d�S�rw���ry���rz���r+���r+���r,����!v2_playbook_on_handler_task_start2��s����z0CallbackModule.v2_playbook_on_handler_task_startFc�����������������C���s,���|r|�j�dkr|��d|��n|��d|��d�S�)NrA���rB���rC���)r���rO���)r(���rK���� ignore_errorsr+���r+���r,����v2_runner_on_failed5��s����z"CallbackModule.v2_runner_on_failedc�����������������C���s���|���d|��d�S�)NrB����rO����r(���rK���r+���r+���r,����v2_runner_on_ok;��s����zCallbackModule.v2_runner_on_okc�����������������C���s���|���d|��d�S�)Nr[���r����r����r+���r+���r,����v2_runner_on_skipped>��s����z#CallbackModule.v2_runner_on_skippedc�����������������C���s���|���d|��d�S�)NrP���r����)r(���Z included_filer+���r+���r,����v2_playbook_on_includeA��s����z%CallbackModule.v2_playbook_on_includec�����������������C���s���|������d�S�rw���)rt���)r(���Zstatsr+���r+���r,����v2_playbook_on_statsD��s����z#CallbackModule.v2_playbook_on_stats)F)�__name__� __module__�__qualname__�__doc__ZCALLBACK_VERSIONZ CALLBACK_TYPEZ CALLBACK_NAMEZCALLBACK_NEEDS_ENABLEDr���r?���rO���rj���rc���rt���rv���rx���r{���r|���r}���r~���r����r����r����r����r����� __classcell__r+���r+���r)���r,���r���f���s,��� 1 r���c�������������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)r:���z( Data about an individual task. c�����������������C���s8���||�_�||�_||�_||�_d�|�_i�|�_t���|�_||�_d�S�rw���)r<���r>���r���r=���r]���rg���rR���r6���)r(���r<���r>���r���r=���r6���r+���r+���r,���r���M��s���� zTaskData.__init__c�����������������C���s^���|j�|�jv�rN|jdkr2d|�j|j��j|jf�|_ntd|�j|�j|�j|jf���||�j|j�<�d�S�)NrP���z%s %sz'%s: %s: %s: duplicate host callback: %s)r<���rg���rJ���rK���� Exceptionr���r=���r>���)r(����hostr+���r+���r,���rH���W��s ���� zTaskData.add_hostN)r����r����r����r����r���rH���r+���r+���r+���r,���r:���H��s��� r:���c�������������������@���s���e�Zd�ZdZdd��ZdS�)rI���z( Data about an individual host. c�����������������C���s&���||�_�||�_||�_||�_t���|�_d�S�rw���)r<���r>���rJ���rK���rR���r\���)r(���r<���r>���rJ���rK���r+���r+���r,���r���g��s ����zHostData.__init__N)r����r����r����r����r���r+���r+���r+���r,���rI���b��s���rI���)Z __future__r���r���r����typeZ __metaclass__Z DOCUMENTATIONr���rR���r`���Zansibler���rp���Zansible.module_utils._textr���r���Zansible.plugins.callbackr���Zansible.utils._junit_xmlr ���r ���r���r���r ���r���r:���rI���r+���r+���r+���r,����<module>���s���N �c