<s> import time <EOL> from oslo_config import cfg <EOL> import requests <EOL> from rally . common import logging <EOL> from rally import exceptions <EOL> from rally . plugins . openstack import scenario <EOL> from rally . task import atomic <EOL> from rally . task import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> HEAT_BENCHMARK_OPTS = [ <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . FloatOpt ( "<STR_LIT>" , <EOL> default = <NUM_LIT:1.0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> CONF = cfg . CONF <EOL> benchmark_group = cfg . OptGroup ( name = "<STR_LIT>" , title = "<STR_LIT>" ) <EOL> CONF . register_opts ( HEAT_BENCHMARK_OPTS , group = benchmark_group ) <EOL> class HeatScenario ( scenario . OpenStackScenario ) : <EOL> """<STR_LIT>""" <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _list_stacks ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . clients ( "<STR_LIT>" ) . stacks . list ( ) ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _create_stack ( self , template , parameters = None , <EOL> files = None , environment = None ) : <EOL> """<STR_LIT>""" <EOL> stack_name = self . generate_random_name ( ) <EOL> kw = { <EOL> "<STR_LIT>" : stack_name , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : parameters or { } , <EOL> "<STR_LIT>" : template , <EOL> "<STR_LIT>" : files or { } , <EOL> "<STR_LIT>" : environment or { } <EOL> } <EOL> stack_id = self . clients ( "<STR_LIT>" ) . stacks . create ( ** kw ) [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] <EOL> stack = self . clients ( "<STR_LIT>" ) . stacks . get ( stack_id ) <EOL> time . sleep ( CONF . benchmark . heat_stack_create_prepoll_delay ) <EOL> stack = utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_create_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_create_poll_interval ) <EOL> return stack <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _update_stack ( self , stack , template , parameters = None , <EOL> files = None , environment = None ) : <EOL> """<STR_LIT>""" <EOL> kw = { <EOL> "<STR_LIT>" : stack . stack_name , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : parameters or { } , <EOL> "<STR_LIT>" : template , <EOL> "<STR_LIT>" : files or { } , <EOL> "<STR_LIT>" : environment or { } <EOL> } <EOL> self . clients ( "<STR_LIT>" ) . stacks . update ( stack . id , ** kw ) <EOL> time . sleep ( CONF . benchmark . heat_stack_update_prepoll_delay ) <EOL> stack = utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_update_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_update_poll_interval ) <EOL> return stack <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _check_stack ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> self . clients ( "<STR_LIT>" ) . actions . check ( stack . id ) <EOL> utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( [ "<STR_LIT>" ] ) , <EOL> timeout = CONF . benchmark . heat_stack_check_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_check_poll_interval ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _delete_stack ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> stack . delete ( ) <EOL> utils . wait_for_status ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> check_deletion = True , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_delete_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_delete_poll_interval ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _suspend_stack ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> self . clients ( "<STR_LIT>" ) . actions . suspend ( stack . id ) <EOL> utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_suspend_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_suspend_poll_interval ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _resume_stack ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> self . clients ( "<STR_LIT>" ) . actions . resume ( stack . id ) <EOL> utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_resume_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_resume_poll_interval ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _snapshot_stack ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> snapshot = self . clients ( "<STR_LIT>" ) . stacks . snapshot ( <EOL> stack . id ) <EOL> utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_snapshot_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_snapshot_poll_interval ) <EOL> return snapshot <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _restore_stack ( self , stack , snapshot_id ) : <EOL> """<STR_LIT>""" <EOL> self . clients ( "<STR_LIT>" ) . stacks . restore ( stack . id , snapshot_id ) <EOL> utils . wait_for ( <EOL> stack , <EOL> ready_statuses = [ "<STR_LIT>" ] , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_restore_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_restore_poll_interval <EOL> ) <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _stack_show_output ( self , stack , output_key ) : <EOL> """<STR_LIT>""" <EOL> output = self . clients ( "<STR_LIT>" ) . stacks . output_show ( stack . id , output_key ) <EOL> return output <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _stack_show_output_via_API ( self , stack , output_key ) : <EOL> """<STR_LIT>""" <EOL> stack = self . clients ( "<STR_LIT>" ) . stacks . get ( stack_id = stack . id ) <EOL> for output in stack . to_dict ( ) . get ( "<STR_LIT>" , [ ] ) : <EOL> if output [ "<STR_LIT>" ] == output_key : <EOL> return output <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _stack_list_output ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> output_list = self . clients ( "<STR_LIT>" ) . stacks . output_list ( stack . id ) <EOL> return output_list <EOL> @ atomic . action_timer ( "<STR_LIT>" ) <EOL> def _stack_list_output_via_API ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> stack = self . clients ( "<STR_LIT>" ) . stacks . get ( stack_id = stack . id ) <EOL> output_list = stack . to_dict ( ) [ "<STR_LIT>" ] <EOL> return output_list <EOL> def _count_instances ( self , stack ) : <EOL> """<STR_LIT>""" <EOL> return len ( [ <EOL> r for r in self . clients ( "<STR_LIT>" ) . resources . list ( stack . id , <EOL> nested_depth = <NUM_LIT:1> ) <EOL> if r . resource_type == "<STR_LIT>" ] ) <EOL> def _scale_stack ( self , stack , output_key , delta ) : <EOL> """<STR_LIT>""" <EOL> num_instances = self . _count_instances ( stack ) <EOL> expected_instances = num_instances + delta <EOL> LOG . debug ( "<STR_LIT>" % <EOL> ( stack . id , num_instances , expected_instances , output_key ) ) <EOL> with atomic . ActionTimer ( self , "<STR_LIT>" % output_key ) : <EOL> self . _stack_webhook ( stack , output_key ) <EOL> utils . wait_for ( <EOL> stack , <EOL> is_ready = lambda s : ( <EOL> self . _count_instances ( s ) == expected_instances ) , <EOL> failure_statuses = [ "<STR_LIT>" ] , <EOL> update_resource = utils . get_from_manager ( ) , <EOL> timeout = CONF . benchmark . heat_stack_scale_timeout , <EOL> check_interval = CONF . benchmark . heat_stack_scale_poll_interval ) <EOL> def _stack_webhook ( self , stack , output_key ) : <EOL> """<STR_LIT>""" <EOL> url = None <EOL> for output in stack . outputs : <EOL> if output [ "<STR_LIT>" ] == output_key : <EOL> url = output [ "<STR_LIT>" ] <EOL> break <EOL> else : <EOL> raise exceptions . InvalidConfigException ( <EOL> "<STR_LIT>" % <EOL> { "<STR_LIT:key>" : output_key , "<STR_LIT:id>" : stack . id } ) <EOL> with atomic . ActionTimer ( self , "<STR_LIT>" % output_key ) : <EOL> requests . post ( url ) . raise_for_status ( ) </s>
