<s> import os <EOL> import tarfile <EOL> import zipfile <EOL> import unittest <EOL> import zopkio . constants as constants <EOL> import zopkio . adhoc_deployer as adhoc_deployer <EOL> class TestAdhocDeployer ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> test_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> executable = os . path . join ( test_dir , "<STR_LIT>" ) <EOL> install_path = "<STR_LIT>" <EOL> start_cmd = "<STR_LIT>" <EOL> files_to_clean = [ "<STR_LIT>" ] <EOL> self . trivial_deployer = adhoc_deployer . SSHDeployer ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : executable , <EOL> '<STR_LIT>' : install_path , <EOL> '<STR_LIT>' : start_cmd , <EOL> '<STR_LIT>' : files_to_clean , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' . format ( install_path ) <EOL> ] } ) <EOL> def test_ssh_deployer_install_uninstall ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trivial_deployer . install ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertTrue ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> self . trivial_deployer . uninstall ( "<STR_LIT>" ) <EOL> self . assertFalse ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> def test_ssh_deployer_start_stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trivial_deployer . install ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertTrue ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> self . trivial_deployer . start ( "<STR_LIT>" ) <EOL> self . assertNotEqual ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> self . trivial_deployer . stop ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> self . trivial_deployer . uninstall ( "<STR_LIT>" ) <EOL> self . assertFalse ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> def test_ssh_deployer_deploy_undeploy ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trivial_deployer . deploy ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertTrue ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> self . assertNotEqual ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> self . trivial_deployer . undeploy ( "<STR_LIT>" ) <EOL> self . assertFalse ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> def test_ssh_deployer_get_log ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trivial_deployer . deploy ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertTrue ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . isfile ( "<STR_LIT>" ) ) <EOL> self . assertNotEqual ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> if not os . path . isdir ( "<STR_LIT>" ) : <EOL> os . makedirs ( "<STR_LIT>" ) <EOL> self . trivial_deployer . get_logs ( "<STR_LIT>" , [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" ) <EOL> self . trivial_deployer . stop ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( <EOL> self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> if not os . path . isdir ( "<STR_LIT>" ) : <EOL> os . makedirs ( "<STR_LIT>" ) <EOL> self . trivial_deployer . get_logs ( "<STR_LIT>" , [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" ) <EOL> self . trivial_deployer . uninstall ( "<STR_LIT>" ) <EOL> self . assertFalse ( os . path . isdir ( "<STR_LIT>" ) ) <EOL> def test_ssh_deployer_get_pid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trivial_deployer . deploy ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> pids = self . trivial_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert len ( pids ) > <NUM_LIT:0> <EOL> pid_file = "<STR_LIT>" <EOL> with open ( pid_file , '<STR_LIT:w>' ) as f : <EOL> file_str = '<STR_LIT:\n>' . join ( [ str ( pid ) for pid in pids ] ) <EOL> f . write ( file_str ) <EOL> assert pids == self . trivial_deployer . get_pid ( "<STR_LIT>" , { '<STR_LIT>' : pid_file } ) <EOL> self . trivial_deployer . undeploy ( "<STR_LIT>" ) <EOL> assert self . trivial_deployer . get_pid ( "<STR_LIT>" , { '<STR_LIT>' : '<STR_LIT>' } ) == constants . PROCESS_NOT_RUNNING_PID <EOL> os . remove ( pid_file ) <EOL> self . trivial_deployer . undeploy ( "<STR_LIT>" ) <EOL> def test_tar_executable ( self ) : <EOL> test_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> executable = os . path . join ( test_dir , "<STR_LIT>" ) <EOL> tar = tarfile . open ( executable , "<STR_LIT:w>" ) <EOL> try : <EOL> tar . add ( os . path . join ( test_dir , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> finally : <EOL> tar . close ( ) <EOL> install_path = "<STR_LIT>" <EOL> start_cmd = "<STR_LIT>" <EOL> files_to_clean = [ "<STR_LIT>" ] <EOL> tar_deployer = adhoc_deployer . SSHDeployer ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : executable , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : install_path , <EOL> '<STR_LIT>' : start_cmd , <EOL> '<STR_LIT>' : files_to_clean } ) <EOL> tar_deployer . deploy ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertNotEqual ( <EOL> tar_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> tar_deployer . undeploy ( "<STR_LIT>" , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> os . remove ( executable ) <EOL> def test_zip_executable ( self ) : <EOL> test_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> executable = os . path . join ( test_dir , "<STR_LIT>" ) <EOL> zf = zipfile . ZipFile ( executable , "<STR_LIT:w>" ) <EOL> try : <EOL> zf . write ( os . path . join ( test_dir , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> zipfile . ZIP_DEFLATED ) <EOL> finally : <EOL> zf . close ( ) <EOL> install_path = "<STR_LIT>" <EOL> start_cmd = "<STR_LIT>" <EOL> files_to_clean = [ "<STR_LIT>" ] <EOL> zip_deployer = adhoc_deployer . SSHDeployer ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : executable , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : install_path , <EOL> '<STR_LIT>' : start_cmd , <EOL> '<STR_LIT>' : files_to_clean } ) <EOL> zip_deployer . deploy ( "<STR_LIT>" , { '<STR_LIT>' : "<STR_LIT:localhost>" } ) <EOL> self . assertNotEqual ( <EOL> zip_deployer . get_pid ( "<STR_LIT>" , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> constants . PROCESS_NOT_RUNNING_PID ) <EOL> zip_deployer . undeploy ( "<STR_LIT>" , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> os . remove ( executable ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
