<s> import copy <EOL> import os <EOL> import ConfigParser <EOL> import ooinstall . cli_installer as cli <EOL> from test . fixture import OOCliFixture , SAMPLE_CONFIG , build_input , read_yaml <EOL> from mock import patch <EOL> MOCK_FACTS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> } <EOL> MOCK_FACTS_QUICKHA = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> } <EOL> BAD_CONFIG = """<STR_LIT>""" <EOL> QUICKHA_CONFIG = """<STR_LIT>""" <EOL> QUICKHA_2_MASTER_CONFIG = """<STR_LIT>""" <EOL> QUICKHA_CONFIG_REUSED_LB = """<STR_LIT>""" <EOL> QUICKHA_CONFIG_NO_LB = """<STR_LIT>""" <EOL> QUICKHA_CONFIG_PRECONFIGURED_LB = """<STR_LIT>""" <EOL> class UnattendedCliTests ( OOCliFixture ) : <EOL> def setUp ( self ) : <EOL> OOCliFixture . setUp ( self ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on1 ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> load_facts_mock . return_value = ( mock_facts , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , SAMPLE_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> if result . exception is None or result . exit_code != <NUM_LIT:1> : <EOL> print "<STR_LIT>" % result . exit_code <EOL> self . fail ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on2 ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> self . _verify_get_hosts_to_run_on ( mock_facts , load_facts_mock , run_playbook_mock , <EOL> cli_input = None , <EOL> exp_hosts_len = <NUM_LIT:3> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:3> , <EOL> force = True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on3 ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> self . _verify_get_hosts_to_run_on ( MOCK_FACTS , load_facts_mock , run_playbook_mock , <EOL> cli_input = None , <EOL> exp_hosts_len = <NUM_LIT:3> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:3> , <EOL> force = False ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on4 ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> self . _verify_get_hosts_to_run_on ( MOCK_FACTS , load_facts_mock , run_playbook_mock , <EOL> cli_input = None , <EOL> exp_hosts_len = <NUM_LIT:3> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:3> , <EOL> force = True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on5 ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> self . _verify_get_hosts_to_run_on ( mock_facts , load_facts_mock , run_playbook_mock , <EOL> cli_input = None , <EOL> exp_hosts_len = <NUM_LIT:3> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:2> , <EOL> force = False ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on6 ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> self . _verify_get_hosts_to_run_on ( mock_facts , load_facts_mock , run_playbook_mock , <EOL> cli_input = None , <EOL> exp_hosts_len = <NUM_LIT:3> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:3> , <EOL> force = True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_cfg_full_run ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , SAMPLE_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> load_facts_args = load_facts_mock . call_args [ <NUM_LIT:0> ] <EOL> self . assertEquals ( os . path . join ( self . work_dir , "<STR_LIT>" ) , <EOL> load_facts_args [ <NUM_LIT:0> ] ) <EOL> self . assertEquals ( os . path . join ( self . work_dir , <EOL> "<STR_LIT>" ) , load_facts_args [ <NUM_LIT:1> ] ) <EOL> env_vars = load_facts_args [ <NUM_LIT:2> ] <EOL> self . assertEquals ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , <EOL> env_vars [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , env_vars [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' not in env_vars or <EOL> env_vars [ '<STR_LIT>' ] == cli . DEFAULT_ANSIBLE_CONFIG ) <EOL> hosts = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> hosts_to_run_on = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> self . assertEquals ( <NUM_LIT:3> , len ( hosts ) ) <EOL> self . assertEquals ( <NUM_LIT:3> , len ( hosts_to_run_on ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_inventory_write ( self , load_facts_mock , run_playbook_mock ) : <EOL> merged_config = "<STR_LIT>" % ( SAMPLE_CONFIG % '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , merged_config ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> inventory . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> inventory . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( inventory . items ( '<STR_LIT>' ) ) ) <EOL> self . assertEquals ( <NUM_LIT:3> , len ( inventory . items ( '<STR_LIT>' ) ) ) <EOL> for item in inventory . items ( '<STR_LIT>' ) : <EOL> master_line = item [ <NUM_LIT:0> ] <EOL> if item [ <NUM_LIT:1> ] is not None : <EOL> master_line = "<STR_LIT>" % ( master_line , item [ <NUM_LIT:1> ] ) <EOL> self . assertTrue ( '<STR_LIT>' in master_line ) <EOL> self . assertTrue ( '<STR_LIT>' in master_line ) <EOL> self . assertTrue ( '<STR_LIT>' in master_line ) <EOL> self . assertTrue ( '<STR_LIT>' in master_line ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_variant_version_latest_assumed ( self , load_facts_mock , <EOL> run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , SAMPLE_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> written_config = read_yaml ( config_file ) <EOL> self . assertEquals ( '<STR_LIT>' , written_config [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , written_config [ '<STR_LIT>' ] ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> inventory . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_variant_version_preserved ( self , load_facts_mock , <EOL> run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config = SAMPLE_CONFIG % '<STR_LIT>' <EOL> config = '<STR_LIT>' % ( config , '<STR_LIT>' ) <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , config ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> written_config = read_yaml ( config_file ) <EOL> self . assertEquals ( '<STR_LIT>' , written_config [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , written_config [ '<STR_LIT>' ] ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> inventory . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_no_ansible_config_specified ( self , load_facts_mock , run_ansible_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_ansible_mock . return_value = <NUM_LIT:0> <EOL> config = SAMPLE_CONFIG % '<STR_LIT>' <EOL> self . _ansible_config_test ( load_facts_mock , run_ansible_mock , <EOL> config , None , None ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ansible_config_specified_cli ( self , load_facts_mock , run_ansible_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_ansible_mock . return_value = <NUM_LIT:0> <EOL> config = SAMPLE_CONFIG % '<STR_LIT>' <EOL> ansible_config = os . path . join ( self . work_dir , '<STR_LIT>' ) <EOL> self . _ansible_config_test ( load_facts_mock , run_ansible_mock , <EOL> config , ansible_config , ansible_config ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ansible_config_specified_in_installer_config ( self , <EOL> load_facts_mock , run_ansible_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_ansible_mock . return_value = <NUM_LIT:0> <EOL> ansible_config = os . path . join ( self . work_dir , '<STR_LIT>' ) <EOL> config = SAMPLE_CONFIG % '<STR_LIT>' <EOL> config = "<STR_LIT>" % ( config , ansible_config ) <EOL> self . _ansible_config_test ( load_facts_mock , run_ansible_mock , <EOL> config , None , ansible_config ) <EOL> def _ansible_config_test ( self , load_facts_mock , run_ansible_mock , <EOL> installer_config , ansible_config_cli = None , expected_result = None ) : <EOL> """<STR_LIT>""" <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_ansible_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , installer_config ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file ] ) <EOL> if ansible_config_cli : <EOL> self . cli_args . extend ( [ "<STR_LIT>" , ansible_config_cli ] ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> facts_env_vars = load_facts_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> if expected_result : <EOL> self . assertEquals ( expected_result , facts_env_vars [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . assertTrue ( '<STR_LIT>' not in facts_env_vars or <EOL> facts_env_vars [ '<STR_LIT>' ] == cli . DEFAULT_ANSIBLE_CONFIG ) <EOL> env_vars = run_ansible_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> if expected_result : <EOL> self . assertEquals ( expected_result , env_vars [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . assertTrue ( '<STR_LIT>' not in env_vars or <EOL> env_vars [ '<STR_LIT>' ] == cli . DEFAULT_ANSIBLE_CONFIG ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_bad_config ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , BAD_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assertEquals ( <NUM_LIT:1> , result . exit_code ) <EOL> self . assertTrue ( "<STR_LIT>" <EOL> in result . output ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_quick_ha_full_run ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , QUICKHA_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> hosts = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> hosts_to_run_on = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> self . assertEquals ( <NUM_LIT:6> , len ( hosts ) ) <EOL> self . assertEquals ( <NUM_LIT:6> , len ( hosts_to_run_on ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_quick_ha_only_2_masters ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , QUICKHA_2_MASTER_CONFIG % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:1> ) <EOL> self . assertTrue ( "<STR_LIT>" in result . output ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_quick_ha_no_lb ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , QUICKHA_CONFIG_NO_LB % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:1> ) <EOL> self . assertTrue ( '<STR_LIT>' in result . output ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_quick_ha_reused_lb ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , QUICKHA_CONFIG_REUSED_LB % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:1> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_quick_ha_preconfigured_lb ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , QUICKHA_CONFIG_PRECONFIGURED_LB % '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file , "<STR_LIT>" ] ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> hosts = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> hosts_to_run_on = run_playbook_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> self . assertEquals ( <NUM_LIT:6> , len ( hosts ) ) <EOL> self . assertEquals ( <NUM_LIT:6> , len ( hosts_to_run_on ) ) <EOL> class AttendedCliTests ( OOCliFixture ) : <EOL> def setUp ( self ) : <EOL> OOCliFixture . setUp ( self ) <EOL> self . config_file = os . path . join ( self . work_dir , '<STR_LIT>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , self . config_file ] ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_full_run ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , False , False ) , <EOL> ( '<STR_LIT>' , False , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:4> , <NUM_LIT:4> ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:4> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var_unset ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var_unset ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_add_nodes ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> load_facts_mock . return_value = ( mock_facts , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , False , False ) , <EOL> ] , <EOL> add_nodes = [ ( '<STR_LIT>' , False , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , <EOL> self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:3> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_fresh_install_with_config ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> config_file = self . write_config ( os . path . join ( self . work_dir , <EOL> '<STR_LIT>' ) , <EOL> SAMPLE_CONFIG % '<STR_LIT>' ) <EOL> cli_input = build_input ( confirm_facts = '<STR_LIT:y>' ) <EOL> self . cli_args . extend ( [ "<STR_LIT:-c>" , config_file ] ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , <EOL> self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> written_config = read_yaml ( config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:3> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_get_hosts_to_run_on ( self , load_facts_mock , run_playbook_mock ) : <EOL> mock_facts = copy . deepcopy ( MOCK_FACTS ) <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> mock_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ] , <EOL> add_nodes = [ ( '<STR_LIT>' , False , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> schedulable_masters_ok = True , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' , ) <EOL> self . _verify_get_hosts_to_run_on ( mock_facts , load_facts_mock , <EOL> run_playbook_mock , <EOL> cli_input , <EOL> exp_hosts_len = <NUM_LIT:2> , <EOL> exp_hosts_to_run_on_len = <NUM_LIT:2> , <EOL> force = False ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ha_dedicated_node ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , False , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> master_lb = ( '<STR_LIT>' , False ) , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:6> , <NUM_LIT:6> ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:6> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var_unset ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( inventory . has_section ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( <NUM_LIT:3> , len ( inventory . items ( '<STR_LIT>' ) ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ha_no_dedicated_nodes ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , True , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> master_lb = ( '<STR_LIT>' , False ) , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:5> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def assert_inventory_host_var ( self , inventory , section , host , variable ) : <EOL> for ( a , b ) in inventory . items ( section ) : <EOL> full_line = "<STR_LIT>" % ( a , b ) <EOL> tokens = full_line . split ( ) <EOL> if tokens [ <NUM_LIT:0> ] == host : <EOL> found = False <EOL> for token in tokens : <EOL> if token == variable : <EOL> found = True <EOL> continue <EOL> self . assertTrue ( "<STR_LIT>" % <EOL> ( variable , full_line ) , found ) <EOL> return <EOL> self . fail ( "<STR_LIT>" % host ) <EOL> def assert_inventory_host_var_unset ( self , inventory , section , host , variable ) : <EOL> for ( a , b ) in inventory . items ( section ) : <EOL> full_line = "<STR_LIT>" % ( a , b ) <EOL> tokens = full_line . split ( ) <EOL> if tokens [ <NUM_LIT:0> ] == host : <EOL> self . assertFalse ( ( "<STR_LIT>" % variable ) in full_line , <EOL> msg = '<STR_LIT>' % <EOL> ( variable , full_line ) ) <EOL> return <EOL> self . fail ( "<STR_LIT>" % host ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ha_reuse_master_as_lb ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS_QUICKHA , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , False , False ) , <EOL> ( '<STR_LIT>' , True , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> master_lb = ( [ '<STR_LIT>' , '<STR_LIT>' ] , False ) , <EOL> storage = '<STR_LIT>' ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_all_in_one ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . _verify_run_playbook ( run_playbook_mock , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:1> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_ha_hint ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:3> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> print result . output <EOL> self . assertTrue ( "<STR_LIT>" <EOL> not in result . output ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_gen_inventory ( self , load_facts_mock , run_playbook_mock ) : <EOL> load_facts_mock . return_value = ( MOCK_FACTS , <NUM_LIT:0> ) <EOL> run_playbook_mock . return_value = <NUM_LIT:0> <EOL> cli_input = build_input ( hosts = [ <EOL> ( '<STR_LIT>' , True , False ) , <EOL> ( '<STR_LIT>' , False , False ) , <EOL> ( '<STR_LIT>' , False , False ) ] , <EOL> ssh_user = '<STR_LIT:root>' , <EOL> variant_num = <NUM_LIT:1> , <EOL> confirm_facts = '<STR_LIT:y>' , <EOL> storage = '<STR_LIT>' , ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> self . cli_args . append ( "<STR_LIT>" ) <EOL> result = self . runner . invoke ( cli . cli , self . cli_args , <EOL> input = cli_input ) <EOL> self . assert_result ( result , <NUM_LIT:0> ) <EOL> self . _verify_load_facts ( load_facts_mock ) <EOL> self . assertEquals ( <NUM_LIT:0> , len ( run_playbook_mock . mock_calls ) ) <EOL> written_config = read_yaml ( self . config_file ) <EOL> self . _verify_config_hosts ( written_config , <NUM_LIT:4> ) <EOL> inventory = ConfigParser . ConfigParser ( allow_no_value = True ) <EOL> inventory . read ( os . path . join ( self . work_dir , '<STR_LIT>' ) ) <EOL> self . assert_inventory_host_var ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var_unset ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . assert_inventory_host_var_unset ( inventory , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) </s>
