HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/test.cpython-310.pyc
o

�N�g�=�@sdZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlmZddlmZdgZdddd	�Ze�e�Zed
�dd��Zd
d�Zdd�Zdd�Zdd�Zdd�Zd[dd�Z dd�Z!dd�Z"dd�Z#e	j$j%�&e#d �Z'd!d"�Z(d#d$�Z)d\d%d&�Z*d'd(�Z+d)d*�Z,d+d,�Z-d-d.�Z.d/d0�Z/d1d2�Z0d3d4�Z1d5d6�Z2d]d8d9�Z3d:d;�Z4d<d=�Z5d>d?�Z6d@dA�Z7d^dCdD�Z8d^dEdF�Z9d_dHdI�Z:dJdK�Z;dLdM�Z<d`dOdP�Z=dQdR�Z>dSdT�Z?dUdV�Z@dWdX�ZAdYdZ�ZBdS)az$
Module for running arbitrary tests
�N)�DEFAULT_HASH_TYPE)�depends�*�true�false�try)�true_�false_�try_Znon_existantmodulenamecC�dS)NZfoo�rrr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/test.py�missing_func$srcC�
tj��S)zz
    Call grains.items via the attribute

    CLI Example:

    .. code-block:: bash

        salt '*' test.attr_call
    )�__salt__�grains�itemsrrrr
�	attr_call)�

rcCs�gggggggd�}tD]K}d|vr|d�|�q|d�|�tt|�r-|d�|�t|D]%}|�d|��}ttt|�|�rI|d�|�|t|vrV|d�|�q1q|dD]}||dvrk|d�|�||dvrx|d	�|�q\|S)
z�
    Return a dict containing all of the execution modules with a report on
    the overall availability via different references

    CLI Example:

    .. code-block:: bash

        salt '*' test.module_report
    )�	functions�function_attrs�
function_subs�modules�module_attrs�
missing_attrs�missing_subs�.rrrrrrr)r�append�hasattr�getattr)�ret�ref�func�fullrrr
�
module_report6s:�	
���r$cC�|S)z�
    Return a string - used for testing the connection

    CLI Example:

    .. code-block:: bash

        salt '*' test.echo 'foo bar baz quo qux'
    r)�textrrr
�echo_�
r'cCsVtjj��st�dt�d��dStddd}t�dd�r&td	|�St|�S)
z�
    Used to make sure the minion is up and responding. Not an ICMP ping.

    Returns ``True``.

    CLI Example:

    .. code-block:: bash

        salt '*' test.ping
    z"test.ping received for minion '%s'�idT�proxyZ	proxytypez.pingZadd_proxymodule_to_optsFZproxymodule)	�salt�utils�platformZis_proxy�log�debug�__opts__�getZ	__proxy__)Zping_cmdrrr
�pingls

r2cCst�t|��dS)z�
    Instruct the minion to initiate a process that will sleep for a given
    period of time.

    CLI Example:

    .. code-block:: bash

        salt '*' test.sleep 20
    T)�time�sleep�int)�lengthrrr
r4�sr4�<cCst�t�d|��dS)z�
    Sleep for a random number of seconds, used to test long-running commands
    and minions returning at differing intervals

    CLI Example:

    .. code-block:: bash

        salt '*' test.rand_sleep 60
    rT)r3r4�random�randint)�maxrrr
�
rand_sleep�sr;cCstjjS)z}
    Return the version of salt on the minion

    CLI Example:

    .. code-block:: bash

        salt '*' test.version
    )r+�version�__version__rrrr
r<�s
r<cCr)z�
    Report the versions of dependent and system software

    CLI Example:

    .. code-block:: bash

        salt '*' test.versions_information
    )r+r<�versions_informationrrrr
r>�rr>cCsd�tj���S)z�
    Returns versions of components used by salt

    CLI Example:

    .. code-block:: bash

        salt '*' test.versions_report
    �
)�joinr+r<�versions_reportrrrr
rA�s
rA�versionscCstdd�S)z�
    Return the value for test.foo in the minion configuration file, or return
    the default value

    CLI Example:

    .. code-block:: bash

        salt '*' test.conf_test
    z
config.optionztest.foo�rrrrr
�	conf_test�srDcCstS)z�
    Return the configuration options passed to this minion

    CLI Example:

    .. code-block:: bash

        salt '*' test.get_opts
    )r0rrrr
�get_opts�r(rEcCs|durg}t||�S)a
    Execute a minion function via the ``__salt__`` object in the test
    module, used to verify that the Minion functions can be called
    via the ``__salt__`` module.

    CLI Example:

    .. code-block:: bash

        salt '*' test.cross_test file.gid_to_group 0
    NrC)r"�argsrrr
�
cross_test�srGcKr%)aR
    Print out the data passed into the function ``**kwargs``, this is used to
    both test the publication data and CLI ``kwarg`` passing, but also to display
    the information available within the publication data.

    CLI Example:

    .. code-block:: bash

        salt '*' test.kwarg num=1 txt="two" env='{a: 1, b: "hello"}'
    r)�kwargsrrr
�kwarg�srIcOs
||d�S)a�
    Print out the data passed into the function ``*args`` and ``kwargs``, this
    is used to both test the publication data and CLI argument passing, but
    also to display the information available within the publication data.

    :return: ``{"args": args, "kwargs": kwargs}``
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' test.arg 1 "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}'
    �rFrHrrJrrr
�args
rKcOsTgid�}|D]
}|d�tt|���q|��D]\}}tt|��|d|<q|S)a
    Print out the types of the ``args`` and ``kwargs``. This is used to test the types
    of the ``args`` and ``kwargs`` passed down to the Minion

    :rtype: dict

    CLI Example:

    .. code-block:: bash

           salt '*' test.arg_type 1 'int'
    rJrFrH)r�str�typer)rFrHr �argument�key�valrrr
�arg_types

rQcOst|�t|�d�S)a�
    Print out the data passed into the function ``*args`` and ``kwargs``, this
    is used to both test the publication data and CLI argument passing, but
    also to display the information available within the publication data.

    :return: ``{"args": repr(args), "kwargs": repr(kwargs)}``

    CLI Example:

    .. code-block:: bash

        salt '*' test.arg_repr 1 "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}'
    rJ)�reprrJrrr
�arg_repr2srScOst|tjjjdi|��d�S)z�
    Like :mod:`test.arg <salt.modules.test.arg>` but cleans ``kwargs`` of the ``__pub*`` items

    CLI Example:

    .. code-block:: bash

        salt '*' test.arg_clean 1 "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}'
    rJNr)�dictr+r,rF�clean_kwargsrJrrr
�	arg_cleanCs
rVcCszt|�}|dkrtd��t��}|dkr|t��|fSd}d}d}||kr5|||}}|d7}||ks&|t��|fS)a
    Return the ``num``-th Fibonacci number, and the time it took to compute in
    seconds. Used for performance tests.

    This function is designed to have terrible performance.

    CLI Example:

    .. code-block:: bash

        salt '*' test.fib 3
    rzNegative number is not allowed!��)r5�
ValueErrorr3)�num�start�prev�curr�irrr
�fibPs
�r_cCsht|�}t��}g}|dkr,|�|�|dkr(|ddkr"|d}n|dd}|dks|t��|fS)z�
    Execute the collatz conjecture from the passed starting number,
    returns the sequence and the time it took to compute. Used for
    performance tests.

    CLI Example:

    .. code-block:: bash

        salt '*' test.collatz 3
    rXrWr�)r5r3r)r[�beginZstepsrrr
�collatzns

�rbcCr%)z�
    Test the outputter, pass in data to return

    CLI Example:

    .. code-block:: bash

        salt '*' test.outputter foobar
    r)�datarrr
�	outputter�r(rd�*cCs|td<dS)z�
    Test that the returncode system is functioning correctly

    CLI Example:

    .. code-block:: bash

        salt '*' test.retcode 42
    �retcodeT)�__context__)�coderrr
rf�s
rfcCs\d}tD]
}|�|�d��sq|}|sdStjt|jj}tj�|�}|d|�	d��S)z�
    Pass in a function name to discover what provider is being used

    CLI Example:

    .. code-block:: bash

        salt '*' test.provider service
    �rN)
r�
startswith�sysr�
__module__�__file__�os�path�basename�rindex)�moduler"rOZpfnrrr
�provider�s
rscCs4i}tD]}|�d�d}||vr||t|�<q|S)z�
    Return a dict of the provider names and the files that provided them

    CLI Example:

    .. code-block:: bash

        salt '*' test.providers
    rr)r�splitrs)r �funcname�modnamerrr
�	providers�s
�rwcCs�t�}t�}tj�tdd�D].}tj�|�sqtj�	|�sqt�
|�D]}|�d�r+q#|�d�d}||vr;|�
|�q#qt|�S)z�
    List the modules that were not loaded by the salt loader system

    CLI Example:

    .. code-block:: bash

        salt '*' test.not_loaded
    rrr�_rr)rw�setr+�loaderZ_module_dirsr0rnro�isabs�isdir�listdirrjrt�add�sorted)Zprovr Zmod_dirZfn_�namerrr
�
not_loaded�s 


��r�cCsi}|�t�t��|d<|S)a
    Return an ``opts`` package with the ``grains`` and ``opts`` for this Minion.
    This is primarily used to create the options used for Master side
    state compiling routines

    CLI Example:

    .. code-block:: bash

        salt '*' test.opts_pkg
    r)�updater0Z
__grains__�value)r rrr
�opts_pkg�s
r���c(	cCst||d�S)a
    This function has been renamed to
    :mod:`test.random_hash <salt.modules.test.random_hash>`. This function will stay to
    ensure backwards compatibility, but please switch to using the preferred name
    :mod:`test.random_hash <salt.modules.test.random_hash>`.
    ��size�	hash_type)�random_hashr�rrr
�rand_str�sr�cCs"|st�dt�}tjjj||d�S)a�
    .. versionadded:: 2015.5.2
    .. versionchanged:: 2018.3.0
        Function has been renamed from ``test.rand_str`` to
        ``test.random_hash``

    Generates a random number between 1 and ``size``, then returns a hash of
    that number. If no ``hash_type`` is passed, the ``hash_type`` specified by the
    Minion's :conf_minion:`hash_type` config option is used.

    CLI Example:

    .. code-block:: bash

        salt '*' test.random_hash
        salt '*' test.random_hash hash_type=sha512
    r�r�)r0r1rr+r,Z	hashutilsr�r�rrr
r�sr��Test ExceptioncCst|��)z�
    Raise an exception

    Optionally provide an error message or output the full stack.

    CLI Example:

    .. code-block:: bash

        salt '*' test.exception 'Oh noes!'
    )�	Exception)�messagerrr
�	exceptionsr�cCsd�t���S)zq
    Return the current stack trace

    CLI Example:

    .. code-block:: bash

        salt '*' test.stack
    ri)r@�	traceback�format_stackrrrr
�stack's
r�cOr)z�
    Deprecated! Moved to :mod:`cmd.tty <salt.modules.cmdmod.tty>`

    CLI Example:

    .. code-block:: bash

        salt '*' test.tty tty0 'This is a test'
        salt '*' test.tty pts3 'This is a test'
    z.ERROR: This function has been moved to cmd.ttyrrJrrr
�tty4sr�Fc
KsPz
t|di|��WSty'}z|r|WYd}~SWYd}~dSd}~ww)a�
    Try to run a module command. On an exception return ``None``.
    If ``return_try_exception`` is set to ``True``, return the exception.
    This can be helpful in templates where running a module might fail as expected.

    Jinja Example:

    .. code-block:: jinja

        {% for i in range(0,230) %}
            {{ salt['test.try'](module='ipmi.get_users', bmc_host='172.2.2.'+i)|yaml(False) }}
        {% endfor %}
    Nr)rr�)rrZreturn_try_exceptionrH�errr
r
Bs
���r
cCs|sJ�dS)zv
    Assert the given argument

    CLI Example:

    .. code-block:: bash

        salt '*' test.assertion False
    Nr)�	assertionrrr
r�Xs
r�cCr)zh
    Always return ``True``

    CLI Example:

    .. code-block:: bash

        salt '*' test.true
    Trrrrr
rer(rcCr)zj
    Always return ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' test.false
    Frrrrr
r	rr(r	cs��fdd��z1|�d�rttj|dd��}ntt|�}�|�r/||itjjjd	i|�����t�	d|�WdSt
yGt�	d|�YdSw)
aC
    Raise an exception. Built-in exceptions and those in
    :mod:`salt.exceptions <salt.internals.salt.exceptions>`
    can be raised by this test function. If no matching exception is found,
    then no exception will be raised and this function will return ``False``.

    This function is designed to test Salt's exception and return code
    handling.

    CLI Example:

    .. code-block:: bash

        salt '*' test.raise_exception TypeError "An integer is required"
        salt '*' test.raise_exception salt.exceptions.CommandExecutionError "Something went wrong"
    cs(|jD]}|turdS�|�SdS)NFT)�	__bases__�
BaseException)�cls�base��_is_excrr
r��s
�z raise_exception.<locals>._is_exczsalt.exceptions.�Nz%s is not an exceptionFzNo such exception: %sr)rjrr+�
exceptions�builtinsr,rFrUr.�error�AttributeError)r�rFrH�excrr�r
�raise_exceptions


�r�cCs$tjj�dd�tjj�dd�dS)a
    Return True, but also produce two DeprecationWarnings. One by date, the
    other by the codename - release Oganesson, which should correspond to Salt
    3108.

    CLI Example:

    .. code-block:: bash

        salt \* test.deprecation_warning
    Z	Oganessonz.This is a test deprecation warning by version.Z30000101zMThis is a test deprecation warning by date very far into the future ({date}).T)r+r,rBZ
warn_untilZwarn_until_daterrrr
�deprecation_warning�s
��r�)r7)N)re)r�N)r�)F)C�__doc__r��loggingrnr8rkr3r�Zsalt.exceptionsr+Zsalt.loaderZsalt.utils.argsZsalt.utils.functoolsZsalt.utils.hashutilsZsalt.utils.platformZsalt.utils.versionsZsalt.versionZsalt.configrZsalt.utils.decoratorsrZ__proxyenabled__Z__func_alias__�	getLogger�__name__r.rrr$r'r2r4r;r<r>rAr,�	functoolsZalias_functionrBrDrErGrIrKrQrSrVr_rbrdrfrsrwr�r�r�r�r�r�r�r
r�rr	r�r�rrrr
�<module>s~�


)

















+