#NEWLINE# @ scenario . configure ( context = { #NEWLINE# #INDENT# 'cleanup' : [ 'nova' , 'heat' ] , #NEWLINE# 'keypair' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'network' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# def runcommand_heat( self , workload , template , files , parameters ) : #NEWLINE# #INDENT# 'Run workload on stack deployed by heat.\n\n        Workload can be either file or resource:\n\n        .. code-block: json\n\n            {"file": "/path/to/file.sh"}\n            {"resource": ["package.module", "workload.py"]}\n\n        Also it should contain "username" key.\n\n        Given file will be uploaded to `gate_node` and started. This script\n        should print `key` `value` pairs separated by colon. These pairs will\n        be presented in results.\n\n        Gate node should be accessible via ssh with keypair `key_name`, so\n        heat template should accept parameter `key_name`.\n\n        :param workload: workload to run\n        :param template: path to heat template file\n        :param files: additional template files\n        :param parameters: parameters for heat template\n        ' #NEWLINE# keypair = self . context [ 'user' ] [ 'keypair' ] #NEWLINE# parameters [ 'key_name' ] = keypair [ 'name' ] #NEWLINE# network = self . context [ 'tenant' ] [ 'networks' ] [ 0 ] #NEWLINE# parameters [ 'router_id' ] = network [ 'router_id' ] #NEWLINE# self . stack = heat . main . Stack ( self , self . task , template , files = files , parameters = parameters ) #NEWLINE# self . stack . create ( ) #NEWLINE# for output in self . stack . stack . outputs : #NEWLINE# #INDENT# if ( output [ 'output_key' ] == 'gate_node' ) : #NEWLINE# #INDENT# ip = output [ 'output_value' ] #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# ssh = sshutils . SSH ( workload [ 'username' ] , ip , pkey = keypair [ 'private' ] ) #NEWLINE# ssh . wait ( ) #NEWLINE# script = workload . get ( 'resource' ) #NEWLINE# if script : #NEWLINE# #INDENT# script = pkgutil . get_data ( * script ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# script = open ( workload [ 'file' ] ) . read ( ) #NEWLINE# #UNINDENT# ssh . execute ( 'cat > /tmp/.rally-workload' , stdin = script ) #NEWLINE# ssh . execute ( 'chmod +x /tmp/.rally-workload' ) #NEWLINE# with atomic . ActionTimer ( self , 'runcommand_heat.workload' ) : #NEWLINE# #INDENT# ( status , out , err ) = ssh . execute ( '/tmp/.rally-workload' , stdin = json . dumps ( self . stack . stack . outputs ) ) #NEWLINE# #UNINDENT# rows = [ ] #NEWLINE# for line in out . splitlines ( ) : #NEWLINE# #INDENT# row = line . split ( ':' ) #NEWLINE# if ( len ( row ) != 2 ) : #NEWLINE# #INDENT# raise exceptions . ScriptError ( ( "Invalid data '%s'" % line ) ) #NEWLINE# #UNINDENT# rows . append ( row ) #NEWLINE# #UNINDENT# if ( not rows ) : #NEWLINE# #INDENT# raise exceptions . ScriptError ( ( 'No data returned. Original error message is %s' % err ) ) #NEWLINE# #UNINDENT# self . add_output ( complete = { #NEWLINE# #INDENT# 'title' : 'Workload summary' , #NEWLINE# 'description' : 'Data generated by workload' , #NEWLINE# 'chart_plugin' : 'Table' , #NEWLINE# 'data' : { #NEWLINE# #INDENT# 'cols' : [ 'key' , 'value' ] , #NEWLINE# 'rows' : self , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } )