
    kc%U                         d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 dej                  v rd dlZej                  ZneZ G d de      Zd Zed	k(  r ej&                  d
       yy)    )unicode_literalsN	xmlrpclibSupervisorTransport
END_TO_ENDc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)EndToEndTestsc                    d}d}t        j                  t        d      }ddd|g}	 |t        j                  |<   t        j                  t        j                  |d      }| j                  |j                  t        j                         |j                  |d	z   |z          t        j                  |= y
# t        j                  |= w xY w)zWhen an environment variable whose value contains a percent sign is
        present in the environment before supervisord starts, the value is
        passed to the child without the percent sign being mangled.SUPERVISOR_TEST_1441Bzfoo_%s_%_%%_%%%_%2_barzfixtures/issue-291a.conf-msupervisor.supervisord-cutf-8encoding=N)pkg_resourcesresource_filename__name__osenvironpexpectspawnsys
executable
addCleanupkillsignalSIGINTexpect_exact)selfkeyvalfilenameargssupervisords         B/usr/lib/python3/dist-packages/supervisor/tests/test_end_to_end.py;test_issue_291a_percent_signs_in_original_env_are_preservedzIEndToEndTests.test_issue_291a_percent_signs_in_original_env_are_preserved   s     && 228=WX.h?	 !BJJsO!--wOKOOK,,fmm<$$S3Y_5

3

3s   A:B2 2Cc                 8   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       |j                  d       dd	d|d
dg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       |j                  t        j                         y)zWhen an environment variable is set in the [supervisord] section,
        it should be put into the environment of the subprocess.zfixtures/issue-550.confr   r   r   r   r   z(success: print_env entered RUNNING statez+exited: print_env (exit status 0; expected)supervisor.supervisorctlztail -100000	print_envzTHIS_SHOULD=BE_IN_CHILD_ENVNr   r   r   r   r   r   r   r   r   r   r    r!   expectEOF)r"   r%   r&   r'   supervisorctls        r(   test_issue_550zEndToEndTests.test_issue_550'   s     !228=VW.h?mmCNND7K((&--8  !KL  !NO0$.R]^cnndWM**FMM:""#@AW[[)    c                 
   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       ddd|d	d
dg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         t        dd      D ]  }d|z  }|j                  |d        y)zeWhen a log file has Unicode characters in it, 'supervisorctl
        tail -f name' should still work.zfixtures/issue-565.confr   r   r   r   r   $success: hello entered RUNNING stater+   tail-fhello      u'   The Øresund bridge ends in Malmö - %d   timeoutNr   r   r   r   r   r   r   r   r   r   r    r!   ranger"   r%   r&   r'   r0   ilines          r(   test_issue_565zEndToEndTests.test_issue_5657   s     !228=VW.h?mmCNND7K((&--8  !GH0$&$PWXcnndWM**FMM:q! 	9A<q@D&&tR&8	9r2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         t
        j                  d   dk  }|rd	}nd
}|j                  d|z  d       |j                  dd       |r|j                  dd       yy)zWhen a process outputs something on its stdout or stderr file
        descriptor that is not valid UTF-8, supervisord should not crash.zfixtures/issue-638.confr   r   r   r   r   r       bzUndecodable: %s'\x88\n'r:   r;   z)received SIGCH?LD indicating a child quitzVgave up: produce-unicode-error entered FATAL state, too many start retries too quickly<   N)r   r   r   r   r   r   r   r   r   r   r    version_infor!   r.   )r"   r%   r&   r'   is_py2b_prefixs         r(   test_issue_638zEndToEndTests.test_issue_638H   s     !228=VW.h?mmCNND7K((&--8!!!$q(HH  !;h!FPR SFPRS$$ &JSU % W r2   c                 P   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         t        d      D ](  }|j                  dd	
       |j                  dd
       * y)zSWhen Supervisor is run on Python 3, the eventlistener protocol
        should work.zfixtures/issue-663.confr   r   r   r   r      OKREADYrG   r;   zBUSY -> ACKNOWLEDGEDr:   N)r   r   r   r   r   r   r   r   r   r   r    r>   r!   )r"   r%   r&   r'   r@   s        r(   test_issue_663zEndToEndTests.test_issue_663[   s     !228=VW.h?mmCNND7K((&--8q 	IA$$Y$;$$%;R$H	Ir2   c                 <   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  dd	       dd
d|dg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         	 |j                  dd	       d}| j                  |       y# t        j                  $ r d}Y )w xY w)zWhen a subprocess name has Unicode characters, 'supervisord'
        should not send incomplete XML-RPC responses and 'supervisorctl
        status' should work.zfixtures/issue-664.confr   r   r   r   r   u!   test_öäü entered RUNNING staterG   r;   r+   statusu   test_öäü\s+RUNNINGr:   TFNr   r   r   r   r   r   r   r   r   r   r    r!   r.   ExceptionPexpect
assertTruer"   r%   r&   r'   r0   seens         r(   test_issue_664zEndToEndTests.test_issue_664f   s     !228=VW.h?mmCNND7K((&--8  !Db Q0$(KcnndWM**FMM:	  !92 FD 	 '' 	D	s   D DDc                 f   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       |j                  d       |j                  t        j                         y	)
zzWhen a subprocess enters the FATAL state, a one-line eventlistener
        can be used to signal supervisord to shut down.zfixtures/issue-733.confr   r   r   r   r   z(gave up: nonexistent entered FATAL statez(received SIGTERM indicating exit requestNr-   r"   r%   r&   r'   s       r(   test_issue_733zEndToEndTests.test_issue_733z   s     !228=VW.h?mmCNND7K((&--8  !KL  !KL7;;'r2   c                 T   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  dd	       t        d
d
d      }t        j                  d|      }	 dD ]B  }|j                  j!                  d|      }| j#                  |       |j                  |d	       D 	 |j$                  j'                          y # |j$                  j'                          w xY w)Nzfixtures/issue-835.confr   r   r   r   r   cat entered RUNNING staterG   r;   rE   zunix:///tmp/issue-835.sockzhttp://anything/RPC2)"   The Øresund bridge ends in Malmör7   catr:   )r   r   r   r   r   r   r   r   r   r   r    r!   r   r   ServerProxy
supervisorsendProcessStdinrT   
connectionclose)r"   r%   r&   r'   	transportserversresults           r(   test_issue_835zEndToEndTests.test_issue_835   s     228=VW.h?mmCNND7K((&--8  !<b I'B0LM	&&'=yI	)D 8**;;E1E'((B(78
   &&(I  &&(s   (AD D'c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  dd	       dd
d|ddg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         	 dD ]H  }|j                  |       |j                  |d	       |j                  |       |j                  |       J d}| j                  |       y # t        j                  $ r d}Y )w xY w)Nzfixtures/issue-836.confr   r   r   r   r   r\   rG   r;   r+   fgr^   )HiHellor]   TF)r   r   r   r   r   r   r   r   r   r   r    r!   sendlinerS   rT   )r"   r%   r&   r'   r0   rf   rV   s          r(   test_issue_836zEndToEndTests.test_issue_836   s)    228=VW.h?mmCNND7K((&--8  !<b I0$$NcnndWM**FMM:	J .&&q)((B(7**1-**1-	.
 D 	 '' 	D	s   AD> >EEc                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       y)	zyA percent sign can be used in a command= string without being
        expanded if it is escaped by a second percent sign.zfixtures/issue-986.confr   r   r   r   r   z2dhcrelay -d -q -a %h:%p %P -i Vlan1000 192.168.0.1Nr   r   r   r   r   r   r   r   r   r   r    r!   rY   s       r(   1test_issue_986_command_string_with_double_percentz?EndToEndTests.test_issue_986_command_string_with_double_percent   sc     !228=VW.h?mmCNND7K((&--8  !UVr2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  dd	       dd
d|dg}t        j                  t
        j                  |d      }	 |j                  dd	       d}| j                  |       y# t        j                  $ r d}Y )w xY w)zLWhen run on Python 3, the 'supervisorctl avail' command
        should work.zfixtures/issue-1054.confr   r   r   r   r   r\   rG   r;   r+   availzcat\s+in use\s+autor:   TFNrR   rU   s         r(   test_issue_1054zEndToEndTests.test_issue_1054   s     !228=WX.h?mmCNND7K((&--8  !<b I0$'JcnndWM	  !8" ED 	 '' 	D	s   2C C10C1c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       y)	zWhen the [supervisord] section has a variable defined in
        environment=, that variable should be able to be used in an
        %(ENV_x) expansion in a [program] section.zfixtures/issue-1170a.confr   r   r   r   r   zset from [supervisord] sectionNrp   rY   s       r(   test_issue_1170azEndToEndTests.test_issue_1170a   sc     !228=XY.h?mmCNND7K((&--8  !ABr2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       y)	zWhen the [supervisord] section has a variable defined in
        environment=, and a variable by the same name is defined in
        enviroment= of a [program] section, the one in the [program]
        section should be used.zfixtures/issue-1170b.confr   r   r   r   r   zset from [program] sectionNrp   rY   s       r(   test_issue_1170bzEndToEndTests.test_issue_1170b   sc    
 !228=XY.h?mmCNND7K((&--8  !=>r2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       y)	zWhen the [supervisord] section has a variable defined in
        environment=, and a variable by the same name is defined in
        enviroment= of an [eventlistener] section, the one in the
        [eventlistener] section should be used.zfixtures/issue-1170c.confr   r   r   r   r   z set from [eventlistener] sectionNrp   rY   s       r(   test_issue_1170czEndToEndTests.test_issue_1170c   sc    
 !228=XY.h?mmCNND7K((&--8  !CDr2   c                 
   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  dd	       y
)zWhen the main log file does not need rotation (logfile_maxbyte=0)
        then the non-rotating logger will be used to avoid an
        IllegalSeekError in the case that the user has configured a
        non-seekable file like /dev/stdout.zfixtures/issue-1224.confr   r   r   r   r   r\   rG   r;   Nrp   rY   s       r(   test_issue_1224zEndToEndTests.test_issue_1224   sh    
 !228=WX.h?mmCNND7K((&--8  !<b Ir2   c                 
   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       ddd|d	d
dg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         t        dd      D ]  }d|z  }|j                  |d        y)bWhen 'supervisorctl tail -f name' is run and the log contains
        unicode, it should not fail.zfixtures/issue-1231a.confr   r   r   r   r   r4   r+   r5   r6   r7   r8   r9      %d - hash=57d94b…381088r:   r;   Nr=   r?   s          r(   test_issue_1231azEndToEndTests.test_issue_1231a   s     !228=XY.h?mmCNND7K((&--8  !GH0$&$PWXcnndWM**FMM:q! 	9A.2D&&tR&8	9r2   c                 L   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       ddd|d	d
dg}t        j                  j                         }d|d<   t        j                  t
        j                  |d|      }| j                  |j                  t        j                         t
        j                  dd dk  r&|j!                  dd       |j!                  dd       t#        dd      D ]  }d|z  }	 |j                  |d        y# t        j$                  j&                  $ r  | j)                  d|j*                         Y  yw xY w)r~   zfixtures/issue-1231b.confr   r   r   r   r   r4   r+   r5   r6   r7   oopsLANGr   envNrM   rD      'Warning: sys.stdout.encoding is set to r:   r;   Unicode output may fail.r8   r9   r   z:Unable to write Unicode to stdout because it has encoding )r   r   r   r   r   r   r   r   r   r   r    r!   r   r   copyrH   r.   r>   
exceptionsr/   assertInbefore)r"   r%   r&   r'   r   r0   r@   rA   s           r(   test_issue_1231bzEndToEndTests.test_issue_1231b   s|    !228=XY.h?mmCNND7K((&--8  !GH0$&$PWXjjooFcnndW*-/**FMM:
 BQ&(  !J)+ ! -  !;R Hq! 	A.2D**4*<	 %%))  .+224 	s   E&&9F#"F#c                 x   t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       ddd|d	d
g}t        j                  j                         }d|d<   t        j                  t
        j                  |d|      }| j                  |j                  t        j                         t
        j                  dd dk  r'|j!                  dd       |j!                  dd       yy)r~   zfixtures/issue-1231c.confr   r   r   r   r   r4   r+   r5   r7   r   r   r   NrM   r   r   r:   r;   r   )r   r   r   r   r   r   r   r   r   r   r    r!   r   r   r   rH   r.   )r"   r%   r&   r'   r   r0   s         r(   test_issue_1231czEndToEndTests.test_issue_1231c"  s    !228=XY.h?mmCNND7K((&--8  !GH0$&'RjjooFcnndW*-/**FMM:
 BQ&(  !J)+ ! -  !;R H )r2   c                 X   g d}t        j                  t        j                  |d      }| j	                  |j
                  t        j                         |j                  d       |j                  d       |j                  t         j                         g d}t        j                  t        j                  |d      }| j	                  |j
                  t        j                         |j                  d       |j                  d       |j                  t         j                         y	)
z`When -? is given to supervisord or supervisorctl, help should be
        displayed like -h does.)r   r   -?r   r   z(supervisord -- run a set of applicationsz(-l/--logfile FILENAME -- use FILENAME as)r   r+   r   z%supervisorctl -- control applicationsz(-i/--interactive -- start an interactiveN)r   r   r   r   r   r   r   r    r!   r.   r/   )r"   r&   r'   r0   s       r(   test_issue_1251zEndToEndTests.test_issue_1251:  s     6mmCNND7K((&--8  !KL  !KL7;;'7cnndWM**FMM:""#JK""#MNW[[)r2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       dt
        j                  d	|d
}t        j                  dd|gd      }| j                  |j                  t        j                         |j                  dd       y)zWhen the output of 'supervisorctl tail -f worker' is piped such as
        'supervisor tail -f worker | grep something', 'supervisorctl' should
        not crash.zfixtures/issue-1298.confr   r   r   r   r   z#success: spew entered RUNNING state'z"' -m supervisor.supervisorctl -c 'z' tail -f spew | /bin/cat -uz/bin/shz	spewage 2r:   r;   N)r   r   r   r   r   r   r   r   r   r   r    r!   r.   )r"   r%   r&   r'   cmdbashs         r(   test_issue_1298zEndToEndTests.test_issue_1298K  s     !228=WX.h?mmCNND7K((&--8  !FG NNH }}YsgF		6==1K,r2   c                 >   g d}t        j                  t        j                  |d      }| j	                  |j
                  t        j                         |j                  t         j                         | j                  |j                  j                         d       y)z\When pidproxy is given a command to run that has no arguments, it
        runs that command.)r   supervisor.pidproxynonexistent-pidfile	/bin/echor   r   rE   Nr   r   r   r   r   r   r   r    r.   r/   assertEqualr   stripr"   r&   pidproxys      r(   )test_issue_1418_pidproxy_cmd_with_no_argsz7EndToEndTests.test_issue_1418_pidproxy_cmd_with_no_args\  sc     Q==Hv}}5$..0"5r2   c                 >   g d}t        j                  t        j                  |d      }| j	                  |j
                  t        j                         |j                  t         j                         | j                  |j                  j                         d       y)zYWhen pidproxy is given a command to run that has arguments, it
        runs that command.)r   r   r   r   12r   r   z1 2Nr   r   s      r(   &test_issue_1418_pidproxy_cmd_with_argsz4EndToEndTests.test_issue_1418_pidproxy_cmd_with_argse  sc     [==Hv}}5$..0%8r2   c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       dd	lm} dd
lm}  |ddd      }	  |j                   d|      }|j"                  j%                         }|j'                          | j)                  |d       y# |j'                          w xY w)zfWhen no identifier is supplied on the command line or in the config
        file, the default is used.zfixtures/issue-1483a.confr   r   r   r   r   supervisord started with pidr   r   r   rE   zunix:///tmp/issue-1483a.sock"http://transport.ignores.host/RPC2r`   Nr   r   r   r   r   r   r   r   r   r   r    r!   supervisor.compatr   supervisor.xmlrpcr   r_   r`   getIdentificationrc   r   	r"   r%   r&   r'   r   r   rd   re   idents	            r(   #test_issue_1483a_identifier_defaultz1EndToEndTests.test_issue_1483a_identifier_defaultn  s     !228=XY.h?mmCNND7K((&--8  !?@/9'B0NO		*Y**+OQZ[F%%779EOO- OO   -C) )C;c                    t        j                  t        d      }ddd|g}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d       dd	lm} dd
lm}  |ddd      }	  |j                   d|      }|j"                  j%                         }|j'                          | j)                  |d       y# |j'                          w xY w)zpWhen the identifier is supplied in the config file only, that
        identifier is used instead of the default.zfixtures/issue-1483b.confr   r   r   r   r   r   r   r   r   rE   zunix:///tmp/issue-1483b.sockr   from_config_fileNr   r   s	            r(   ,test_issue_1483b_identifier_from_config_filez:EndToEndTests.test_issue_1483b_identifier_from_config_file  s     !228=XY.h?mmCNND7K((&--8  !?@/9'B0NO		*Y**+OQZ[F%%779EOO 23 OOr   c                     t        j                  t        d      }ddd|ddg}t        j                  t
        j                  |d      }| j                  |j                  t        j                         |j                  d	       d
dlm} d
dlm}  |ddd      }	  |j                   d|      }|j"                  j%                         }|j'                          | j)                  |d       y# |j'                          w xY w)z~When an identifier is supplied in both the config file and on the
        command line, the one from the command line is used.zfixtures/issue-1483c.confr   r   r   z-ifrom_command_liner   r   r   r   r   r   rE   zunix:///tmp/issue-1483c.sockr   Nr   r   s	            r(   -test_issue_1483c_identifier_from_command_linez;EndToEndTests.test_issue_1483c_identifier_from_command_line  s     !228=XY.hFYZmmCNND7K((&--8  !?@/9'B0NO		*Y**+OQZ[F%%779EOO 34 OOs   -C+ +C=N)r   
__module____qualname__r)   r1   rB   rK   rO   rW   rZ   rh   rn   rq   rt   rv   rx   rz   r|   r   r   r   r   r   r   r   r   r   r    r2   r(   r
   r
      s      * 9"W&	I(	() *W"C	?	E	J9" DI0*"-"69.&4&5r2   r
   c                  V    t        j                  t        j                  t                 S )N)unittestfindTestCasesr   modulesr   r   r2   r(   
test_suiter     s    !!#++h"788r2   __main__r   )defaultTest)
__future__r   r   r   r   r   r   r   r   r   r   r   r   TestCaseBaseTestCaseobjectr
   r   r   mainr   r2   r(   <module>r      so    ' 	  
   ' 1 2::$$LLP5L P5d9 zHMMl+ r2   