<s> import os <EOL> from fabric . api import * <EOL> from fabric . contrib . files import uncomment , exists , comment , contains , append , sed <EOL> from fabric . state import connections , env <EOL> from fabric . network import join_host_strings , normalize <EOL> from woven . linux import disable_root , change_ssh_port , port_is_open , setup_ufw <EOL> from woven . linux import setup_ufw_rules <EOL> from woven . linux import uninstall_packages <EOL> from woven . linux import add_repositories <EOL> from woven . environment import server_state , set_server_state <EOL> H = '<STR_LIT>' <EOL> HS = '<STR_LIT>' <EOL> R = '<STR_LIT>' <EOL> def test_lin_add_repositories ( ) : <EOL> add_repositories ( ) <EOL> def teardown_disable_root ( ) : <EOL> local ( '<STR_LIT>' ) <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT>' , password = '<STR_LIT>' ) : <EOL> run ( '<STR_LIT>' % ( '<STR_LIT:root>' , '<STR_LIT:root>' ) ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> print "<STR_LIT>" % env . host_string <EOL> connections [ env . host_string ] . close ( ) <EOL> try : <EOL> connections [ '<STR_LIT>' ] . close ( ) <EOL> except : pass <EOL> original_username = '<STR_LIT>' <EOL> ( olduser , host , port ) = normalize ( env . host_string ) <EOL> host_string = join_host_strings ( '<STR_LIT:root>' , host , '<STR_LIT>' ) <EOL> with settings ( host_string = host_string , password = '<STR_LIT:root>' ) : <EOL> sudo ( '<STR_LIT>' + original_username ) <EOL> def test_lin_disable_root ( ) : <EOL> env . DISABLE_ROOT = True <EOL> env . INTERACTIVE = False <EOL> env . HOST_PASSWORD = '<STR_LIT>' <EOL> env . ROOT_PASSWORD = '<STR_LIT:root>' <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT>' , password = '<STR_LIT>' ) : <EOL> disable_root ( ) <EOL> assert exists ( '<STR_LIT>' ) <EOL> def test_lin_change_ssh_port ( ) : <EOL> env . ROOT_PASSWORD = '<STR_LIT:root>' <EOL> host_state_dir = os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> host_state_path = os . path . join ( host_state_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( host_state_dir ) : <EOL> os . mkdir ( host_state_dir ) <EOL> open ( host_state_path , '<STR_LIT:w>' ) . close ( ) <EOL> print "<STR_LIT>" <EOL> with settings ( user = '<STR_LIT:root>' , password = env . ROOT_PASSWORD ) : <EOL> change_ssh_port ( ) <EOL> print "<STR_LIT>" <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT:root>' , password = env . ROOT_PASSWORD ) : <EOL> try : <EOL> run ( '<STR_LIT>' ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> return <EOL> print '<STR_LIT>' <EOL> with settings ( user = '<STR_LIT:root>' , password = env . ROOT_PASSWORD ) : <EOL> result = change_ssh_port ( ) <EOL> print result <EOL> assert result <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT:root>' , password = env . ROOT_PASSWORD ) : <EOL> sed ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , use_sudo = True ) <EOL> sudo ( '<STR_LIT>' ) <EOL> local ( '<STR_LIT>' ) <EOL> return <EOL> def test_lin_port_is_open ( ) : <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT:root>' , password = env . ROOT_PASSWORD ) : <EOL> result = port_is_open ( ) <EOL> assert result <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> result = port_is_open ( ) <EOL> sudo ( '<STR_LIT>' ) <EOL> def test_lin_setup_ufw_rules ( ) : <EOL> UFW_RULES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> with settings ( packages = p , UFW_RULES = UFW_RULES , host_string = HS , user = R , password = R ) : <EOL> setup_ufw_rules ( ) <EOL> def test_lin_setup_ufw ( ) : <EOL> with settings ( host_string = '<STR_LIT>' , user = '<STR_LIT:root>' , password = '<STR_LIT:root>' ) : <EOL> env . HOST_SSH_PORT = '<STR_LIT>' <EOL> setup_ufw ( ) <EOL> r = sudo ( '<STR_LIT>' ) . strip ( ) <EOL> assert '<STR_LIT>' in r <EOL> assert '<STR_LIT>' in r <EOL> with settings ( warn_only = True ) : <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> apt_get_purge ( '<STR_LIT>' ) <EOL> set_server_state ( '<STR_LIT>' , delete = True ) <EOL> print "<STR_LIT>" <EOL> env . HOST_SSH_PORT = '<STR_LIT>' <EOL> setup_ufw ( ) <EOL> r = sudo ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in r <EOL> assert '<STR_LIT>' in r <EOL> env . UFW_RULES = [ '<STR_LIT>' ] <EOL> setup_ufw ( ) <EOL> r = sudo ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in r <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> apt_get_purge ( '<STR_LIT>' ) <EOL> set_server_state ( '<STR_LIT>' , delete = True ) <EOL> def test_lin_uninstall_packages ( ) : <EOL> uninstall_packages ( ) </s>
