File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/state.cpython-310.pyc
o
�N�g�! � @ s^ d Z ddlZddlZddlmZ e� Zdd� Zdd� Z dd � Z
ddd�Zdd
d�Zdd� Z
dS )zC
Utility functions for state functions
.. versionadded:: 2018.3.0
� N)�CommandExecutionErrorc C s
d� | �S )zJ
Generate the running dict tag string from the low data structure
z/{0[state]}_|-{0[__id__]}_|-{0[name]}_|-{0[fun]})�format)�low� r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/state.py�gen_tag s
r c C s. g }d| v r
t j�| �}nd| i}|�� D ]\}}||d kr q|�� D ]o\}}t|t�r2|�d�r3q$t|t�s9q$d}|D ]} t| t�sEq=| � dd�du }|rQ nq=|sUq$|D ];} t| t�s_qW| �� D ].\}
}|
dkrlqc|D ]"}|�� D ]\}
}||d kr�|
|� d|
�ks�qt|�
|||f� qtqnqcqWq$q|S ) zK
For a particular low chunk, search relevant onfail related states
�_|-�__id__�__FZonfail_stopTZonfail�state)�saltr �
split_low_tag�items�
isinstance�str�
startswith�list�dict�get�append)Zsid� highstate�onfails�st�fstateZfchunks�mod_�fchunkZonfail_handledZfdataZknobZfvalueZfreqs�fmodZfidr r r �search_onfail_requisites sP
�
�����!r c C s� d}| rg|rg|rgt |t�rgt| |�}|rg|D ]P}|\}}} |�� D ]>\}
}d|
v r0tj�|
�}n|�d|
�}
|
s<td��|
|d�}||d kr_||d kr_|�dt �}|dv rY|}|d u r_ nq!|du rfd }q|S )
a�
When a state fail and is part of a highstate, check
if there is onfail requisites.
When we find onfail requisites, we will consider the state failed
only if at least one of those onfail requisites also failed
Returns:
True: if onfail handlers succeeded
False: if one on those handler failed
None: if the state does not have onfail requisites
Nr r zno state id)r r r �result)FTF)
r r r r r r r
r �
ValueError�_empty)�state_id�state_result�runningr Znretr �handlerr r r ZrstateidZrstater Zid_Zofresultr r r �check_onfail_requisitesG s0
��r% Fc C s� t | t�sdS | sdS d}| �� D ]K\}}t}d|krt}|s&t ||�s&d}|rLt |t�rL|�dt�}|du r:d}n|tu rLt |t�rL|rLt|d|d�}|sWtt||| |��}|s\ |S q|S )zf
Check the total return value of the run and determine if the running
dict has any issues
FTZ
__extend__r )�recurser ) r r r r r r �check_result�boolr% )r# r&