def step_impl(context, fildername,hostname): cmd = "mkdir {0}".format(fildername) context.logger.info("sed cmd is :{0}".format(cmd)) if hostname.startswith('dble'): ssh = get_ssh(context.dbles, hostname) else: ssh = get_ssh(context.mysqls, hostname) rc, stdout, stderr = ssh.exec_command(cmd) assert_that(len(stderr) == 0, "create filder content with:{1}, got err:{0}".format(stderr, cmd))
def update_file_content(context,filename, hostname): sed_cmd_str = context.text.strip() sed_cmd_list = sed_cmd_str.splitlines() sed_cmd = "sed -i" for cmd in sed_cmd_list: sed_cmd += " -e '{0}'".format(cmd.strip()) sed_cmd += " {0}".format(filename) context.logger.info("sed cmd is :{0}".format(sed_cmd)) if hostname.startswith('dble'): ssh = get_ssh(context.dbles,hostname) else: ssh = get_ssh(context.mysqls, hostname) rc, stdout, stderr = ssh.exec_command(sed_cmd) assert_that(len(stderr)==0, "update file content with:{1}, got err:{0}".format(stderr, sed_cmd))
def check_cluster_successd(context, expectNodes): if not hasattr(context, "retry_check_zk_nodes"): context.retry_check_zk_nodes = 0 context.check_zk_nodes_success = False realNodes = [] cmd = "cd {0}/bin && ./zkCli.sh ls /dble/cluster-1/online|grep -v ':'|grep -v ^$ ".format(context.cfg_zookeeper['home']) cmd_ssh = get_ssh(context.dbles, "dble-1") rc, sto, ste = cmd_ssh.exec_command(cmd) LOGGER.debug("add debug to check the result of executing {0} is :sto:{1}".format(cmd,sto)) sub_sto = re.findall(r'[[](.*)[]]', sto) LOGGER.debug("add debug to check the result of sub_sto is :{0}".format(sub_sto)) nodes = sub_sto[0].replace(",", " ").split() LOGGER.debug("add debug to check the result of nodes is:{0}".format(nodes)) for id in nodes: LOGGER.info("id:{0}".format(id)) hostname = "dble-{0}".format(id) realNodes.append(hostname) if (expectNodes == realNodes): context.check_zk_nodes_success = True if not context.check_zk_nodes_success: if context.retry_check_zk_nodes < 10: context.retry_check_zk_nodes = context.retry_check_zk_nodes + 1 time.sleep(10) check_cluster_successd(context, expectNodes) else: LOGGER.info("The online dbles detected by zk do not meet expectations after 10 times try,expectNodes:{0},realNodes:{1}".format(expectNodes, realNodes)) delattr(context, "retry_check_zk_nodes") else: delattr(context, "retry_check_zk_nodes")
def step_impl(context,flag,dirname,hostname): strs = context.text.strip() strs_list = strs.splitlines() ssh = get_ssh(context.dbles, hostname) for str in strs_list[1:]: cmd = "find {0} -name {1}".format(dirname, str) rc, stdout, stderr = ssh.exec_command(cmd) if flag == "not": assert_that(len(stdout) == 0, "expect \"{0}\" not exist in dir {1},but exist".format(str, dirname)) else: assert_that(len(stdout) > 0, "expect \"{0}\" exist in dir {1},but not".format(str, dirname))
def step_impl(context, filename): # remove file in behave resides server if os.path.exists(filename): os.remove(filename) # remove file in dble cmd = "rm -rf {0}".format(filename) rc, stdout, stderr = context.ssh_client.exec_command(cmd) assert len(stderr)==0, "rm file in dble fail for {0}".format(stderr) # remove file in compare mysql dble_node_ssh = get_ssh(context.mysqls, context.cfg_mysql['compare_mysql']['master1']['hostname']) rc, stdout, stderr = dble_node_ssh.exec_command(cmd) assert len(stderr)==0, "rm file in compare mysql fail for {0}".format(stderr)
def reset_zk_nodes(context): resetCmd = "cd {0}/zookeeper/bin && sh zkCli.sh rmr /dble".format( context.cfg_dble["install_dir"]) ssh_client = get_ssh(context.dbles, "dble-1") ssh_client.exec_command(resetCmd)
def step_impl(context,filename,hostname): cmd = "rm -rf {0}".format(filename) ssh = get_ssh(context.dbles,hostname) rc, stdout, stderr = ssh.exec_command(cmd) assert_that(len(stderr)==0 ,"get err {0} with deleting {1}".format(stderr,filename))