#NEWLINE# @ destructiveTest #NEWLINE# @ skipIf ( ( os . geteuid ( ) != 0 ) , 'you must be root to run this test' ) #NEWLINE# @ with_system_user ( 'issue-6912' , on_existing = 'delete' , delete = True ) #NEWLINE# def test_issue_6912_wrong_owner( self , username ) : #NEWLINE# #INDENT# venv_dir = os . path . join ( integration . SYS_TMP_DIR , '6912-wrong-owner' ) #NEWLINE# venv_create = self . run_function ( 'virtualenv.create' , [ venv_dir ] , user = username ) #NEWLINE# if ( venv_create [ 'retcode' ] > 0 ) : #NEWLINE# #INDENT# self . skipTest ( 'Failed to create testcase virtual environment: {0}' . format ( venv_create ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret = self . run_state ( 'pip.installed' , name = 'pep8' , user = username , bin_env = venv_dir ) #NEWLINE# self . assertSaltTrueReturn ( ret ) #NEWLINE# uinfo = pwd . getpwnam ( username ) #NEWLINE# for globmatch in ( os . path . join ( venv_dir , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '*' , '**' , 'pep8*' ) ) : #NEWLINE# #INDENT# for path in glob . glob ( globmatch ) : #NEWLINE# #INDENT# self . assertEqual ( uinfo . pw_uid , os . stat ( path ) . st_uid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if os . path . isdir ( venv_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( venv_dir ) #NEWLINE# #UNINDENT# #UNINDENT# venv_create = self . run_function ( 'virtualenv.create' , [ venv_dir ] , user = username ) #NEWLINE# if ( venv_create [ 'retcode' ] > 0 ) : #NEWLINE# #INDENT# self . skipTest ( 'Failed to create testcase virtual environment: {0}' . format ( ret ) ) #NEWLINE# #UNINDENT# req_filename = os . path . join ( integration . TMP_STATE_TREE , 'issue-6912-requirements.txt' ) #NEWLINE# with salt . utils . fopen ( req_filename , 'wb' ) as reqf : #NEWLINE# #INDENT# reqf . write ( 'pep8' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret = self . run_state ( 'pip.installed' , name = '' , user = username , bin_env = venv_dir , requirements = 'salt://issue-6912-requirements.txt' ) #NEWLINE# self . assertSaltTrueReturn ( ret ) #NEWLINE# uinfo = pwd . getpwnam ( username ) #NEWLINE# for globmatch in ( os . path . join ( venv_dir , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '*' , '**' , 'pep8*' ) ) : #NEWLINE# #INDENT# for path in glob . glob ( globmatch ) : #NEWLINE# #INDENT# self . assertEqual ( uinfo . pw_uid , os . stat ( path ) . st_uid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if os . path . isdir ( venv_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( venv_dir ) #NEWLINE# #UNINDENT# os . unlink ( req_filename ) #NEWLINE# #UNINDENT# venv_create = self . run_function ( 'virtualenv.create' , [ venv_dir ] , user = username ) #NEWLINE# if ( venv_create [ 'retcode' ] > 0 ) : #NEWLINE# #INDENT# self . skipTest ( 'Failed to create testcase virtual environment: {0}' . format ( ret ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret = self . run_state ( 'pip.installed' , name = 'pep8' , user = username , bin_env = venv_dir ) #NEWLINE# self . assertSaltTrueReturn ( ret ) #NEWLINE# uinfo = pwd . getpwnam ( username ) #NEWLINE# for globmatch in ( os . path . join ( venv_dir , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '*' , '**' , 'pep8*' ) ) : #NEWLINE# #INDENT# for path in glob . glob ( globmatch ) : #NEWLINE# #INDENT# self . assertEqual ( uinfo . pw_uid , os . stat ( path ) . st_uid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if os . path . isdir ( venv_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( venv_dir ) #NEWLINE# #UNINDENT# #UNINDENT# venv_create = self . run_function ( 'virtualenv.create' , [ venv_dir ] , user = username ) #NEWLINE# if ( venv_create [ 'retcode' ] > 0 ) : #NEWLINE# #INDENT# self . skipTest ( 'Failed to create testcase virtual environment: {0}' . format ( ret ) ) #NEWLINE# #UNINDENT# req_filename = os . path . join ( integration . TMP_STATE_TREE , 'issue-6912-requirements.txt' ) #NEWLINE# with salt . utils . fopen ( req_filename , 'wb' ) as reqf : #NEWLINE# #INDENT# reqf . write ( 'pep8' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret = self . run_state ( 'pip.installed' , name = '' , user = username , bin_env = venv_dir , requirements = 'salt://issue-6912-requirements.txt' ) #NEWLINE# self . assertSaltTrueReturn ( ret ) #NEWLINE# uinfo = pwd . getpwnam ( username ) #NEWLINE# for globmatch in ( os . path . join ( venv_dir , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '**' , 'pep8*' ) , os . path . join ( venv_dir , '*' , '*' , '**' , 'pep8*' ) ) : #NEWLINE# #INDENT# for path in glob . glob ( globmatch ) : #NEWLINE# #INDENT# self . assertEqual ( uinfo . pw_uid , os . stat ( path ) . st_uid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if os . path . isdir ( venv_dir ) : #NEWLINE# #INDENT# shutil . rmtree ( venv_dir ) #NEWLINE# #UNINDENT# os . unlink ( req_filename )