#NEWLINE# def writeConfigAndValidate( config , config_file ) : #NEWLINE# #INDENT# if args . dry : #NEWLINE# #INDENT# print ( config ) #NEWLINE# sys . exit ( ) #NEWLINE# #UNINDENT# ( fd , haproxyTempConfigFile ) = mkstemp ( ) #NEWLINE# logger . debug ( 'writing config to temp file %s' , haproxyTempConfigFile ) #NEWLINE# with os . fdopen ( fd , 'w' ) as haproxyTempConfig : #NEWLINE# #INDENT# haproxyTempConfig . write ( config ) #NEWLINE# #UNINDENT# perms = 420 #NEWLINE# if os . path . isfile ( config_file ) : #NEWLINE# #INDENT# perms = stat . S_IMODE ( os . lstat ( config_file ) . st_mode ) #NEWLINE# #UNINDENT# os . chmod ( haproxyTempConfigFile , perms ) #NEWLINE# if args . skip_validation : #NEWLINE# #INDENT# logger . debug ( 'skipping validation. moving temp file %s to %s' , haproxyTempConfigFile , config_file ) #NEWLINE# move ( haproxyTempConfigFile , config_file ) #NEWLINE# return True #NEWLINE# #UNINDENT# cmd = [ 'haproxy' , '-f' , haproxyTempConfigFile , '-c' ] #NEWLINE# logger . debug ( ( 'checking config with command: ' + str ( cmd ) ) ) #NEWLINE# returncode = subprocess . call ( args = cmd ) #NEWLINE# if ( returncode == 0 ) : #NEWLINE# #INDENT# logger . debug ( 'moving temp file %s to %s' , haproxyTempConfigFile , config_file ) #NEWLINE# move ( haproxyTempConfigFile , config_file ) #NEWLINE# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . error ( 'haproxy returned non-zero when checking config' ) #NEWLINE# return False