<s> import json <EOL> import os <EOL> import re <EOL> import threading <EOL> import time <EOL> import unittest <EOL> import mock <EOL> from tests . functional import utils <EOL> FAKE_TASK_UUID = "<STR_LIT>" <EOL> class TaskTestCase ( unittest . TestCase ) : <EOL> def _get_sample_task_config ( self ) : <EOL> return { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> def _get_sample_task_config_v2 ( self ) : <EOL> return { <EOL> "<STR_LIT:version>" : <NUM_LIT:2> , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } <EOL> } <EOL> } ] <EOL> } , <EOL> { <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:description>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } <EOL> } <EOL> } ] <EOL> } <EOL> ] <EOL> } <EOL> def _get_deployment_uuid ( self , output ) : <EOL> return re . search ( <EOL> r"<STR_LIT>" , <EOL> output ) . group ( "<STR_LIT>" ) <EOL> def test_status ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> def test_detailed ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> detailed = rally ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" , detailed ) <EOL> self . assertIn ( "<STR_LIT>" , detailed ) <EOL> detailed_iterations_data = rally ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" , detailed_iterations_data ) <EOL> self . assertNotIn ( "<STR_LIT>" , detailed_iterations_data ) <EOL> def test_detailed_with_errors ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( "<STR_LIT>" % config . filename ) <EOL> uuid = re . search ( <EOL> r"<STR_LIT>" , output ) . group ( "<STR_LIT>" ) <EOL> output = rally ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" % uuid , output ) <EOL> def test_detailed_no_atomic_actions ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> detailed = rally ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" , detailed ) <EOL> detailed_iterations_data = rally ( "<STR_LIT>" ) <EOL> self . assertNotIn ( "<STR_LIT>" , detailed_iterations_data ) <EOL> def test_start_with_empty_config ( self ) : <EOL> rally = utils . Rally ( ) <EOL> config = utils . TaskConfig ( None ) <EOL> with self . assertRaises ( utils . RallyCliError ) as err : <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT>" , err . exception . output ) <EOL> def test_results ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT:result>" , rally ( "<STR_LIT>" ) ) <EOL> def test_results_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_abort_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_delete_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_detailed_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_report_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_sla_check_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_status_with_wrong_task_id ( self ) : <EOL> rally = utils . Rally ( ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def _assert_html_report_libs_are_embedded ( self , file_path , expected = True ) : <EOL> embedded_signatures = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> external_signatures = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> html = open ( file_path ) . read ( ) <EOL> result_embedded = all ( [ sig in html for sig in embedded_signatures ] ) <EOL> result_external = all ( [ sig in html for sig in external_signatures ] ) <EOL> self . assertEqual ( expected , result_embedded ) <EOL> self . assertEqual ( not expected , result_external ) <EOL> def test_report_one_uuid ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> rally ( "<STR_LIT>" % rally . gen_report_path ( extension = "<STR_LIT:html>" ) ) <EOL> html_report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> self . assertTrue ( os . path . exists ( html_report ) ) <EOL> self . _assert_html_report_libs_are_embedded ( html_report , False ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> rally ( "<STR_LIT>" % <EOL> rally . gen_report_path ( extension = "<STR_LIT>" ) ) <EOL> self . assertTrue ( os . path . exists ( <EOL> rally . gen_report_path ( extension = "<STR_LIT>" ) ) ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> def test_report_bunch_uuids ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> task_uuids = [ ] <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> res = rally ( "<STR_LIT>" % config . filename ) <EOL> for line in res . splitlines ( ) : <EOL> if "<STR_LIT>" in line : <EOL> task_uuids . append ( line . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] ) <EOL> html_report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> rally ( "<STR_LIT>" % ( "<STR_LIT:U+0020>" . join ( task_uuids ) , <EOL> html_report ) ) <EOL> self . assertTrue ( os . path . exists ( html_report ) ) <EOL> self . _assert_html_report_libs_are_embedded ( html_report , False ) <EOL> def test_report_bunch_files ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> files = [ ] <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> path = "<STR_LIT>" % i <EOL> files . append ( path ) <EOL> if os . path . exists ( path ) : <EOL> os . remove ( path ) <EOL> rally ( "<STR_LIT>" , report_path = path , raw = True ) <EOL> html_report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> rally ( "<STR_LIT>" % ( <EOL> "<STR_LIT:U+0020>" . join ( files ) , html_report ) ) <EOL> self . assertTrue ( os . path . exists ( html_report ) ) <EOL> self . _assert_html_report_libs_are_embedded ( html_report , False ) <EOL> def test_report_one_uuid_one_file ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> task_result_file = "<STR_LIT>" <EOL> if os . path . exists ( task_result_file ) : <EOL> os . remove ( task_result_file ) <EOL> rally ( "<STR_LIT>" , report_path = task_result_file , raw = True ) <EOL> task_run_output = rally ( <EOL> "<STR_LIT>" % config . filename ) . splitlines ( ) <EOL> for line in task_run_output : <EOL> if "<STR_LIT>" in line : <EOL> task_uuid = line . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] <EOL> break <EOL> else : <EOL> return <NUM_LIT:1> <EOL> html_report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> rally ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( task_result_file , task_uuid , <EOL> html_report ) ) <EOL> self . assertTrue ( os . path . exists ( html_report ) ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" % FAKE_TASK_UUID ) <EOL> self . _assert_html_report_libs_are_embedded ( html_report , False ) <EOL> def test_report_one_uuid_with_static_libs ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> html_report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> rally ( "<STR_LIT>" % html_report ) <EOL> self . assertTrue ( os . path . exists ( html_report ) ) <EOL> self . _assert_html_report_libs_are_embedded ( html_report ) <EOL> def test_delete ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> rally ( "<STR_LIT>" ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> rally ( "<STR_LIT>" ) <EOL> self . assertNotIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> def test_list ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> rally ( "<STR_LIT>" ) ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> self . assertIn ( <EOL> "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , "<STR_LIT>" ) <EOL> def test_list_with_print_uuids_option ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> self . assertEqual ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> res = rally ( "<STR_LIT>" % config . filename ) <EOL> task_uuids = [ ] <EOL> for line in res . splitlines ( ) : <EOL> if "<STR_LIT>" in line : <EOL> task_uuids . append ( line . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] ) <EOL> self . assertTrue ( len ( task_uuids ) ) <EOL> self . assertIn ( task_uuids [ <NUM_LIT:0> ] , <EOL> rally ( "<STR_LIT>" ) ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> res = rally ( "<STR_LIT>" ) <EOL> task_uuids = res . split ( ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( task_uuids ) ) <EOL> res = rally ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for uuid in task_uuids : <EOL> self . assertIn ( uuid , res ) <EOL> def test_validate_is_valid ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> def test_validate_is_invalid ( self ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> cfg = { "<STR_LIT>" : "<STR_LIT>" } <EOL> config = utils . TaskConfig ( cfg ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> def test_start ( self ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> cfg = self . _get_sample_task_config ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> result = re . search ( <EOL> r"<STR_LIT>" , output ) <EOL> self . assertIsNotNone ( result ) <EOL> def test_validate_with_plugin_paths ( self ) : <EOL> rally = utils . Rally ( ) <EOL> plugin_paths = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> task_file = "<STR_LIT>" <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : task_file , <EOL> "<STR_LIT>" : plugin_paths } ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> plugin_paths = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> task_file = "<STR_LIT>" <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : task_file , <EOL> "<STR_LIT>" : plugin_paths } ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> plugin_paths = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> task_file = "<STR_LIT>" <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : task_file , <EOL> "<STR_LIT>" : plugin_paths } ) <EOL> self . assertIn ( "<STR_LIT>" , output ) <EOL> def _test_start_abort_on_sla_failure_success ( self , cfg , times ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> results = json . loads ( rally ( "<STR_LIT>" ) ) <EOL> iterations_completed = len ( results [ <NUM_LIT:0> ] [ "<STR_LIT:result>" ] ) <EOL> self . assertEqual ( times , iterations_completed ) <EOL> def test_start_abort_on_sla_failure_success_constant ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure_success ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_success_serial ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure_success ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_success_rps ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:20> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure_success ( cfg , times ) <EOL> def _test_start_abort_on_sla_failure ( self , cfg , times ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> results = json . loads ( rally ( "<STR_LIT>" ) ) <EOL> iterations_completed = len ( results [ <NUM_LIT:0> ] [ "<STR_LIT:result>" ] ) <EOL> self . assertTrue ( iterations_completed < times ) <EOL> def test_start_abort_on_sla_failure_max_seconds_constant ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_max_seconds_serial ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_max_seconds_rps ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:20> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_max_failure_rate_constant ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_max_failure_rate_serial ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def test_start_abort_on_sla_failure_max_failure_rate_rps ( self ) : <EOL> times = <NUM_LIT:100> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0.1> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : times , <EOL> "<STR_LIT>" : <NUM_LIT:20> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0.0> } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> self . _test_start_abort_on_sla_failure ( cfg , times ) <EOL> def _start_task_in_new_thread ( self , rally , cfg , report_file ) : <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> cmd = ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> report_path = os . path . join ( <EOL> os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" , report_file ) <EOL> task = threading . Thread ( target = rally , args = ( cmd , ) , <EOL> kwargs = { "<STR_LIT>" : report_path } ) <EOL> task . start ( ) <EOL> uuid = None <EOL> while not uuid : <EOL> if not uuid : <EOL> uuid = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> return task , uuid <EOL> def test_abort ( self ) : <EOL> RUNNER_TIMES = <NUM_LIT:10> <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : RUNNER_TIMES <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> rally = utils . Rally ( ) <EOL> task , uuid = self . _start_task_in_new_thread ( <EOL> rally , cfg , "<STR_LIT>" ) <EOL> rally ( "<STR_LIT>" % uuid ) <EOL> task . join ( ) <EOL> results = json . loads ( rally ( "<STR_LIT>" ) ) <EOL> iterations_completed = len ( results [ <NUM_LIT:0> ] [ "<STR_LIT:result>" ] ) <EOL> self . assertTrue ( iterations_completed < RUNNER_TIMES ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> report = rally . gen_report_path ( extension = "<STR_LIT:html>" ) <EOL> rally ( "<STR_LIT>" % report ) <EOL> def test_abort_soft ( self ) : <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : <NUM_LIT:2> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> } <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> rally = utils . Rally ( ) <EOL> task , uuid = self . _start_task_in_new_thread ( <EOL> rally , cfg , "<STR_LIT>" ) <EOL> rally ( "<STR_LIT>" ) <EOL> task . join ( ) <EOL> results = json . loads ( rally ( "<STR_LIT>" ) ) <EOL> iterations_completed = len ( results [ <NUM_LIT:0> ] [ "<STR_LIT:result>" ] ) <EOL> self . assertEqual ( <NUM_LIT:3> , iterations_completed ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( results ) ) <EOL> self . assertIn ( "<STR_LIT>" , rally ( "<STR_LIT>" ) ) <EOL> def test_use ( self ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> config = utils . TaskConfig ( self . _get_sample_task_config ( ) ) <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> result = re . search ( <EOL> r"<STR_LIT>" , output ) <EOL> uuid = result . group ( "<STR_LIT>" ) <EOL> rally ( "<STR_LIT>" % uuid ) <EOL> current_task = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> self . assertEqual ( uuid , current_task ) <EOL> def test_start_v2 ( self ) : <EOL> rally = utils . Rally ( ) <EOL> deployment_id = utils . get_global ( "<STR_LIT>" , rally . env ) <EOL> cfg = self . _get_sample_task_config_v2 ( ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { "<STR_LIT>" : config . filename , <EOL> "<STR_LIT>" : deployment_id } ) <EOL> result = re . search ( <EOL> r"<STR_LIT>" , output ) <EOL> self . assertIsNotNone ( result ) <EOL> def test_export ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( "<STR_LIT>" % config . filename ) <EOL> uuid = re . search ( <EOL> r"<STR_LIT>" , output ) . group ( "<STR_LIT>" ) <EOL> connection = ( <EOL> "<STR_LIT>" + rally . gen_report_path ( extension = "<STR_LIT>" ) ) <EOL> output = rally ( "<STR_LIT>" % ( <EOL> uuid , connection ) ) <EOL> expected = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % { <EOL> "<STR_LIT>" : uuid , <EOL> "<STR_LIT>" : connection , <EOL> } ) <EOL> self . assertIn ( expected , output ) <EOL> def test_export_with_wrong_connection ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> config = utils . TaskConfig ( cfg ) <EOL> output = rally ( "<STR_LIT>" % config . filename ) <EOL> uuid = re . search ( <EOL> r"<STR_LIT>" , output ) . group ( "<STR_LIT>" ) <EOL> connection = ( <EOL> "<STR_LIT>" + rally . gen_report_path ( extension = "<STR_LIT>" ) ) <EOL> self . assertRaises ( utils . RallyCliError , <EOL> rally , <EOL> "<STR_LIT>" % ( <EOL> uuid , connection ) ) <EOL> class SLATestCase ( unittest . TestCase ) : <EOL> def _get_sample_task_config ( self , max_seconds_per_iteration = <NUM_LIT:4> , <EOL> failure_rate_max = <NUM_LIT:0> ) : <EOL> return { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : True <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : max_seconds_per_iteration , <EOL> "<STR_LIT>" : { "<STR_LIT>" : failure_rate_max } <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> def test_sla_fail ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = self . _get_sample_task_config ( max_seconds_per_iteration = <NUM_LIT> ) <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> self . assertRaises ( utils . RallyCliError , rally , "<STR_LIT>" ) <EOL> def test_sla_success ( self ) : <EOL> rally = utils . Rally ( ) <EOL> config = utils . TaskConfig ( self . _get_sample_task_config ( ) ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> rally ( "<STR_LIT>" ) <EOL> expected = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : mock . ANY , <EOL> "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:status>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : mock . ANY , <EOL> "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:status>" : "<STR_LIT>" } <EOL> ] <EOL> data = rally ( "<STR_LIT>" , getjson = True ) <EOL> self . assertEqual ( expected , data ) <EOL> class SLAExtraFlagsTestCase ( unittest . TestCase ) : <EOL> def test_abort_on_sla_fail ( self ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:5> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:0> } <EOL> } <EOL> } <EOL> ] } <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> expected = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:status>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : mock . ANY , <EOL> "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:status>" : "<STR_LIT>" } <EOL> ] <EOL> try : <EOL> rally ( "<STR_LIT>" , getjson = True ) <EOL> except utils . RallyCliError as expected_error : <EOL> self . assertEqual ( json . loads ( expected_error . output ) , expected ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _test_broken_context ( self , runner ) : <EOL> rally = utils . Rally ( ) <EOL> cfg = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:args>" : { } , <EOL> "<STR_LIT>" : runner , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : True } <EOL> } <EOL> } <EOL> ] } <EOL> config = utils . TaskConfig ( cfg ) <EOL> rally ( "<STR_LIT>" % config . filename ) <EOL> expected = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : mock . ANY , <EOL> "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT:status>" : "<STR_LIT>" } <EOL> ] <EOL> try : <EOL> rally ( "<STR_LIT>" , getjson = True ) <EOL> except utils . RallyCliError as expected_error : <EOL> self . assertEqual ( json . loads ( expected_error . output ) , expected ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_broken_context_with_constant_runner ( self ) : <EOL> self . _test_broken_context ( { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:5> } ) <EOL> def test_broken_context_with_rps_runner ( self ) : <EOL> self . _test_broken_context ( { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:6> } ) </s>
