def change_instance_binaries(self, instance): script = test_bash_script_error() script += build_change_mongodb_conf_file_script() script += build_stop_database_script(clean_data=False) script += build_clean_data_data_script() script += build_start_database_script() script += build_wait_admin_be_created_script() script += td_agent_script(option='restart') context_dict = {} script = build_context_script(context_dict, script) output = {} host = instance.hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def do(self, workflow_dict): try: for source_host in workflow_dict['source_hosts']: future_host = source_host.future_host hosts_option = [(source_host, 'stop'), (future_host, 'start')] for host, option in hosts_option: LOG.info("Starting td_agent on host {}".format(host)) cs_host_attr = CS_HostAttr.objects.get(host=host) context_dict = {} script = test_bash_script_error() script += build_mk_heartbeat_daemon_script(option) script = build_context_script(context_dict, script) LOG.info(script) output = {} return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: LOG.error("Error starting mysql_statsd") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: option = 'restart' for host in workflow_dict['hosts']: LOG.info("{} monit on host {}".format(option, host)) cs_host_attr = CS_HostAttr.objects.get(host=host) script = test_bash_script_error() script += td_agent_script(option) LOG.info(script) output = {} sleep(30) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: LOG.error("Error monit") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: for host in workflow_dict['target_hosts']: cs_host_attr = CS_HostAttr.objects.get(host=host) script = test_bash_script_error() script += build_uncomment_skip_slave_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def change_slave_priority_file(host, original_value, final_value): script = test_bash_script_error() script += """ sed -i 's/slave-priority {}/slave-priority {}/g' /data/redis.conf """.format(original_value, final_value) script = build_context_script({}, script) host.ssh.run_script(script)
def change_instance_binaries(self, instance, connect_string, run_authschemaupgrade): script = test_bash_script_error() script += util.build_cp_mongodb_binary_file() script += util.build_stop_database_script(clean_data=False) script += util.build_change_release_alias_script() script += util.build_start_database_script(wait_time=30) script += util.build_change_limits_script() script += util.build_remove_reprecated_index_counter_metrics() if run_authschemaupgrade: script += util.build_authschemaupgrade_script() context_dict = { 'SOURCE_PATH': '/mnt/software/db/mongodb', 'TARGET_PATH': '/usr/local/', 'MONGODB_RELEASE_FILE': 'mongodb-linux-x86_64-3.0.8.tgz', 'MONGODB_RELEASE_FOLDER': 'mongodb-linux-x86_64-3.0.8', 'CONNECT_STRING': connect_string, } script = build_context_script(context_dict, script) output = {} host = instance.hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def do(self, workflow_dict): try: host = workflow_dict['source_hosts'][0] databaseinfra = workflow_dict['databaseinfra'] cs_host_attr = CS_HostAttr.objects.get(host=host) context_dict = { 'MASTERPAIRNAME': databaseinfra.name, } script = test_bash_script_error() script += build_turn_flipper_ip_down_script() script = build_context_script(context_dict, script) output = {} return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: option = 'start' for host in workflow_dict['hosts']: LOG.info("{} monit on host {}".format(option, host)) cs_host_attr = CS_HostAttr.objects.get(host=host) script = test_bash_script_error() script += monit_script(option) LOG.info(script) output = {} return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: LOG.error("Error monit") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: for source_host in workflow_dict['source_hosts']: future_host = source_host.future_host hosts_option = [(future_host, 'stop')] for host, option in hosts_option: LOG.info("{} td_agent on host {}".format(option, host)) cs_host_attr = CS_HostAttr.objects.get(host=host) script = test_bash_script_error() script += monit_script(option) script += td_agent_script(option) LOG.info(script) output = {} return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: LOG.error("Error stopping td_agent") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: for source_host in workflow_dict['source_hosts']: host = source_host.future_host LOG.info("Starting td_agent on host {}".format(host)) cs_host_attr = CS_HostAttr.objects.get(host=host) context_dict = {} script = test_bash_script_error() script += build_start_td_agent_script() script = build_context_script(context_dict, script) LOG.info(script) output = {} return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: LOG.error("Error starting td_agent") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self): LOG.info("Start monit on host {}".format(self.host)) script = test_bash_script_error() script += self.host.commands.monit_script(action='start') LOG.info(script) self.host.ssh.run_script(script)
def do(self, workflow_dict): try: for index, instance in enumerate( workflow_dict['target_instances']): if instance.instance_type == instance.MONGODB_ARBITER: continue if instance.instance_type == instance.REDIS_SENTINEL: continue host = instance.hostname LOG.info("Mounting disks on host {}".format(host)) cs_host_attr = CS_HostAttr.objects.get(host=host) nfs_host_attr = NFS_HostAttr.objects.get(host=host) LOG.info("Cheking host ssh...") host_ready = check_ssh(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, wait=5, interval=10) if not host_ready: raise Exception(str("Host %s is not ready..." % host)) context_dict = { 'EXPORTPATH': nfs_host_attr.nfsaas_path, } script = test_bash_script_error() script += build_mount_disk_script() script = build_context_script(context_dict, script) LOG.info(script) output = {} return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def change_slave_priority_file(host, original_value, final_value): script = test_bash_script_error() script += """ sed -i 's/slave-priority {}/slave-priority {}/g' /data/redis.conf """.format(original_value, final_value) script = build_context_script({}, script) output = {} return_code = exec_remote_command_host(host, script, output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'], databaseinfra=databaseinfra) client = databaseinfra.get_driver().get_client(None) rsconf = client.local.system.replset.find_one() member_ids = [] for member in rsconf['members']: member_ids.append(member['_id']) max_member_id = max(member_ids) secundary_one_member_id = max_member_id + 1 secundary_two_member_id = max_member_id + 2 arbiter_member_id = max_member_id + 3 context_dict = { 'CONNECT_STRING': connect_string, 'SECUNDARY_ONE': "{}:{}".format(workflow_dict['target_instances'][0].address, workflow_dict['target_instances'][0].port), 'SECUNDARY_TWO': "{}:{}".format(workflow_dict['target_instances'][1].address, workflow_dict['target_instances'][1].port), 'ARBITER': "{}:{}".format(workflow_dict['target_instances'][2].address, workflow_dict['target_instances'][2].port), 'SECUNDARY_ONE_MEMBER_ID': secundary_one_member_id, 'SECUNDARY_TWO_MEMBER_ID': secundary_two_member_id, 'ARBITER_MEMBER_ID': arbiter_member_id, } script = test_bash_script_error() script += build_add_replica_set_members_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'], databaseinfra=databaseinfra) context_dict = { 'CONNECT_STRING': connect_string, } script = test_bash_script_error() script += build_switch_primary_to_new_instances_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) sleep(30) driver = databaseinfra.get_driver() client = driver.get_client(instance=None) rsconf = client['local'].system.replset.find_one() priority_0 = rsconf['members'][0].get('priority', 1) priority_1 = rsconf['members'][1].get('priority', 1) if priority_0 != 0 or priority_1 != 0: errormsg = "The priority of the old mongodb instances should be zero." LOG.error(errormsg) raise Exception(errormsg) replSetGetStatus = client.admin.command('replSetGetStatus') if 'PRIMARY' not in (replSetGetStatus['members'][3]['stateStr'], replSetGetStatus['members'][4]['stateStr']): errormsg = "One of the new instances should be PRIMARY." LOG.error(errormsg) raise Exception(errormsg) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def failover_sentinel(host, sentinel_host, sentinel_port, service_name): LOG.info('Failover of Sentinel {}:{}'.format(sentinel_host, sentinel_port)) script = test_bash_script_error() script += """ /usr/local/redis/src/redis-cli -h {} -p {} <<EOF_DBAAS SENTINEL failover {} exit \nEOF_DBAAS die_if_error "Error reseting sentinel" """.format(sentinel_host, sentinel_port, service_name) script = build_context_script({}, script) host.ssh.run_script(script)
def do(self, workflow_dict): try: for index, instance in enumerate(workflow_dict['target_instances']): if instance.instance_type == instance.MONGODB_ARBITER: continue if instance.instance_type == instance.REDIS_SENTINEL: continue host = instance.hostname LOG.info("Mounting disks on host {}".format(host)) cs_host_attr = CS_HostAttr.objects.get(host=host) nfs_host_attr = NFS_HostAttr.objects.get(host=host) LOG.info("Cheking host ssh...") host_ready = check_ssh(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, wait=5, interval=10) if not host_ready: raise Exception(str("Host %s is not ready..." % host)) context_dict = { 'EXPORTPATH': nfs_host_attr.nfsaas_path, } script = test_bash_script_error() script += build_mount_disk_script() script = build_context_script(context_dict, script) LOG.info(script) output = {} return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: instances = workflow_dict['instances'] databaseinfra = workflow_dict['databaseinfra'] connect_string = util.build_mongodb_connect_string(instances=instances, databaseinfra=databaseinfra) script = test_bash_script_error() script += util.build_cp_mongodb_binary_file() script += util.build_stop_database_script(clean_data=False) script += util.build_change_release_alias_script() script += util.build_start_database_script() script += util.build_authschemaupgrade_script() script += util.build_change_limits_script() script += util.build_change_in_serverstatus_file_script() script += util.build_reinstal_mongo_gen_script() script += util.build_remove_reprecated_index_counter_metrics() context_dict = { 'SOURCE_PATH': '/mnt/software/db/mongodb', 'TARGET_PATH': '/usr/local/', 'MONGODB_RELEASE_FILE': 'mongodb-linux-x86_64-3.0.8.tgz', 'MONGODB_RELEASE_FOLDER': 'mongodb-linux-x86_64-3.0.8', 'CONNECT_STRING': connect_string, } script = build_context_script(context_dict, script) output = {} host = instances[0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0023) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] target_instances = [] for source_instance in workflow_dict['source_instances']: target_instances.append(source_instance.future_instance) connect_string = build_mongodb_connect_string( instances=target_instances, databaseinfra=databaseinfra) context_dict = { 'CONNECT_STRING': connect_string, 'SECUNDARY_ONE': "{}:{}".format(workflow_dict['source_instances'][0].address, workflow_dict['source_instances'][0].port), 'SECUNDARY_TWO': "{}:{}".format(workflow_dict['source_instances'][1].address, workflow_dict['source_instances'][1].port), 'ARBITER': "{}:{}".format(workflow_dict['source_instances'][2].address, workflow_dict['source_instances'][2].port), } script = test_bash_script_error() script += build_remove_replica_set_members_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] driver = databaseinfra.get_driver() sentinel = driver.get_sentinel_client() master = sentinel.discover_master(databaseinfra.name) master_host = master[0] master_port = master[1] for index, source_host in enumerate(workflow_dict['source_hosts']): target_host = source_host.future_host target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) script = test_bash_script_error() script += build_start_stop_scripts() if index < 2: script += build_start_database_script() script += build_start_sentinel_script() script += build_start_http_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) for target_instance in workflow_dict['target_instances']: if target_instance.instance_type == target_instance.REDIS: LOG.info( 'Changing master of host: {}'.format(target_instance.address)) client = driver.get_client(target_instance) client.slaveof(master_host, master_port) LOG.info( 'New master: {}:{}'.format(master_host, master_port)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self): LOG.info("Start monit on host {}".format(self.host)) script = test_bash_script_error() action = 'start' script += monit_script(action) LOG.info(script) output = {} return_code = exec_remote_command_host(self.host, script, output) LOG.info(output) if return_code != 0: LOG.error("Error starting monit") LOG.error(str(output))
def do(self, workflow_dict): try: backup_log_dict = get_backup_log_configuration_dict( environment=workflow_dict['target_environment'], databaseinfra=workflow_dict['databaseinfra']) if backup_log_dict is None: LOG.info( "There is not any backup log configuration for this database..." ) return True for index, instance in enumerate( workflow_dict['target_instances']): if instance.instance_type == instance.MONGODB_ARBITER: continue if instance.instance_type == instance.REDIS_SENTINEL: continue host = instance.hostname LOG.info("Getting vm credentials...") host_csattr = CsHostAttr.objects.get(host=host) script = test_bash_script_error() script += build_backup_log_script() contextdict = backup_log_dict script = build_context_script(contextdict, script) output = {} return_code = exec_remote_command( server=host.address, username=host_csattr.vm_user, password=host_csattr.vm_password, command=script, output=output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0014) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: instances = workflow_dict['instances'] databaseinfra = workflow_dict['databaseinfra'] connect_string = util.build_mongodb_connect_string( instances=instances, databaseinfra=databaseinfra) script = test_bash_script_error() script += util.build_cp_mongodb_binary_file() script += util.build_stop_database_script(clean_data=False) script += util.build_change_release_alias_script() script += util.build_start_database_script() script += util.build_authschemaupgrade_script() script += util.build_addrole_mongo3_script() script += util.build_change_limits_script() context_dict = { 'SOURCE_PATH': '/mnt/software/db/mongodb', 'TARGET_PATH': '/usr/local/', 'MONGODB_RELEASE_FILE': 'mongodb-linux-x86_64-3.0.12.tgz', 'MONGODB_RELEASE_FOLDER': 'mongodb-linux-x86_64-3.0.12', 'CONNECT_STRING': connect_string, } script = build_context_script(context_dict, script) output = {} host = instances[0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0023) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: flipper_crdentials = get_credentials_for(workflow_dict['source_environment'], CredentialType.FLIPPER) flipper_vip = flipper_crdentials.get_parameter_by_name('vip') for host in workflow_dict['target_hosts']: cs_host_attr = CS_HostAttr.objects.get(host=host) source_host = workflow_dict['source_hosts'][0] nf_host_attr = NF_HostAttr.objects.get(host=source_host) script = test_bash_script_error() script += build_mount_snapshot_volume_script() script += build_remove_deprecated_files_script() script += build_permission_script() script += build_start_database_script() script += build_flipper_script() context_dict = { 'EXPORT_PATH': nf_host_attr.nfsaas_path, 'SNAPSHOPT_NAME': workflow_dict['snapshot_name'], 'VIP_FLIPPER': flipper_vip, 'IPWRITE': workflow_dict['target_secondary_ips'][0].ip, 'HOST01': workflow_dict['target_hosts'][0], 'HOST02': workflow_dict['target_hosts'][1] } script = build_context_script(context_dict, script) output = {} LOG.info(script) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: flipper_crdentials = get_credentials_for( workflow_dict['source_environment'], CredentialType.FLIPPER) flipper_vip = flipper_crdentials.get_parameter_by_name('vip') for host in workflow_dict['target_hosts']: cs_host_attr = CS_HostAttr.objects.get(host=host) source_host = workflow_dict['source_hosts'][0] nf_host_attr = NF_HostAttr.objects.get(host=source_host) script = test_bash_script_error() script += build_mount_snapshot_volume_script() script += build_remove_deprecated_files_script() script += build_permission_script() script += build_start_database_script() script += build_flipper_script() context_dict = { 'EXPORT_PATH': nf_host_attr.nfsaas_path, 'SNAPSHOPT_NAME': workflow_dict['snapshot_name'], 'VIP_FLIPPER': flipper_vip, 'IPWRITE': workflow_dict['target_secondary_ips'][0].ip, 'HOST01': workflow_dict['target_hosts'][0], 'HOST02': workflow_dict['target_hosts'][1] } script = build_context_script(context_dict, script) output = {} LOG.info(script) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] driver = databaseinfra.get_driver() sentinel = driver.get_sentinel_client() master = sentinel.discover_master(databaseinfra.name) master_host = master[0] master_port = master[1] for index, source_host in enumerate(workflow_dict['source_hosts']): target_host = source_host.future_host target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) script = test_bash_script_error() script += build_start_stop_scripts() if index < 2: script += build_start_database_script() script += build_start_sentinel_script() script += build_start_http_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) for target_instance in workflow_dict['target_instances']: if target_instance.instance_type == target_instance.REDIS: LOG.info('Changing master of host: {}'.format(target_instance.address)) client = driver.get_client(target_instance) client.slaveof(master_host, master_port) LOG.info('New master: {}:{}'.format(master_host, master_port)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] target_instances = [] for source_instance in workflow_dict['source_instances']: target_instances.append(source_instance.future_instance) connect_string = build_mongodb_connect_string(instances=target_instances, databaseinfra=databaseinfra) context_dict = { 'CONNECT_STRING': connect_string, 'SECUNDARY_ONE': "{}:{}".format(workflow_dict['source_instances'][0].address, workflow_dict['source_instances'][0].port), 'SECUNDARY_TWO': "{}:{}".format(workflow_dict['source_instances'][1].address, workflow_dict['source_instances'][1].port), 'ARBITER': "{}:{}".format(workflow_dict['source_instances'][2].address, workflow_dict['source_instances'][2].port), } script = test_bash_script_error() script += build_remove_replica_set_members_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) for source_instance in workflow_dict['source_instances']: source_instance.delete() LOG.info("Source instance deleted") return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict["databaseinfra"] for index, source_host in enumerate(workflow_dict["source_hosts"]): source_cs_host_attr = CS_HostAttr.objects.get(host=source_host) script = test_bash_script_error() script += build_start_stop_scripts() if index < 2: script += build_stop_database_script() script += build_stop_sentinel_script() script += build_start_http_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command( server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, command=script, output=output, ) LOG.info(output) if return_code != 0: raise Exception(str(output)) for source_instance in workflow_dict["source_instances"]: if source_instance.instance_type == source_instance.REDIS_SENTINEL: target_instance = source_instance.future_instance reset_sentinel( host=target_instance.hostname, sentinel_host=target_instance.address, sentinel_port=target_instance.port, service_name=databaseinfra.name, ) sleep(30) return True except Exception: traceback = full_stack() workflow_dict["exceptions"]["error_codes"].append(DBAAS_0020) workflow_dict["exceptions"]["traceback"].append(traceback) return False
def change_slave_priority_file(host, original_value, final_value): host_attr = HostAttr.objects.get(host=host) script = test_bash_script_error() script += """ sed -i 's/slave-priority {}/slave-priority {}/g' /data/redis.conf """.format(original_value, final_value) script = build_context_script({}, script) output = {} return_code = exec_remote_command(server=host.address, username=host_attr.vm_user, password=host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def failover_sentinel(host, sentinel_host, sentinel_port, service_name): LOG.info('Failover of Sentinel {}:{}'.format(sentinel_host, sentinel_port)) script = test_bash_script_error() script += """ /usr/local/redis/src/redis-cli -h {} -p {} <<EOF_DBAAS SENTINEL failover {} exit \nEOF_DBAAS die_if_error "Error reseting sentinel" """.format(sentinel_host, sentinel_port, service_name) script = build_context_script({}, script) output = {} return_code = exec_remote_command_host(host, script, output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def do(self, workflow_dict): try: backup_log_dict = get_backup_log_configuration_dict(environment=workflow_dict['environment'], databaseinfra=workflow_dict['databaseinfra']) if backup_log_dict is None: LOG.info("There is not any backup log configuration for this database...") return True for index, instance in enumerate(workflow_dict['instances']): if instance.instance_type == instance.MONGODB_ARBITER: continue if instance.instance_type == instance.REDIS_SENTINEL: continue host = instance.hostname LOG.info("Getting vm credentials...") host_csattr = CsHostAttr.objects.get(host=host) script = test_bash_script_error() script += build_backup_log_script() contextdict = backup_log_dict script = build_context_script(contextdict, script) output = {} return_code = exec_remote_command(server=host.address, username=host_csattr.vm_user, password=host_csattr.vm_password, command=script, output=output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0014) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: target_host_zero = workflow_dict['source_hosts'][0].future_host target_host_one = workflow_dict['source_hosts'][1].future_host databaseinfra = workflow_dict['databaseinfra'] cs_host_attr = CS_HostAttr.objects.get(host=target_host_zero) context_dict = { 'MASTERPAIRNAME': databaseinfra.name, 'HOST01': target_host_zero, 'HOST02': target_host_one, } script = test_bash_script_error() script += build_set_flipper_ips_script() script = build_context_script(context_dict, script) output = {} return_code = exec_remote_command( server=target_host_zero.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) databaseinfraattr = workflow_dict[ 'source_secondary_ips'][0].equivalent_dbinfraattr databaseinfra = workflow_dict['databaseinfra'] databaseinfra.endpoint = databaseinfraattr.ip + ":3306" databaseinfra.save() return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: databaseinfra = workflow_dict['databaseinfra'] for index, source_host in enumerate(workflow_dict['source_hosts']): source_cs_host_attr = CS_HostAttr.objects.get(host=source_host) script = test_bash_script_error() script += build_start_stop_scripts() if index < 2: script += build_stop_database_script() script += build_stop_sentinel_script() script += build_start_http_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) for source_instance in workflow_dict['source_instances']: if source_instance.instance_type == source_instance.REDIS_SENTINEL: target_instance = source_instance.future_instance reset_sentinel(host=target_instance.hostname, sentinel_host=target_instance.address, sentinel_port=target_instance.port, service_name=databaseinfra.name) sleep(30) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: target_host_zero = workflow_dict['source_hosts'][0].future_host target_host_one = workflow_dict['source_hosts'][1].future_host databaseinfra = workflow_dict['databaseinfra'] cs_host_attr = CS_HostAttr.objects.get(host=target_host_zero) context_dict = { 'MASTERPAIRNAME': databaseinfra.name, 'HOST01': target_host_zero, 'HOST02': target_host_one, } script = test_bash_script_error() script += build_set_flipper_ips_script() script = build_context_script(context_dict, script) output = {} return_code = exec_remote_command( server=target_host_zero.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) databaseinfraattr = workflow_dict['source_secondary_ips'][ 0].equivalent_dbinfraattr databaseinfra = workflow_dict['databaseinfra'] databaseinfra.endpoint = databaseinfraattr.ip + ":3306" databaseinfra.save() return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: instances = workflow_dict['instances'] script = test_bash_script_error() script += build_change_mongodb_conf_file_script() script += build_stop_database_script(clean_data=False) script += build_clean_data_data_script() script += build_start_database_script() script += build_mongorestore_database_script() script += build_enable_authentication_single_instance_script() script += build_restart_database_script() script += td_agent_script(option='restart') context_dict = {} script = build_context_script(context_dict, script) output = {} host = instances[0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0023) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: for host in workflow_dict['target_hosts']: cs_host_attr = CS_HostAttr.objects.get(host=host) source_host = workflow_dict['source_hosts'][0] nf_host_attr = NF_HostAttr.objects.get(host=source_host) script = test_bash_script_error() script += build_mount_snapshot_volume_script() script += build_remove_deprecated_files_script() script += build_permission_script() script += build_start_database_script() context_dict = { 'EXPORT_PATH': nf_host_attr.nfsaas_path, 'SNAPSHOPT_NAME': workflow_dict['snapshot_name'], } script = build_context_script(context_dict, script) output = {} LOG.info(script) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def failover_sentinel(host, sentinel_host, sentinel_port, service_name): LOG.info('Failover of Sentinel {}:{}'.format(sentinel_host, sentinel_port)) host_attr = HostAttr.objects.get(host=host) script = test_bash_script_error() script += """ /usr/local/redis/src/redis-cli -h {} -p {} <<EOF_DBAAS SENTINEL failover {} exit \nEOF_DBAAS die_if_error "Error reseting sentinel" """.format(sentinel_host, sentinel_port, service_name) script = build_context_script({}, script) output = {} return_code = exec_remote_command(server=host.address, username=host_attr.vm_user, password=host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output))
def undo(self, workflow_dict): LOG.info("Running undo...") try: databaseinfra = workflow_dict['databaseinfra'] for index, source_host in enumerate(workflow_dict['source_hosts']): target_host = source_host.future_host target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) script = test_bash_script_error() script += build_start_stop_scripts() script += build_stop_sentinel_script() if index < 2: script += build_stop_database_script() script = build_context_script({}, script) output = {} exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) for source_instance in workflow_dict['source_instances']: if source_instance.instance_type == source_instance.REDIS_SENTINEL: reset_sentinel(host=source_instance.hostname, sentinel_host=source_instance.address, sentinel_port=source_instance.port, service_name=databaseinfra.name) sleep(30) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def undo(self, workflow_dict): LOG.info("Running undo...") try: databaseinfra = workflow_dict['databaseinfra'] connect_string = build_mongodb_connect_string( instances=workflow_dict['source_instances'], databaseinfra=databaseinfra) context_dict = { 'CONNECT_STRING': connect_string, } script = test_bash_script_error() script += build_switch_primary_to_old_instances_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command( server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: option = 'start' for host in workflow_dict['hosts']: LOG.info("{} monit on host {}".format(option, host)) script = test_bash_script_error() script += monit_script(option) LOG.info(script) output = {} return_code = exec_remote_command_host(host, script, output) LOG.info(output) if return_code != 0: LOG.error("Error monit") LOG.error(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0002) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: instances = workflow_dict['instances'] script = test_bash_script_error() script += build_disable_authentication_single_instance_script() script += build_restart_database_script() script += build_dump_database_script() context_dict = { } script = build_context_script(context_dict, script) output = {} host = instances[0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0023) workflow_dict['exceptions']['traceback'].append(traceback) return False
def undo(self, workflow_dict): LOG.info("Running undo...") try: databaseinfra = workflow_dict['databaseinfra'] connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'], databaseinfra=databaseinfra) context_dict = { 'CONNECT_STRING': connect_string, } script = test_bash_script_error() script += build_switch_primary_to_old_instances_script() script = build_context_script(context_dict, script) output = {} host = workflow_dict['source_instances'][0].hostname cs_host_attr = CS_HostAttr.objects.get(host=host) return_code = exec_remote_command(server=host.address, username=cs_host_attr.vm_user, password=cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: flipper_fox_migration_dir = Configuration.get_by_name( 'flipper_fox_migration_dir') if not flipper_fox_migration_dir: flipper_fox_migration_dir = '/tmp' workflow_dict['flipper_fox_migration_dir_infra_name'] = "{}/{}".format( flipper_fox_migration_dir, workflow_dict['databaseinfra'].name) for index, source_instance in enumerate(workflow_dict['source_instances']): source_host = source_instance.hostname source_cs_host_attr = CS_HostAttr.objects.get(host=source_host) hostname = source_host.hostname.split('.')[0] localpath = "{}/{}".format( workflow_dict['flipper_fox_migration_dir_infra_name'], hostname) os.makedirs(localpath) LOG.info('Get source host files to {}'.format(localpath)) if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/my.cnf".format(localpath), remotepath="/etc/my.cnf"): raise Exception("FTP Error") target_host = source_host.future_host LOG.info(target_host) target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/my.cnf".format(localpath), remotepath="/etc/my.cnf"): raise Exception("FTP Error") script = test_bash_script_error() script += build_server_id_conf_script() context_dict = { 'SERVERID': index + 5, } script = build_context_script(context_dict, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) shutil.rmtree(workflow_dict['flipper_fox_migration_dir_infra_name']) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def script(self): return test_bash_script_error() + """
def do(self, workflow_dict): try: region_migration_dir = Configuration.get_by_name('region_migration_dir') if not region_migration_dir: region_migration_dir = '/tmp' workflow_dict['region_migration_dir_infra_name'] = "{}/{}".format(region_migration_dir, workflow_dict['databaseinfra'].name) for index, source_instance in enumerate(workflow_dict['source_instances']): source_host = source_instance.hostname source_cs_host_attr = CS_HostAttr.objects.get(host=source_host) hostname = source_host.hostname.split('.')[0] localpath = "{}/{}".format(workflow_dict['region_migration_dir_infra_name'], hostname) os.makedirs(localpath) LOG.info('Get source host files to {}'.format(localpath)) if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/mongodb.key".format(localpath), remotepath="/data/mongodb.key"): raise Exception("FTP Error") if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/mongodb.conf".format(localpath), remotepath="/data/mongodb.conf"): raise Exception("FTP Error") if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/td-agent.conf".format(localpath), remotepath="/etc/td-agent/td-agent.conf"): raise Exception("FTP Error") target_host = source_host.future_host LOG.info(target_host) target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) target_instance = source_instance.future_instance if target_instance.instance_type == target_instance.MONGODB_ARBITER: LOG.info("Cheking host ssh...") host_ready = check_ssh(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, wait=5, interval=10) if not host_ready: raise Exception(str("Host %s is not ready..." % target_host)) if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/mongodb.key".format(localpath), remotepath="/data/mongodb.key"): raise Exception("FTP Error") if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/mongodb.conf".format(localpath), remotepath="/data/mongodb.conf"): raise Exception("FTP Error") if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/td-agent.conf".format(localpath), remotepath="/etc/td-agent/td-agent.conf"): raise Exception("FTP Error") script = test_bash_script_error() script += build_permission_script() script += build_start_database_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) shutil.rmtree(workflow_dict['region_migration_dir_infra_name']) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: LOG.info("Getting cloudstack credentials...") statsd_credentials = get_credentials_for( environment=workflow_dict['target_environment'], credential_type=CredentialType.STATSD) statsd_host, statsd_port = statsd_credentials.endpoint.split(':') databaseinfra = workflow_dict['databaseinfra'] sentinel = databaseinfra.get_driver().get_sentinel_client() master = sentinel.discover_master(databaseinfra.name) master_host = master[0] master_port = master[1] for index, source_host in enumerate(workflow_dict['source_hosts']): target_host = source_host.future_host LOG.info(target_host) target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) if index == 2: LOG.info("Cheking host ssh...") host_ready = check_ssh(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, wait=5, interval=10) if not host_ready: raise Exception( str("Host %s is not ready..." % target_host)) script = test_bash_script_error() script += build_permission_script() script = build_context_script({}, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) instances_redis = Instance.objects.filter(hostname=target_host, instance_type=Instance.REDIS) instances_sentinel = Instance.objects.filter(hostname=target_host, instance_type=Instance.REDIS_SENTINEL) if instances_redis: only_sentinel = False instance_redis_address = instances_redis[0].address instance_redis_port = instances_redis[0].port else: only_sentinel = True instance_redis_address = '' instance_redis_port = '' if instances_sentinel: instance_sentinel_address = instances_sentinel[0].address instance_sentinel_port = instances_sentinel[0].port else: instance_sentinel_address = '' instance_sentinel_port = '' contextdict = { 'DATABASENAME': workflow_dict['database'].name, 'DBPASSWORD': databaseinfra.password, 'HOSTADDRESS': instance_redis_address, 'PORT': instance_redis_port, 'ENGINE': 'redis', 'HOST': source_host.hostname.split('.')[0], 'STATSD_HOST': statsd_host, 'STATSD_PORT': statsd_port, 'IS_HA': databaseinfra.plan.is_ha, 'SENTINELMASTER': master_host, 'SENTINELMASTERPORT': master_port, 'SENTINELADDRESS': instance_sentinel_address, 'SENTINELPORT': instance_sentinel_port, 'MASTERNAME': databaseinfra.name, 'ONLY_SENTINEL': only_sentinel, } planattr = PlanAttr.objects.get( plan=workflow_dict['source_plan']) script = build_context_script( contextdict, planattr.configuration_script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) if index < 2: change_slave_priority_file(host=target_host, original_value=100, final_value=0) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self, workflow_dict): try: region_migration_dir = Configuration.get_by_name('region_migration_dir') if not region_migration_dir: region_migration_dir = '/tmp' workflow_dict['region_migration_dir_infra_name'] = "{}/{}".format(region_migration_dir, workflow_dict['databaseinfra'].name) for index, source_instance in enumerate(workflow_dict['source_instances']): source_host = source_instance.hostname source_cs_host_attr = CS_HostAttr.objects.get(host=source_host) hostname = source_host.hostname.split('.')[0] localpath = "{}/{}".format(workflow_dict['region_migration_dir_infra_name'], hostname) os.makedirs(localpath) LOG.info('Get source host files to {}'.format(localpath)) if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/my.cnf".format(localpath), remotepath="/etc/my.cnf"): raise Exception("FTP Error") if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/mysql_statsd.conf".format(localpath), remotepath="/etc/mysql_statsd/mysql_statsd.conf"): raise Exception("FTP Error") if not scp_get_file(server=source_host.address, username=source_cs_host_attr.vm_user, password=source_cs_host_attr.vm_password, localpath="{}/td-agent.conf".format(localpath), remotepath="/etc/td-agent/td-agent.conf"): raise Exception("FTP Error") target_host = source_host.future_host LOG.info(target_host) target_cs_host_attr = CS_HostAttr.objects.get(host=target_host) if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/my.cnf".format(localpath), remotepath="/etc/my.cnf"): raise Exception("FTP Error") if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/mysql_statsd.conf".format(localpath), remotepath="/etc/mysql_statsd/mysql_statsd.conf"): raise Exception("FTP Error") if not scp_put_file(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, localpath="{}/td-agent.conf".format(localpath), remotepath="/etc/td-agent/td-agent.conf"): raise Exception("FTP Error") script = test_bash_script_error() script += build_server_id_conf_script() context_dict = { 'SERVERID': index + 3, } script = build_context_script(context_dict, script) output = {} LOG.info(script) return_code = exec_remote_command(server=target_host.address, username=target_cs_host_attr.vm_user, password=target_cs_host_attr.vm_password, command=script, output=output) LOG.info(output) if return_code != 0: raise Exception(str(output)) shutil.rmtree(workflow_dict['region_migration_dir_infra_name']) return True except Exception: traceback = full_stack() workflow_dict['exceptions']['error_codes'].append(DBAAS_0020) workflow_dict['exceptions']['traceback'].append(traceback) return False
def do(self): script = test_bash_script_error() script += build_remove_read_only_replica_set_member_script() self._execute_script(self.script_variables, script)
def do(self): script = test_bash_script_error() script += self.base_script self._execute_script(self.script_variables, script)
def do(self): script = test_bash_script_error() script += build_change_priority_script(len(self.infra.instances.all())) self._execute_script(self.script_variables, script)