<s> import json <EOL> __author__ = '<STR_LIT>' <EOL> import re <EOL> from eucaops import Eucaops <EOL> from eutester . eutestcase import EutesterTestCase <EOL> class Install ( EutesterTestCase ) : <EOL> def __init__ ( self , download_creds = False , extra_args = None ) : <EOL> self . setuptestcase ( ) <EOL> self . setup_parser ( ) <EOL> self . parser . add_argument ( "<STR_LIT>" , ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' ) <EOL> self . parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" ) <EOL> self . parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> if extra_args : <EOL> for arg in extra_args : <EOL> self . parser . add_argument ( arg ) <EOL> self . get_args ( ) <EOL> self . tester = Eucaops ( config_file = self . args . config_file , password = self . args . password , download_creds = download_creds ) <EOL> def clean_method ( self ) : <EOL> pass <EOL> def get_repo_url ( self , repo = "<STR_LIT>" , branch = "<STR_LIT>" ) : <EOL> import httplib <EOL> api_host = "<STR_LIT>" <EOL> machine = self . tester . get_component_machines ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> path = "<STR_LIT>" + str ( machine . distro . name ) + "<STR_LIT>" + str ( repo ) + "<STR_LIT>" + str ( branch ) + "<STR_LIT>" <EOL> conn = httplib . HTTPConnection ( api_host ) <EOL> conn . request ( "<STR_LIT:GET>" , path ) <EOL> res = conn . getresponse ( ) <EOL> repo_url = res . read ( ) . strip ( ) <EOL> self . tester . debug ( "<STR_LIT>" + repo + "<STR_LIT>" + repo_url ) <EOL> return repo_url <EOL> def add_euca_repo ( self ) : <EOL> if self . args . branch : <EOL> self . args . euca_url = self . get_repo_url ( "<STR_LIT>" , self . args . branch ) <EOL> for machine in self . tester . config [ "<STR_LIT>" ] : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . add_repo ( self . args . euca_url , "<STR_LIT>" ) <EOL> def add_enterprise_repo ( self ) : <EOL> if self . args . branch : <EOL> self . args . enterprise_url = self . get_repo_url ( "<STR_LIT>" , self . args . branch ) <EOL> for machine in self . tester . config [ "<STR_LIT>" ] : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . add_repo ( self . args . enterprise_url , "<STR_LIT>" ) <EOL> def add_repos ( self ) : <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . add_repo ( self . repo_url , "<STR_LIT>" ) <EOL> machine . package_manager . add_repo ( self . euca2ools_url , "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . add_repo ( self . repo_url , "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . add_repo ( self . repo_url , "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . add_repo ( self . repo_url , "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . package_manager . add_repo ( self . repo_url , "<STR_LIT>" ) <EOL> machine . package_manager . add_repo ( self . euca2ools_url , "<STR_LIT>" ) <EOL> def install_packages ( self ) : <EOL> for machine in self . tester . config [ "<STR_LIT>" ] : <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . package_manager . install ( "<STR_LIT>" ) <EOL> def start_components ( self ) : <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> def stop_components ( self ) : <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> if machine . distro . name is "<STR_LIT>" : <EOL> continue <EOL> machine . sys ( "<STR_LIT>" , timeout = <NUM_LIT> ) <EOL> def initialize_db ( self ) : <EOL> first_clc = self . tester . get_component_machines ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> first_clc . sys ( "<STR_LIT>" ) <EOL> def setup_bridges ( self ) : <EOL> nc_machines = self . tester . get_component_machines ( "<STR_LIT>" ) <EOL> bridge_interface = "<STR_LIT>" <EOL> for nc in nc_machines : <EOL> if nc . distro . name is "<STR_LIT>" : <EOL> return <EOL> nc . sys ( "<STR_LIT>" ) <EOL> nc . sys ( "<STR_LIT>" + bridge_interface + "<STR_LIT>" + bridge_interface ) <EOL> nc . sys ( "<STR_LIT>" ) <EOL> def extend_logical_volume ( self , logical_volume = "<STR_LIT>" , extents = "<STR_LIT>" ) : <EOL> if self . args . root_lv : <EOL> logical_volume = self . args . root_lv <EOL> if self . args . lv_extents : <EOL> logical_volume = self . args . lv_extents <EOL> for machine in self . tester . config [ "<STR_LIT>" ] : <EOL> machine . sys ( "<STR_LIT>" + logical_volume + "<STR_LIT>" + extents ) <EOL> machine . sys ( "<STR_LIT>" + logical_volume , timeout = <NUM_LIT> ) <EOL> def wait_for_creds ( self , timeout = <NUM_LIT> ) : <EOL> def get_creds ( ) : <EOL> try : <EOL> self . tester = Eucaops ( config_file = self . args . config_file , password = self . args . password , download_creds = False ) <EOL> self . tester . get_credentials ( ) <EOL> return True <EOL> except Exception : <EOL> return False <EOL> self . tester . wait_for_result ( get_creds , True , timeout = timeout ) <EOL> def sync_ssh_keys ( self ) : <EOL> clc = self . tester . get_component_machines ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> clc_pub_key = clc . sys ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> for machine in self . tester . get_component_machines ( ) : <EOL> machine . sys ( "<STR_LIT>" + clc_pub_key + "<STR_LIT>" ) <EOL> try : <EOL> for cluster in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" + cluster ) : <EOL> cc_pub_key = machine . sys ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> for nc in self . tester . get_component_machines ( "<STR_LIT>" + cluster ) : <EOL> nc . sys ( "<STR_LIT>" + cc_pub_key + "<STR_LIT>" ) <EOL> except IndexError : <EOL> pass <EOL> def remove_host_check ( self ) : <EOL> for machine in self . tester . get_component_machines ( ) : <EOL> ssh_config_file = '<STR_LIT>' <EOL> ssh_config_file = machine . sftp . open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> ssh_config_file . write ( ssh_config_file ) <EOL> ssh_config_file . close ( ) <EOL> def register_components ( self ) : <EOL> clcs = self . tester . get_component_machines ( "<STR_LIT>" ) <EOL> if len ( clcs ) > <NUM_LIT:1> : <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + clcs [ <NUM_LIT:1> ] . hostname ) <EOL> walrii = self . tester . get_component_machines ( "<STR_LIT>" ) <EOL> for walrus in walrii : <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + walrus . hostname ) <EOL> ccs = self . tester . get_component_machines ( "<STR_LIT>" ) <EOL> registered_clusters = { <NUM_LIT:1> : None , <NUM_LIT:2> : None , <NUM_LIT:3> : None , <NUM_LIT:4> : None , <NUM_LIT:5> : None , <NUM_LIT:6> : None , <NUM_LIT:7> : None , <NUM_LIT:8> : None } <EOL> cluster_number = <NUM_LIT:1> <EOL> for cluster in ccs : <EOL> if not registered_clusters [ cluster_number ] : <EOL> registered_clusters [ cluster_number ] = [ cluster ] <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + str ( cluster_number ) + <EOL> "<STR_LIT>" + str ( cluster_number ) + "<STR_LIT>" + cluster . hostname ) <EOL> cluster_number += <NUM_LIT:1> <EOL> else : <EOL> registered_clusters [ cluster_number - <NUM_LIT:1> ] . append ( cluster ) <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + str ( cluster_number ) + <EOL> "<STR_LIT>" + str ( cluster_number ) + "<STR_LIT>" + cluster . hostname ) <EOL> cluster_number = <NUM_LIT:1> <EOL> scs = self . tester . get_component_machines ( "<STR_LIT>" ) <EOL> registered_scs = { <NUM_LIT:1> : None , <NUM_LIT:2> : None , <NUM_LIT:3> : None , <NUM_LIT:4> : None , <NUM_LIT:5> : None , <NUM_LIT:6> : None , <NUM_LIT:7> : None , <NUM_LIT:8> : None } <EOL> for sc in scs : <EOL> if not registered_scs [ cluster_number ] : <EOL> registered_scs [ cluster_number ] = [ sc ] <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + str ( cluster_number ) + <EOL> "<STR_LIT>" + str ( cluster_number ) + "<STR_LIT>" + sc . hostname ) <EOL> cluster_number += <NUM_LIT:1> <EOL> else : <EOL> registered_scs [ cluster_number - <NUM_LIT:1> ] . append ( sc ) <EOL> clcs [ <NUM_LIT:0> ] . sys ( "<STR_LIT>" + str ( cluster_number - <NUM_LIT:1> ) + <EOL> "<STR_LIT>" + str ( cluster_number - <NUM_LIT:1> ) + "<STR_LIT>" + sc . hostname ) <EOL> try : <EOL> for cluster in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> for nc in self . tester . get_component_machines ( "<STR_LIT>" + cluster ) : <EOL> for cc in self . tester . get_component_machines ( "<STR_LIT>" + cluster ) : <EOL> cc . sys ( "<STR_LIT>" + nc . hostname ) <EOL> except IndexError : <EOL> pass <EOL> def set_block_storage_manager ( self ) : <EOL> if not hasattr ( self . tester , '<STR_LIT>' ) : <EOL> self . tester = Eucaops ( config_file = self . args . config_file , password = self . args . password ) <EOL> enabled_clc = self . tester . service_manager . get_enabled_clc ( ) <EOL> self . zones = self . tester . get_zones ( ) <EOL> for zone in self . zones : <EOL> ebs_manager = "<STR_LIT>" <EOL> if hasattr ( self . args , '<STR_LIT>' ) : <EOL> if re . search ( "<STR_LIT>" , self . args . ebs_storage_manager ) : <EOL> ebs_manager = "<STR_LIT>" <EOL> if re . search ( "<STR_LIT>" , self . args . ebs_storage_manager ) : <EOL> if hasattr ( self . args , '<STR_LIT>' ) : <EOL> if re . search ( "<STR_LIT>" , self . args . san_provider ) : <EOL> ebs_manager = "<STR_LIT>" <EOL> if re . search ( "<STR_LIT>" , self . args . san_provider ) : <EOL> ebs_manager = "<STR_LIT>" <EOL> if re . search ( "<STR_LIT>" , self . args . san_provider ) : <EOL> ebs_manager = "<STR_LIT>" <EOL> else : <EOL> ebs_manager = self . args . block_device_manager <EOL> self . tester . modify_property ( zone + "<STR_LIT>" , ebs_manager ) <EOL> self . tester . modify_property ( zone + "<STR_LIT>" , self . args . root_lv ) <EOL> def set_config_option ( self , machine , option , parameter ) : <EOL> sed_command = '<STR_LIT>' . format ( option , parameter , self . tester . eucapath ) <EOL> machine . sys ( sed_command ) <EOL> def configure_network ( self ) : <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_mode ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_subnet ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_netmask ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_publicips ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_dns ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_addrspernet ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_privinterface ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_pubinterface ) <EOL> for machine in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_mode ) <EOL> self . set_config_option ( machine , "<STR_LIT>" , self . args . vnet_bridge ) <EOL> def configure_edge_dual_subnet ( self ) : <EOL> if re . search ( "<STR_LIT>" , self . tester . config [ "<STR_LIT>" ] , re . IGNORECASE ) : <EOL> if not hasattr ( self . tester , '<STR_LIT>' ) : <EOL> self . tester = Eucaops ( config_file = self . args . config_file , password = self . args . password ) <EOL> enabled_clc = self . tester . service_manager . get_enabled_clc ( ) <EOL> ip_addr_add_command = "<STR_LIT>" <EOL> cc = self . tester . get_component_machines ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> cc_interface = "<STR_LIT>" <EOL> base_ip = self . tester . config [ "<STR_LIT>" ] . strip ( "<STR_LIT:0>" ) <EOL> private_subnet = base_ip + "<STR_LIT:0>" <EOL> cc_gw_ip = base_ip + "<STR_LIT:1>" <EOL> cc . sys ( ip_addr_add_command . format ( cc_gw_ip , cc_interface ) ) <EOL> cc . sys ( "<STR_LIT>" ) <EOL> for node in self . tester . service_manager . get_all_node_controllers ( ) : <EOL> node . sys ( '<STR_LIT>' ) <EOL> ip_index = <NUM_LIT:2> <EOL> for nc in self . tester . get_component_machines ( "<STR_LIT>" ) : <EOL> nc_private_ip = base_ip + str ( ip_index ) <EOL> ip_index += <NUM_LIT:1> <EOL> nc . sys ( ip_addr_add_command . format ( nc_private_ip , "<STR_LIT>" ) ) <EOL> instance_private_ips = [ ] <EOL> for i in xrange ( <NUM_LIT:64> ) : <EOL> instance_private_ips . append ( base_ip + str ( ip_index + i ) ) <EOL> if hasattr ( self . args , "<STR_LIT>" ) : <EOL> public_ips = self . args . vnet_public_ips <EOL> elif "<STR_LIT>" in self . tester . config : <EOL> public_ips = self . tester . config [ "<STR_LIT>" ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ip_list = public_ips . split ( ) <EOL> if len ( ip_list ) > <NUM_LIT:1> : <EOL> public_ips = ip_list <EOL> else : <EOL> public_ips = [ public_ips ] <EOL> network_config = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ enabled_clc . hostname ] , <EOL> "<STR_LIT>" : public_ips , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ { "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:Name>" : private_subnet , <EOL> "<STR_LIT>" : private_subnet , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : cc_gw_ip <EOL> } , <EOL> "<STR_LIT>" : instance_private_ips <EOL> } ] <EOL> } <EOL> self . tester . modify_property ( "<STR_LIT>" , "<STR_LIT:'>" + json . dumps ( network_config ) + "<STR_LIT:'>" ) <EOL> def setup_dns ( self ) : <EOL> if not hasattr ( self . tester , '<STR_LIT>' ) : <EOL> self . tester = Eucaops ( config_file = self . args . config_file , password = self . args . password ) <EOL> self . tester . modify_property ( "<STR_LIT>" , "<STR_LIT:true>" ) <EOL> self . tester . modify_property ( "<STR_LIT>" , "<STR_LIT:true>" ) <EOL> enabled_dns = self . tester . service_manager . get_enabled_dns ( ) <EOL> if self . args . dnsdomain : <EOL> self . tester . modify_property ( "<STR_LIT>" , self . args . dnsdomain ) <EOL> else : <EOL> hostname = self . tester . get_machine_by_ip ( enabled_dns . hostname ) . sys ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> domain = hostname + "<STR_LIT>" <EOL> self . tester . modify_property ( "<STR_LIT>" , domain ) <EOL> self . tester . modify_property ( "<STR_LIT>" , enabled_dns . hostname ) <EOL> def clean_method ( self ) : <EOL> pass <EOL> def InstallEuca ( self ) : <EOL> self . initialize_db ( ) <EOL> self . sync_ssh_keys ( ) <EOL> self . remove_host_check ( ) <EOL> self . configure_network ( ) <EOL> self . start_components ( ) <EOL> self . wait_for_creds ( ) <EOL> self . register_components ( ) <EOL> self . set_block_storage_manager ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testcase = Install ( ) <EOL> test_list = testcase . args . tests or [ "<STR_LIT>" ] <EOL> unit_list = [ ] <EOL> for test in test_list : <EOL> unit_list . append ( testcase . create_testunit_by_name ( test ) ) <EOL> result = testcase . run_test_case_list ( unit_list , clean_on_exit = True ) <EOL> exit ( result ) </s>
