Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/landscape/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/testing.cpython-310.pyc
o

���cV`�
@sHddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZm
Z
mZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZddlm Z dd
l!m"Z"ddl#m$Z$Gdd�dej�Z%Gdd�dej�Z&Gdd�de'�Z(Gdd�de(�Z)Gdd�de�Z*Gdd�de�Z+Gdd�de,�Z-Gdd�de'�Z.Gdd �d e'�Z/Gd!d"�d"e'�Z0Gd#d$�d$e'�Z1Gd%d&�d&e'�Z2ddd'd(d(d(dddddgd)�fd*d+�Z3d:d,d-�Z4d.d/�Z5Gd0d1�d1e'�Z6Gd2d3�d3e'�Z7Gd4d5�d5e'�Z8Gd6d7�d7e'�Z9Gd8d9�d9e"�Z:dS);�)�absolute_importN)�Handler�ERROR�	Formatter)�TestCase)�
StringType)�_PY3)�Failure)�Deferred)�ConnectError)�ConfigParser)�stringio�	cstringio)�BaseConfiguration)�EventHandlingReactorMixin)�	LoginInfoc@seZdZesejZdSdS)�CompatTestCaseN)�__name__�
__module__�__qualname__rr�assertItemsEqual�assertCountEqual�rr�7/usr/lib/python3/dist-packages/landscape/lib/testing.pyrs
�rcs,eZdZgZ�fdd�Z�fdd�Z�ZS)�HelperTestCasecsftt|���g|_t|jvr|j�dt�d}|jD]}|�}t|d�r*|�|�}|j�	|�q|S)Nr�set_up)
�superr�setUp�_helper_instances�LogKeeperHelper�helpers�insert�hasattrr�append)�self�result�helper_factory�helper��	__class__rrr(s



zHelperTestCase.setUpcs6t|j�D]}t|d�r|�|�qtt|���dS)N�	tear_down)�reversedrr"r*rr�tearDown)r$r'r(rrr,8s


�zHelperTestCase.tearDown)rrrr rr,�
__classcell__rrr(rr$src@s>eZdZdd�Z		ddd�Zd	d
�Zddd�Zdd
d�ZdS)�
FSTestCasecCsBt|d��}|��}Wd�n1swY|�||�dS)N�rb)�open�read�assertEqual)r$�filename�expected_content�fd�actual_contentrrr�assertFileContentBs
�zFSTestCase.assertFileContentN��tmp�wc	s�|dur|durt��}tj�||��n�dur/t�|||�\}	�t�|	�|dur/t���|durMt�|��
}
|
�	|�Wd�n1sHwY|�
|j���rb��fdd�}|�
|��S)a�Create a temporary file and return the path to it.

        @param content: Initial content for the file.
        @param suffix: Suffix to be given to the file's basename.
        @param prefix: Prefix to be given to the file's basename.
        @param basename: Full basename for the file.
        @param dirname: Put file inside this directory.

        The file is removed after the test runs.
        Ncs*z
t����WdStyYdSw�N)�os�remove�OSErrorr��backupsuffix�pathrr�
remove_backupcs
�z*FSTestCase.makeFile.<locals>.remove_backup)�tempfile�mkdtempr<rA�join�mkstemp�close�unlinkr0�write�
addCleanup�_clean_file)r$�content�suffix�prefix�basename�dirnamerA�moder@r5�filerBrr?r�makeFileGs$

�
zFSTestCase.makeFilecCsBztj�|�rt�|�WdSt�|�WdSty YdSw)ztTry to remove a filesystem path, whether it's a directory or file.

        @param path: the path to remove
        N)r<rA�isdir�shutil�rmtreerHr>)r$rArrrrKls�zFSTestCase._clean_filecCs4|dur
t�|�nt�|||�}|�|j|�|S)a@Create a temporary directory and return the path to it.

        @param suffix: Suffix to be given to the file's basename.
        @param prefix: Prefix to be given to the file's basename.
        @param dirname: Put directory inside this parent directory.

        The directory is removed after the test runs.
        N)r<�makedirsrCrDrJrK)r$rMrNrPrArrr�makeDirys
	zFSTestCase.makeDircCs6|dur|��}||_|j|||d�}t�|d�|S)z=Return the path to the script after writing it to a temp dir.N)rPrOi�)rX�bindirrSr<�chmod)r$�config�namerLrYr3rrr�write_script�s�zFSTestCase.write_script)Nr8r9NNNr:N)r8r9NNr;)rrrr7rSrKrXr]rrrrr.@s
�%

r.cs0eZdZ�fdd�Z�fdd�Zdd�Z�ZS)�ConfigTestCasecs(tt|���tj|_|�d�gt_dS�Nr8)rr^rr�default_config_filenames�_old_config_filenamesrS�r$r(rrr�szConfigTestCase.setUpcs|jt_tt|���dSr;)rarr`rr^r,rbr(rrr,�szConfigTestCase.tearDowncCs~t|�}t�}|�|�t|�}t�}|�|�|�t|���t|����|��D]}|�t|�|��t|�|���q*dS)z�
        Compare two configuration files for equality.  The order of parameters
        and comments may be different but the actual parameters and sections
        must be the same.
        N)rr�readfpr2�set�sections�dict�items)r$�first�second�first_fp�first_parser�	second_fp�
second_parser�sectionrrr�assertConfigEqual�s


���z ConfigTestCase.assertConfigEqual)rrrrr,ror-rrr(rr^�sr^c@s6eZdZdd�Zdd�Zdd�Zdd�Zdd
d�Zd	S)
�TwistedTestCasecCsXg}|�|j�|s|�d|f�dSt|dt�r(|�d||df�dS|dS)z�See C{twisted.trial._synctest._Assertions.successResultOf}.

        This is a copy of the original method, which is available only
        since Twisted 12.3.0 (from 2012-12-20).
        z6Success result expected on %r, found no result insteadrz@Success result expected on %r, found failure result (%r) insteadN��addBothr#�fail�
isinstancer	�r$�deferredr%rrr�successResultOf����
��zTwistedTestCase.successResultOfcCsXg}|�|j�|s|�d|f�dSt|dt�s(|�d||df�dS|dS)z�See C{twisted.trial._synctest._Assertions.failureResultOf}.

        This is a copy of the original method, which is available only
        since Twisted 12.3.0 (from 2012-12-20).
        z6Failure result expected on %r, found no result insteadrz@Failure result expected on %r, found success result (%r) insteadNrqrurrr�failureResultOf�rxzTwistedTestCase.failureResultOfcCs2g}|�|j�|r|�d||df�dSdS)z�See C{twisted.trial._synctest._Assertions.assertNoResult}.

        This is a copy of the original method, which is available only
        since Twisted 12.3.0 (from 2012-12-20).
        z*No result expected on %r, found %r insteadrN)rrr#rsrurrr�assertNoResult�s���zTwistedTestCase.assertNoResultcs8|�t|t��g��fdd�}|�|�|���dS)Ncs��d�dS�NT)r#)r%��calledrr�callback��z9TwistedTestCase.assertDeferredSucceeded.<locals>.callback)�
assertTruertr
�addCallback)r$rvr~rr|r�assertDeferredSucceeded�s

z'TwistedTestCase.assertDeferredSucceededNcCs|�t|t��|�|j|�S)zS
        Assert that the given C{deferred} results in the given C{result}.
        )r�rtr
r�r2rurrr�
assertSuccess�szTwistedTestCase.assertSuccessr;)rrrrwryrzr�r�rrrrrp�s
	rpc@�eZdZdd�Zdd�ZdS)�ErrorHandlercOs"tj|g|�Ri|��g|_dSr;)r�__init__�errors)r$�args�kwargsrrrr�s
zErrorHandler.__init__cCs|jtkr
|j�|�dSdSr;)�levelnorr�r#)r$�recordrrr�emits
�zErrorHandler.emitN)rrrr�r�rrrrr��sr�c@�eZdZdd�ZdS)�LoggedErrorsErrorcCs0d}t�}|jdD]}||�|�d7}q
|S)Nz!The following errors were logged
r�
)rr��format)r$�out�	formatter�errorrrr�__str__s
zLoggedErrorsError.__str__N)rrrr�rrrrr�	�r�c@�(eZdZdZdd�Zdd�Zdd�ZdS)	rz�Record logging information.

    Puts a 'logfile' attribute on your test case, which is a StringIO
    containing all log output.
    cCs|g|_g|_t�|_||_t��|_}t�|_	t�
|j	�}d}|�t�|��|j
|_|j|_||jg|_
|�tj�dS)Nz%(levelname)8s: %(message)s)�ignored_exception_regexes�ignored_exception_typesr��
error_handler�
log_helper�logging�	getLogger�loggerr�logfile�
StreamHandler�setFormatterr�handlers�old_handlers�level�	old_level�setLevel�NOTSET)r$�	test_caser��handlerr�rrrrszLogKeeperHelper.set_upcCs�t��}|�|j�|j|_g}|jjD]-}|jD]}|j	r-|j	dr-t
|j	d|�r-nq|jD]
}|�|j
�r;nq1|�|�q|rHt|��dS�Nr)r�r�r�r�r�r�r�r�r��exc_info�
issubclassr��match�messager#r�)r$r�r�r�r��ignored_type�
ignored_regexrrrr*)s(
��
�
��zLogKeeperHelper.tear_downcCs0t|t�r|j�t�|��dS|j�|�dSr;)rt�
basestringr�r#�re�compiler�)r$�
type_or_regexrrr�
ignore_errors=s
zLogKeeperHelper.ignore_errorsN)rrr�__doc__rr*r�rrrrrs
rc@r�)�EnvironSnapshotcCstj��|_dSr;)r<�environ�copy�	_snapshotrbrrrr�F�zEnvironSnapshot.__init__cCs4tj�|j�ttj�D]}||jvrtj|=qdSr;)r<r��updater��list)r$�keyrrr�restoreIs
��zEnvironSnapshot.restoreN)rrrr�r�rrrrr�D�r�c@r�)�EnvironSaverHelpercCst�|_dSr;)r�r��r$r�rrrrRszEnvironSaverHelper.set_upcCs|j��dSr;)r�r�r�rrrr*UrzEnvironSaverHelper.tear_downN�rrrrr*rrrrr�Pr�r�c@sHeZdZddd�Zddd�Zddd�Zd	d
�Zddd�Zed
d��Z	dS)�	MockPopenNr8cCs,||_||_t|�|_g|_||_d|_dSr;)�output�err_outr�stdout�popen_inputs�return_codes�received_input)r$r�r�r�rrrr�[s

zMockPopen.__init__cCs|j||||d�S)N)�stdinr��stderr)�popen�r$r�r�r�r�rrr�__call__cszMockPopen.__call__cCs|j�|�|Sr;)r�r#r�rrrr�fszMockPopen.popencCs|jSr;)�
returncoderbrrr�waitjszMockPopen.waitcCs||_|j|jfSr;)r�r�r�)r$�inputrrr�communicatemszMockPopen.communicatecCs|jdurdS|j�d�Sr�)r��poprbrrrr�qs
zMockPopen.returncoder_)NNNr;)
rrrr�r�r�r�r��propertyr�rrrrr�Ys



r�c@r�)�StandardIOHelpercCs@tj|_tj|_t�|_t_t�|_t_tsd|j_dSdS)NzUTF-8)�sysr��
old_stdoutr��	old_stdinr
r�encodingr�rrrrzs�zStandardIOHelper.set_upcCs|jt_|jt_dSr;)r�r�r�r�r�r�rrrr*�szStandardIOHelper.tear_downNr�rrrrr�xsr�z/dev/r8)rrrrc
Cs~t|d�}
z4|
�t�tj|||�d�|�d�|�d�|�d�|||	|
||d|d|d|dd��W|
��dS|
��w)	z3Append binary login data to the specified filename.�abzutf-8r����N)r0rI�struct�packr�
RAW_FORMAT�encoderG)r3�
login_type�pid�
tty_device�id�username�hostname�termination_status�exit_status�
session_id�entry_time_seconds�entry_time_milliseconds�remote_ip_addressrRrrr�append_login_data�s
�
r�ccs�	|V|d7}q)z>Generator starts at zero and yields integers that grow by one.Tr�r)�irrr�mock_counter�s
��r�cCstd�S)zCGenerator starts at 100 and yields int timestamps that grow by one.�d)r�rrrr�	mock_time�sr�c@s0eZdZdZdd�Zdidddddfdd�ZdS)	�StubProcessFactoryzx
    A L{IReactorProcess} provider which records L{spawnProcess} calls and
    allows tests to get at the protocol.
    cC�
g|_dSr;)�spawnsrbrrrr���
zStubProcessFactory.__init__rNrc

Cs"|j�|||||||||	f	�dSr;)r�r#)
r$�protocol�
executabler��envrA�uid�gid�usePTY�childFDsrrr�spawnProcess�s
�zStubProcessFactory.spawnProcess)rrrr�r�r�rrrrr��s�r�c@r�)	�DummyProcessz/A process (transport) that doesn't do anything.cCr�r;)�signalsrbrrrr��r�zDummyProcess.__init__cCs|j�|�dSr;)rr#)r$�signalrrr�
signalProcess�r�zDummyProcess.signalProcesscCsdSr;r)r$r5rrr�closeChildFD�szDummyProcess.closeChildFDN)rrrr�r�rrrrrrr�s
rc@sJeZdZdZdZdZdZdZdZdZ	dZ
d	d
�Z		ddd�Zdd�Z
dS)�ProcessDataBuilderzBuilder creates sample data for the process info plugin to consume.

    @param sample_dir: The directory for sample data.
    zR (running)zT (stopped)zT (tracing stop)zD (disk sleep)zS (sleeping)zX (dead)z
Z (zombie)cCs
||_dSr;)�_sample_dir)r$�
sample_dirrrrr��r�zProcessDataBuilder.__init__rNT�-c
Csd|dd�||||	d�}
tj�|jt|��}t�|�tj�|d�}t|d�}
z|
�|
�W|
��n|
��w|durCd|f}tj�|d�}t|d�}
z|
�|�W|
��n|
��w|rid	d
|i}
nd}
tj�|d�}t|d�}
z|
�|
�W|
��dS|
��w)
aCreates sample data for a process.

        @param started_after_boot: The amount of time, in jiffies,
            between the system uptime and start of the process.
        @param process_name: Used to generate the process name that appears in
            /proc/%(pid)s/status
        @param generate_cmd_line: If true, place the process_name in
            /proc/%(pid)s/cmdline, otherwise leave it empty (this simulates a
            kernel process)
        @param stat_data: Array of items to write to the /proc/<pid>/stat file.
        a�
Name:   %(process_name)s
State:  %(state)s
Tgid:   24759
Pid:    24759
PPid:   17238
TracerPid:      0
Uid:    %(uid)d    0    0    0
Gid:    %(gid)d    0    0    0
FDSize: 256
Groups: 4 20 24 25 29 30 44 46 106 110 112 1000
VmPeak:    11680 kB
VmSize:    %(vmsize)d kB
VmLck:         0 kB
VmHWM:      6928 kB
VmRSS:      6924 kB
VmData:     1636 kB
VmStk:       196 kB
VmExe:      1332 kB
VmLib:      4240 kB
VmPTE:        20 kB
Threads:        1
SigQ:   0/4294967295
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000059816eff
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
N�)�process_name�stater�r��vmsize�statuszw+z,0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 %d�statzE/usr/sbin/%(process_name)s--pid-file/var/run/%(process_name)s.pid
r
r8�cmdline)	r<rArEr�str�mkdirr0rIrG)r$�
process_idrr�r��started_after_bootr
�generate_cmd_line�	stat_datar�sample_data�process_dirr3rRrrr�create_data�s>��!

�
�
zProcessDataBuilder.create_datacCs"tj�|jt|��}t�|�dS)z>Remove sample data for the process that matches C{process_id}.N)r<rArErrrUrV)r$rrrrr�remove_data(szProcessDataBuilder.remove_data)rNTNr)rrrr��RUNNING�STOPPED�TRACING_STOP�
DISK_SLEEP�SLEEPING�DEAD�ZOMBIEr�rrrrrrr�s
�Src@r�)�
FakeReactorIDcCsd|_||_dSr{)�active�_data)r$�datarrrr�0s
zFakeReactorID.__init__N)rrrr�rrrrr!.r�r!cs�eZdZdZiZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z	�fdd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Z�ZS)&�FakeReactorawA fake reactor with the same API of L{LandscapeReactor}.

    This reactor emulates the asychronous interface of L{LandscapeReactor}, but
    implementing it in a synchronous way, for easier unit-testing.

    Note that the C{listen_unix} method is *not* emulated, but rather inherited
    blindly from L{UnixReactorMixin}, this means that there's no way to control
    it in a synchronous way (see the docstring of the mixin). A better approach
    would be to fake the AMP transport (i.e. fake the twisted abstractions
    around Unix sockets), and implement a fake version C{listen_unix}, but this
    hasn't been done yet.
    cs<tt|���d|_g|_i|_g|_ddlm}||_	dS)Nr)�reactor)
rr%r��
_current_time�_calls�hosts�_threaded_callbacks�twisted.internetr&�_reactor)r$r&r(rrr�Gs
zFakeReactor.__init__cCs
t|j�Sr;)�floatr'rbrrr�timeSr�zFakeReactor.timecOs(|j|}||||f}|�|�t|�Sr;)r'�_insort_callr!)r$�seconds�fr�r��scheduled_time�callrrr�
call_laterVs

zFakeReactor.call_latercCs2dd�|jD�}t�||d�}|j�||�dS)NcSsg|]}|d�qS�rr)�.0�crrr�
<listcomp>`sz,FakeReactor._insort_call.<locals>.<listcomp>r)r(�bisect�bisect_leftr!)r$r3�times�indexrrrr/\szFakeReactor._insort_callcs(�������fdd���������S)NcsF�����j�_z
��i���WdSty"�jr!�����wr;)r4r#�	Exceptionr"�cancel_callr�r�r3r1�faker�r0r$rrr@fs
�z$FakeReactor.call_every.<locals>.fake�r4)r$r0r1r�r�rr?r�
call_everydszFakeReactor.call_everycsDt|�tur|j|jvr|j�|j�d|_dStt|��|�dS�NF)	�typer!r#r(r=r"rr%r>�r$r�r(rrr>ts

zFakeReactor.cancel_callcCs|�d|�dSr�rA)r$r1rrr�call_when_running|szFakeReactor.call_when_runningcs|j����fdd��dS)z5Schedule a function for execution in the main thread.cs��i���Sr;rr�r�r1r�rr�<lambda>�sz*FakeReactor.call_in_main.<locals>.<lambda>N)r*r#)r$r1r�r�rrGr�call_in_main�szFakeReactor.call_in_maincOs|�|||||�|��dS)asEmulate L{LandscapeReactor.call_in_thread} without spawning threads.

        Note that running threaded callbacks here doesn't reflect reality,
        since they're usually run while the main reactor loop is active. At
        the same time, this is convenient as it means we don't need to run
        the the real Twisted reactor with to test actions performed on
        completion of specific events (e.g. L{MessageExchange.exchange} uses
        call_in_thread to run the HTTP request in a separate thread, because
        we use libcurl which is blocking). IOW, it's easier to test things
        synchronously.
        N)�
_in_thread�_run_threaded_callbacks)r$r~�errbackr1r�r�rrr�call_in_thread�szFakeReactor.call_in_threadcs&G��fdd�dt�}|�j�<|�S)NcseZdZ��fdd�ZdS)z)FakeReactor.listen_unix.<locals>.FakePortcs�j���dSr;)�
_socket_pathsr�)�oself�r$�socket_pathrr�
stopListening�r�z7FakeReactor.listen_unix.<locals>.FakePort.stopListeningN)rrrrRrrPrr�FakePort�srS)�objectrN)r$rQ�factoryrSrrPr�listen_unix�s
zFakeReactor.listen_unixcCsT|j�|�}ddlm}|r|||�}|��|St�}ttd��}|�||�|S)Nr)�
FakeConnectorzNo such file or directory)	rN�get�landscape.lib.tests.test_amprW�connectrTr	r�clientConnectionFailed)r$rArU�serverrW�	connector�failurerrr�connect_unix�s
�zFakeReactor.connect_unixcCs>|�d�d|_|jr|�|jdd�|js|�d�dS)zAContinuously advance this reactor until reactor.stop() is called.�runTr�stopN)�fire�_running�advancer(rbrrrr`�s
�zFakeReactor.runcCs
d|_dSrC)rcrbrrrra�r�zFakeReactor.stopc
Cs�|jrY|jdd|j|krY|j�d�}||d|j8}|d|_z|d|di|d��WntyI}zt�|�WYd}~nd}~ww|jrY|jdd|j|ks|j|7_dS)aHAdvance this reactor C{seconds} into the future.

        This method is not part of the L{LandscapeReactor} API and is specific
        to L{FakeReactor}. It's meant to be used only in unit tests for
        advancing time and triggering the relevant scheduled calls (see
        also C{call_later} and C{call_every}).
        rr�r�r�N)r(r'r�r=r��	exception)r$r0r3�errrrd�s
���
zFakeReactor.advancec	
Cs�z	||i|��}Wn5ty>}z)t��}|dur#|jtj||d�n|j|g|�R�WYd}~dSWYd}~dSd}~ww|rI|�||�dSdS)N)r�)r=r�r�rIr�r�)	r$r~rLr1r�r�r%rfr�rrrrJ�s ����zFakeReactor._in_threadc
CsV|jr)z	|j�d��Wnty#}zt�|�WYd}~nd}~ww|jsdSdSr�)r*r�r=r�re)r$rfrrrrK�s���z#FakeReactor._run_threaded_callbackscCs|�d|j�}||_dS)Ng�?)rBrK�_run_threaded_callbacks_idrErrr�_hook_threaded_callbacks�s
z$FakeReactor._hook_threaded_callbackscCs|�|j�dSr;)r>rgrbrrr�_unhook_threaded_callbacks�r�z&FakeReactor._unhook_threaded_callbacks)rrrr�rNr�r.r4r/rBr>rFrIrMrVr_r`rardrJrKrhrir-rrr(rr%5s*

r%r5);�
__future__rr9r�r<�os.pathr�rUr�r�rC�unittestrrr�twisted.trial.unittestr�twisted.python.compatrr��landscape.lib.compatr�twisted.python.failurer	�twisted.internet.deferr
�twisted.internet.errorrrr
r�landscape.lib.configr�landscape.lib.reactorr�landscape.lib.sysstatsrrrrTr.r^rpr�r=r�rr�r�r�r�r�r�r�r�rrr!r%rrrr�<module>s`V"F
1	
�

j

Spamworldpro Mini