%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/testinframod.pyc

�
���^c@@sCdZddlmZmZmZddlZddlZddlZddlZddl	Z	ej
e�Zy&ddl
Z
ddl
mZeZWnek
r�eZnXgZdZdZdefd��YZd	�Zed
�Zd�Zd�Zdd
�Zd�Zd�Zdd�Z d�Z!er?e!�ndS(uu
This module exposes the functionality of the TestInfra library
for use with SaltStack in order to verify the state of your minions.
In order to allow for the addition of new resource types in TestInfra this
module dynamically generates wrappers for the various resources by iterating
over the values in the ``__all__`` variable exposed by the testinfra.modules
namespace.
i(tabsolute_importtunicode_literalstprint_functionN(tmodulesu	testinfraulocal://tInvalidArgumentErrorcB@seZRS((t__name__t
__module__(((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyR!scC@str
tStdfS(Nu&The Testinfra package is not available(tTESTINFRA_PRESENTt__virtualname__tFalse(((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt__virtual__%scC@s"tj|�}|jt|��S(uRetrieve the correct module implementation determined by the backend
    being used.

    :param module_name: TestInfra module to retrieve
    :param backend: string representing backend for TestInfra
    :returns: desired TestInfra module object
    :rtype: object

    (t	testinfratget_backendt
get_modulet_to_pascal_case(tmodule_nametbackendtbackend_instance((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_get_module+s
cC@sgtjdd|�}g}x<|j�D].}|j|dj��|j|d�q(Wdj|�S(u�Convert a snake_case string to its PascalCase equivalent.

    :param snake_case: snake_cased string to be converted
    :returns: PascalCase string
    :rtype: str

    u_u iiu(tretsubtsplittappendtuppertjoin(t
snake_caset
space_casetwordlisttword((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyR9scC@s+tjdd�|�}|j�jd�S(u�Convert a PascalCase string to its snake_case equivalent.

    :param pascal_case: PascalCased string to be converted
    :returns: snake_case string
    :rtype: str

    u(^|[a-z])([A-Z])cS@s.dj|jd�j�|jd�j��S(Nu{0}_{1}ii(tformattgrouptlower(tmatch((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt<lambda>Rsu_(RRRtstrip(tpascal_caseR((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_to_snake_caseIs		cC@sHtjd||�yt||�}WnPtk
rxyt||�}Wqytk
rttdj||���qyXnXt|t�r�|j|�St|t	j
t	jf�r@|s�tdj||���nyt||�|d�SWqDtk
rtdj|���qDtk
r<tdj||���qDXn|SdS(u�Given a TestInfra module object, an instance of that module, and a
    method name, return the result of executing that method against the
    desired module.

    :param module: TestInfra module object
    :param module_instance: TestInfra module instance
    :param method_name: string representing the method to be executed
    :param method_arg: boolean or dictionary object to be passed to method
    :returns: result of executing desired method with supplied argument
    :rtype: variable

    uTrying to call %s on %su=The {0} module does not have any property or method named {1}u@{0} is a method of the {1} module. An argument dict is required.u	parameteru<The argument dict supplied has no key named "parameter": {0}N(tlogtdebugtgetattrtAttributeErrorRRt
isinstancetpropertytfgetttypest
MethodTypetFunctionTypetKeyErrortNone(tmodule_tmodule_instancetmethod_namet
method_argt
method_obj((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_get_method_resultXs6


	
	
	
	cC@s�tjd||�t|t�r,||kSt|t�r�ytt|d�}Wnptk
r�|jd�dkr�t	j
}q�tdj|jd����n!t
k
r�tjd��nX||d|�Stdjt|����dS(	uiGiven the result of a method, verify that it matches the expectation.

    This is done by either passing a boolean value as an expecation or a
    dictionary with the expected value and a string representing the desired
    comparison, as defined in the `operator module <https://docs.python.org/2.7/library/operator.html>`_
    (e.g. 'eq', 'ge', etc.). The ``re.search`` function is also available with
    a comparison value of ``search``.

    :param expected: boolean or dict
    :param result: return value of :ref: `_get_method_result`
    :returns: success or failure state of assertion
    :rtype: bool

    u&Expected result: %s. Actual result: %su
comparisonusearchu(Comparison {0} is not a valid selection.uoThe comparison dictionary provided is missing expected keys. Either "expected" or "comparison" are not present.uexpectedu&Expected bool or dict but received {0}N(R%R&R)tbooltdictR'toperatorR(tgetRtsearchRRR/t	exceptiont	TypeErrorttype(texpectedtresultt
comparison((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_apply_assertion�s"

	

	cC@s|jS(N(t__doc__(R1((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt
_build_doc�sc@sntjd���fd�}|}|dk	r@t|�}n	|j}tj|j|j||j	|j
�S(uV
    This will generate a function that is registered as either ``module_name``
    or ``name``. The contents of the function will be ``_run_tests``. This
    will translate the Testinfra module into a salt function and the methods
    and properties of that module will be exposed as attributes of the salt
    function that is generated. This allows for writing unit tests for a
    configured minion using states in the same way as it is configured

    Example:

    ```yaml
    minion_is_installed:
      testinfra.package:
        - name: salt-minion
        - is_installed: True

    minion_is_running:
      testinfra.service:
        - name: salt-minion
        - is_running: True
        - is_enabled: True

    file_has_contents:
      testinfra.file:
        - name: /etc/salt/minion
        - exists: True
        - contains:
            parameter: master
            expected: True
            comparison: is_

    python_is_v2:
      testinfra.package:
        - name: python
        - is_installed: True
        - version:
            expected: '2.7.9-1'
            comparison: eq
    ```
    u$Generating function for testinfra.%sc
@s�t}g}g}y3tjd��t��}tjd|j�Wn1tk
rxtjd��t}|||fSXtt	d�r�t	j
|�}|j}nWt|j
tj�r�t	j|j
�}n$t|d�r�t	j|j�}n|j}tjd�|�i}x6t|�jt|��D]}	|j|	�||	<q/Wy1t|�dkrs|||�}
n	|�}
Wn!tk
r�tjd��nXi}tjd	|�x.|D]&}|jd
�s�||||<q�q�Wtjd|�x�|j�D]�\}
}	t||
|
|	�}t|	|�}|sut}|jdjd
�d|d|
d|	d|��q|jdjd
�d|d|
d|	d|��qW|||fS(NuRetrieving %s module.uRetrieved module is %su@The %s module is not supported for this backend and/or platform.u	signatureu__call__u$Parameters accepted by module %s: %siuModule failed to instantiateuCalled methods are: %su_uValid methods are: %su;Assertion failed: {modname} {n} {m} {a}. Actual result: {r}tmodnametntmtatru<Assertion passed:  {modname} {n} {m} {a}. Actual result: {r}(tTrueR%R&Rt__dict__tNotImplementedErrorR<R	thasattrtinspectt	signaturet
parametersR)t__init__R,R-t
getargspect__call__targstsettintersectiontpoptlenR=t
startswithtitemsR6RBRR(tnametmethodstsuccesst	pass_msgst	fail_msgstmodtmod_sigRPtadditional_argstargtmodinstancet
valid_methodst	meth_nametmethR@tassertion_result(R(s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt
_run_tests�sb
		
"



%&N(R%R&R0tstrRR,R.t__code__t__globals__t__defaults__t__closure__(RR[Ritfunc((Rs=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_copy_function�s)9	cC@s�y&gtjD]}t|�^q
}Wn-tk
rUgtjD]}|^q@}nXxF|D]>}t||�}t|�|_tj|�|t�|<q]WdS(u�
    Iterate through the exposed Testinfra modules, convert them to salt
    functions, and then register them in the module namespace so that they
    can be called via salt.
    N(	Rt__all__R$R(RpRDRCRtglobals(R1tmodules_tmod_nametmod_func((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt_register_functions%s&
 

("RCt
__future__RRRRNtloggingR9RR,t	getLoggerRR%RRRJRtImportErrorR	RqRtdefault_backendt	ExceptionRR
RRR$R0R6RBRDRpRv(((s=/usr/lib/python2.7/site-packages/salt/modules/testinframod.pyt<module>	s8


			/	(	r	

Zerion Mini Shell 1.0