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 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: 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: 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: 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: 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