HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible/plugins/callback/__pycache__/junit.cpython-39.pyc
a

�)g�5�@s�ddlmZmZmZeZdZddlZddlZddl	Z	ddl
mZddl
mZmZddlmZddlmZmZmZmZmZGdd	�d	e�ZGd
d�d�ZGdd
�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�
TestSuitescs�eZdZdZdZdZdZdZ�fdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�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	aggregateZjunitTcstt|���t�dtj�d��|_t�dd���|_	t�dd�|_
t�dd���|_t�dd���|_t�d	d
���|_
t�dd���|_t�dd�|_t�d
d�|_d|_d|_d|_d|_d|_i|_|jdur�t|j�|_tj�|j�s�t�|j�dS)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__cCs�|j}||jvrdS|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, css|]}d|VqdS)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�namerr6r8r+r+r,�_start_task�s
zCallbackModule._start_taskcCs�|jj}t|d�r$|jj}|jj}nd}d}|j|}|jdkrZ|dkrZ|j�dd�rZd}|dkrrd|jvrrd}n$d	|jvr�|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Cs�d|j|j|jf}|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�}|�|�}|jdkr�t||||d�St|||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../rAz
\.yml:[0-9]+$r�included)r>�	classname�timeZ
system_out�rcr)�indentrB)r>rQrRrC�	exception�
���)�message�output�msgzrc=%s�skippedZskip_reason) r>r=�finish�startrrrr�relpathrr!rG�basenamer�re�subrJr	�strrKrErFZ
_dump_results�_cleanse_stringr5�split�errors�appendr
Zfailuresrr[)r(rN�	host_datar>ZdurationZjunit_classname�resrS�dumpZ	test_caserXrYr+r+r,�_build_test_case�sB 







zCallbackModule._build_test_casecCstt|dd�dd�S)z] convert surrogate escapes to the unicode replacement character to avoid XML encoding errors �surrogateescape�re�replace)rr)r(�valuer+r+r,rc	szCallbackModule._cleanse_stringcCs�g}|j��D]F\}}|jtjvr.|jdkr.q|j��D]\}}|�|�||��q8qt	|j
|d�}t|gd�}|��}t
j�|jd|j
t��f�}	t|	d��"}
|
�t|dd��Wd�n1s�0YdS)	zF generate a TestSuite report from the collected TaskData and HostData r-)r>Zcases)Zsuitesz	%s-%s.xml�wbZsurrogate_or_strictrlN)r%r9r6�CZ
_ACTION_SETUPrrgrfrjrr#r
Z
to_pretty_xmlrrr7rrR�open�writer)r(Z
test_casesrLrNrMrgZ
test_suiteZtest_suites�reportZoutput_fileZxmlr+r+r,�_generate_report
szCallbackModule._generate_reportcCs(|j|_tj�tj�|j��d|_dS)Nr)Z
_file_namer"rr�splitextr_r#)r(Zplaybookr+r+r,�v2_playbook_on_start"sz#CallbackModule.v2_playbook_on_startcCs|��|_dS�N)r4r$)r(r=r+r+r,�v2_playbook_on_play_start&sz(CallbackModule.v2_playbook_on_play_startcCs|�|�dSrw�r?�r(r;r+r+r,�v2_runner_on_no_hosts)sz$CallbackModule.v2_runner_on_no_hostscCs|�|�dSrwry)r(r;Zis_conditionalr+r+r,�v2_playbook_on_task_start,sz(CallbackModule.v2_playbook_on_task_startcCs|�|�dSrwryrzr+r+r,�!v2_playbook_on_cleanup_task_start/sz0CallbackModule.v2_playbook_on_cleanup_task_startcCs|�|�dSrwryrzr+r+r,�!v2_playbook_on_handler_task_start2sz0CallbackModule.v2_playbook_on_handler_task_startFcCs,|r|jdkr|�d|�n|�d|�dS)NrArBrC)rrO)r(rK�
ignore_errorsr+r+r,�v2_runner_on_failed5sz"CallbackModule.v2_runner_on_failedcCs|�d|�dS)NrB�rO�r(rKr+r+r,�v2_runner_on_ok;szCallbackModule.v2_runner_on_okcCs|�d|�dS)Nr[r�r�r+r+r,�v2_runner_on_skipped>sz#CallbackModule.v2_runner_on_skippedcCs|�d|�dS)NrPr�)r(Z
included_filer+r+r,�v2_playbook_on_includeAsz%CallbackModule.v2_playbook_on_includecCs|��dSrw)rt)r(Zstatsr+r+r,�v2_playbook_on_statsDsz#CallbackModule.v2_playbook_on_stats)F)�__name__�
__module__�__qualname__�__doc__ZCALLBACK_VERSIONZ
CALLBACK_TYPEZ
CALLBACK_NAMEZCALLBACK_NEEDS_ENABLEDrr?rOrjrcrtrvrxr{r|r}r~r�r�r�r�r��
__classcell__r+r+r)r,rfs, 1
rc@s eZdZdZdd�Zdd�ZdS)r:z(
    Data about an individual task.
    cCs8||_||_||_||_d|_i|_t��|_||_dSrw)r<r>rr=r]rgrRr6)r(r<r>rr=r6r+r+r,rMs
zTaskData.__init__cCs^|j|jvrN|jdkr2d|j|jj|jf|_ntd|j|j|j|jf��||j|j<dS)NrPz%s
%sz'%s: %s: %s: duplicate host callback: %s)r<rgrJrK�	Exceptionrr=r>)r(�hostr+r+r,rHWs

zTaskData.add_hostN)r�r�r�r�rrHr+r+r+r,r:Hs
r:c@seZdZdZdd�ZdS)rIz(
    Data about an individual host.
    cCs&||_||_||_||_t��|_dSrw)r<r>rJrKrRr\)r(r<r>rJrKr+r+r,rgs
zHostData.__init__N)r�r�r�r�rr+r+r+r,rIbsrI)Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONrrRr`ZansiblerrpZansible.module_utils._textrrZansible.plugins.callbackrZansible.utils._junit_xmlr	r
rrr
rr:rIr+r+r+r,�<module>sN	c