#NEWLINE# def fetch_bootstrap( bootstrap_id ) : #NEWLINE# #INDENT# copy_set = [ '{}.bootstrap.tar.xz' . format ( bootstrap_id ) , '{}.active.json' . format ( bootstrap_id ) ] #NEWLINE# dest_dir = '/genconf/serve/bootstrap/' #NEWLINE# container_cache_dir = '/artifacts/' #NEWLINE# dest_files = [ ( dest_dir + filename ) for filename in copy_set ] #NEWLINE# if all ( map ( os . path . exists , dest_files ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# src_files = [ ( container_cache_dir + filename ) for filename in copy_set ] #NEWLINE# for filename in src_files : #NEWLINE# #INDENT# if ( not os . path . exists ( filename ) ) : #NEWLINE# #INDENT# log . error ( 'Internal Error: %s not found. Should have been in the installer container.' , filename ) #NEWLINE# raise FileNotFoundError ( ) #NEWLINE# #UNINDENT# #UNINDENT# def cleanup_and_exit( ) : #NEWLINE# #INDENT# for filename in dest_files : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . remove ( filename ) #NEWLINE# #UNINDENT# except OSError as ex : #NEWLINE# #INDENT# log . error ( 'Internal error removing temporary file. Might have corrupted file %s: %s' , filename , ex . strerror ) #NEWLINE# #UNINDENT# #UNINDENT# sys . exit ( 1 ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# subprocess . check_output ( [ 'mkdir' , '-p' , '/genconf/serve/bootstrap/' ] ) #NEWLINE# for filename in copy_set : #NEWLINE# #INDENT# subprocess . check_output ( [ 'cp' , ( container_cache_dir + filename ) , ( dest_dir + filename ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# except subprocess . CalledProcessError as ex : #NEWLINE# #INDENT# log . error ( 'Copy failed: %s\nOutput:\n%s' , ex . cmd , ex . output ) #NEWLINE# log . error ( 'Removing partial artifacts' ) #NEWLINE# cleanup_and_exit ( ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# log . error ( 'Copy out of installer interrupted. Removing partial files.' ) #NEWLINE# cleanup_and_exit ( )