<s> import mock <EOL> from oslo_config import cfg <EOL> from oslo_utils import uuidutils <EOL> from saharaclient . api import base as sahara_base <EOL> from rally import consts <EOL> from rally import exceptions <EOL> from rally . plugins . openstack . scenarios . sahara import utils <EOL> from tests . unit import test <EOL> CONF = cfg . CONF <EOL> SAHARA_UTILS = "<STR_LIT>" <EOL> class SaharaScenarioTestCase ( test . ScenarioTestCase ) : <EOL> patch_benchmark_utils = False <EOL> def setUp ( self ) : <EOL> super ( SaharaScenarioTestCase , self ) . setUp ( ) <EOL> CONF . set_override ( "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , <EOL> enforce_type = True ) <EOL> CONF . set_override ( "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , <EOL> enforce_type = True ) <EOL> def test_list_node_group_templates ( self ) : <EOL> ngts = [ ] <EOL> self . clients ( "<STR_LIT>" ) . node_group_templates . list . return_value = ngts <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> return_ngts_list = scenario . _list_node_group_templates ( ) <EOL> self . assertEqual ( ngts , return_ngts_list ) <EOL> self . _test_atomic_action_timer ( scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" ) <EOL> def test_create_node_group_templates ( <EOL> self , mock_sahara_consts , <EOL> mock_generate_random_name ) : <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> mock_processes = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } <EOL> } <EOL> } <EOL> mock_sahara_consts . NODE_PROCESSES = mock_processes <EOL> scenario . _create_master_node_group_template ( <EOL> flavor_id = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" <EOL> ) <EOL> scenario . _create_worker_node_group_template ( <EOL> flavor_id = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" <EOL> ) <EOL> create_calls = [ <EOL> mock . call ( <EOL> name = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> flavor_id = "<STR_LIT>" , <EOL> node_processes = [ "<STR_LIT>" ] ) , <EOL> mock . call ( <EOL> name = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> flavor_id = "<STR_LIT>" , <EOL> node_processes = [ "<STR_LIT>" ] <EOL> ) ] <EOL> self . clients ( "<STR_LIT>" ) . node_group_templates . create . assert_has_calls ( <EOL> create_calls ) <EOL> self . _test_atomic_action_timer ( <EOL> scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> self . _test_atomic_action_timer ( <EOL> scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_delete_node_group_templates ( self ) : <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> ng = mock . MagicMock ( id = <NUM_LIT> ) <EOL> scenario . _delete_node_group_template ( ng ) <EOL> delete_mock = self . clients ( "<STR_LIT>" ) . node_group_templates . delete <EOL> delete_mock . assert_called_once_with ( <NUM_LIT> ) <EOL> self . _test_atomic_action_timer ( scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" ) <EOL> def test_launch_cluster ( self , mock_sahara_consts , <EOL> mock_generate_random_name ) : <EOL> self . context . update ( { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> } <EOL> } ) <EOL> self . clients ( "<STR_LIT>" ) . values . return_value = [ <EOL> consts . Service . NEUTRON <EOL> ] <EOL> scenario = utils . SaharaScenario ( context = self . context ) <EOL> mock_processes = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } <EOL> } <EOL> } <EOL> mock_configs = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:target>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> floating_ip_pool_uuid = uuidutils . generate_uuid ( ) <EOL> node_groups = [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : floating_ip_pool_uuid , <EOL> "<STR_LIT:count>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> } , { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : floating_ip_pool_uuid , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT:count>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> } <EOL> ] <EOL> mock_sahara_consts . NODE_PROCESSES = mock_processes <EOL> mock_sahara_consts . REPLICATION_CONFIGS = mock_configs <EOL> self . clients ( "<STR_LIT>" ) . clusters . create . return_value . id = ( <EOL> "<STR_LIT>" ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . return_value . status = ( <EOL> "<STR_LIT>" ) <EOL> scenario . _launch_cluster ( <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> master_flavor_id = "<STR_LIT>" , <EOL> worker_flavor_id = "<STR_LIT>" , <EOL> image_id = "<STR_LIT>" , <EOL> floating_ip_pool = floating_ip_pool_uuid , <EOL> volumes_per_node = <NUM_LIT:5> , <EOL> volumes_size = <NUM_LIT:10> , <EOL> auto_security_group = True , <EOL> security_groups = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> workers_count = <NUM_LIT> , <EOL> node_configs = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . create . assert_called_once_with ( <EOL> name = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> node_groups = node_groups , <EOL> default_image_id = "<STR_LIT>" , <EOL> cluster_configs = { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:3> } } , <EOL> net_id = "<STR_LIT>" , <EOL> anti_affinity = None <EOL> ) <EOL> self . _test_atomic_action_timer ( scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" ) <EOL> def test_launch_cluster_with_proxy ( self , mock_sahara_consts , <EOL> mock_generate_random_name ) : <EOL> context = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> self . clients ( "<STR_LIT>" ) . values . return_value = [ <EOL> consts . Service . NEUTRON <EOL> ] <EOL> scenario = utils . SaharaScenario ( context = context ) <EOL> mock_processes = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } <EOL> } <EOL> } <EOL> mock_configs = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:target>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> floating_ip_pool_uuid = uuidutils . generate_uuid ( ) <EOL> node_groups = [ <EOL> { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : floating_ip_pool_uuid , <EOL> "<STR_LIT:count>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT>" : True <EOL> } , { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT:count>" : <NUM_LIT> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> } , { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : floating_ip_pool_uuid , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT:count>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ] <EOL> mock_sahara_consts . NODE_PROCESSES = mock_processes <EOL> mock_sahara_consts . REPLICATION_CONFIGS = mock_configs <EOL> self . clients ( "<STR_LIT>" ) . clusters . create . return_value = mock . MagicMock ( <EOL> id = "<STR_LIT>" ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . return_value = mock . MagicMock ( <EOL> status = "<STR_LIT>" ) <EOL> scenario . _launch_cluster ( <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> master_flavor_id = "<STR_LIT>" , <EOL> worker_flavor_id = "<STR_LIT>" , <EOL> image_id = "<STR_LIT>" , <EOL> floating_ip_pool = floating_ip_pool_uuid , <EOL> volumes_per_node = <NUM_LIT:5> , <EOL> volumes_size = <NUM_LIT:10> , <EOL> auto_security_group = True , <EOL> security_groups = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> workers_count = <NUM_LIT> , <EOL> node_configs = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> enable_proxy = True <EOL> ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . create . assert_called_once_with ( <EOL> name = "<STR_LIT>" , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> node_groups = node_groups , <EOL> default_image_id = "<STR_LIT>" , <EOL> cluster_configs = { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT:3> } } , <EOL> net_id = "<STR_LIT>" , <EOL> anti_affinity = None <EOL> ) <EOL> self . _test_atomic_action_timer ( scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" ) <EOL> def test_launch_cluster_error ( self , mock_sahara_consts , <EOL> mock_generate_random_name ) : <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> mock_processes = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } <EOL> } <EOL> } <EOL> mock_configs = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:target>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> mock_sahara_consts . NODE_PROCESSES = mock_processes <EOL> mock_sahara_consts . REPLICATION_CONFIGS = mock_configs <EOL> self . clients ( "<STR_LIT>" ) . clusters . create . return_value = mock . MagicMock ( <EOL> id = "<STR_LIT>" ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . return_value = mock . MagicMock ( <EOL> status = "<STR_LIT:error>" ) <EOL> self . assertRaises ( exceptions . GetResourceErrorStatus , <EOL> scenario . _launch_cluster , <EOL> plugin_name = "<STR_LIT>" , <EOL> hadoop_version = "<STR_LIT>" , <EOL> master_flavor_id = "<STR_LIT>" , <EOL> worker_flavor_id = "<STR_LIT>" , <EOL> image_id = "<STR_LIT>" , <EOL> floating_ip_pool = "<STR_LIT>" , <EOL> volumes_per_node = <NUM_LIT:5> , <EOL> volumes_size = <NUM_LIT:10> , <EOL> workers_count = <NUM_LIT> , <EOL> node_configs = { "<STR_LIT>" : { "<STR_LIT>" : <EOL> "<STR_LIT>" } } ) <EOL> def test_scale_cluster ( self ) : <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> cluster = mock . MagicMock ( id = <NUM_LIT> , node_groups = [ { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:count>" : <NUM_LIT:1> <EOL> } , { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:count>" : <NUM_LIT> <EOL> } ] ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . return_value = mock . MagicMock ( <EOL> id = <NUM_LIT> , <EOL> status = "<STR_LIT>" ) <EOL> expected_scale_object = { <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:count>" : <NUM_LIT> <EOL> } ] <EOL> } <EOL> scenario . _scale_cluster ( cluster , <NUM_LIT:1> ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . scale . assert_called_once_with ( <EOL> <NUM_LIT> , expected_scale_object ) <EOL> def test_delete_cluster ( self ) : <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> cluster = mock . MagicMock ( id = <NUM_LIT> ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . side_effect = [ <EOL> cluster , sahara_base . APIException ( ) <EOL> ] <EOL> scenario . _delete_cluster ( cluster ) <EOL> delete_mock = self . clients ( "<STR_LIT>" ) . clusters . delete <EOL> delete_mock . assert_called_once_with ( <NUM_LIT> ) <EOL> cl_get_expected = mock . call ( <NUM_LIT> ) <EOL> self . clients ( "<STR_LIT>" ) . clusters . get . assert_has_calls ( [ cl_get_expected , <EOL> cl_get_expected ] ) <EOL> self . _test_atomic_action_timer ( scenario . atomic_actions ( ) , <EOL> "<STR_LIT>" ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> def test_create_output_ds ( self , mock_generate_random_name ) : <EOL> self . context . update ( { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } ) <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> scenario . _create_output_ds ( ) <EOL> self . clients ( "<STR_LIT>" ) . data_sources . create . assert_called_once_with ( <EOL> name = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> data_source_type = "<STR_LIT>" , <EOL> url = "<STR_LIT>" <EOL> ) <EOL> @ mock . patch ( SAHARA_UTILS + "<STR_LIT>" , <EOL> return_value = "<STR_LIT>" ) <EOL> def test_create_output_ds_swift ( self , mock_generate_random_name ) : <EOL> self . context . update ( { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } ) <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> self . assertRaises ( exceptions . RallyException , <EOL> scenario . _create_output_ds ) <EOL> def test_run_job_execution ( self ) : <EOL> self . clients ( "<STR_LIT>" ) . job_executions . get . side_effect = [ <EOL> mock . MagicMock ( info = { "<STR_LIT:status>" : "<STR_LIT>" } , id = "<STR_LIT>" ) , <EOL> mock . MagicMock ( info = { "<STR_LIT:status>" : "<STR_LIT>" } , id = "<STR_LIT>" ) ] <EOL> self . clients ( "<STR_LIT>" ) . job_executions . create . return_value = ( <EOL> mock . MagicMock ( id = "<STR_LIT>" ) ) <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> scenario . _run_job_execution ( job_id = "<STR_LIT>" , <EOL> cluster_id = "<STR_LIT>" , <EOL> input_id = "<STR_LIT>" , <EOL> output_id = "<STR_LIT>" , <EOL> configs = { "<STR_LIT:k>" : "<STR_LIT:v>" } , <EOL> job_idx = <NUM_LIT:0> ) <EOL> self . clients ( "<STR_LIT>" ) . job_executions . create . assert_called_once_with ( <EOL> job_id = "<STR_LIT>" , <EOL> cluster_id = "<STR_LIT>" , <EOL> input_id = "<STR_LIT>" , <EOL> output_id = "<STR_LIT>" , <EOL> configs = { "<STR_LIT:k>" : "<STR_LIT:v>" } <EOL> ) <EOL> je_get_expected = mock . call ( "<STR_LIT>" ) <EOL> self . clients ( "<STR_LIT>" ) . job_executions . get . assert_has_calls ( <EOL> [ je_get_expected , je_get_expected ] <EOL> ) <EOL> def test_run_job_execution_fail ( self ) : <EOL> self . clients ( "<STR_LIT>" ) . job_executions . get . side_effect = [ <EOL> mock . MagicMock ( info = { "<STR_LIT:status>" : "<STR_LIT>" } , id = "<STR_LIT>" ) , <EOL> mock . MagicMock ( info = { "<STR_LIT:status>" : "<STR_LIT>" } , id = "<STR_LIT>" ) ] <EOL> self . clients ( "<STR_LIT>" ) . job_executions . create . return_value = ( <EOL> mock . MagicMock ( id = "<STR_LIT>" ) ) <EOL> scenario = utils . SaharaScenario ( self . context ) <EOL> self . assertRaises ( exceptions . RallyException , <EOL> scenario . _run_job_execution , <EOL> job_id = "<STR_LIT>" , <EOL> cluster_id = "<STR_LIT>" , <EOL> input_id = "<STR_LIT>" , <EOL> output_id = "<STR_LIT>" , <EOL> configs = { "<STR_LIT:k>" : "<STR_LIT:v>" } , <EOL> job_idx = <NUM_LIT:0> ) <EOL> self . clients ( "<STR_LIT>" ) . job_executions . create . assert_called_once_with ( <EOL> job_id = "<STR_LIT>" , <EOL> cluster_id = "<STR_LIT>" , <EOL> input_id = "<STR_LIT>" , <EOL> output_id = "<STR_LIT>" , <EOL> configs = { "<STR_LIT:k>" : "<STR_LIT:v>" } <EOL> ) </s>
