Exemplo n.º 1
0
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(hostname)
    else:
        ssh = get_ssh(hostname)
    rc, stdout, stderr = ssh.exec_command(cmd)
    assert_that(len(stderr) == 0, "create filder content with:{1}, got err:{0}".format(stderr, cmd))
Exemplo n.º 2
0
def step_impl(context,result,hostname):
    cmd = context.text.strip()
    if hostname.startswith("dble"):
        ssh = get_ssh(hostname)
    else:
        ssh = get_ssh(hostname)
    rc, stdout, stderr = ssh.exec_command(cmd)
    context.logger.info("execute cmd:{0}".format(cmd))
    stderr = stderr.lower()
    assert stderr.find("error") == -1, "execute cmd:{0} error:{1}".format(cmd, stderr)
    setattr(context,result,stdout)
Exemplo n.º 3
0
def impl_step(context, host, pattern, resultName):
    if host.startswith('dble'):
        ssh = get_ssh(host)
    else:
        ssh = get_ssh(host)
    oscmd = context.text.strip()
    rc, stdout, stderr = ssh.exec_command(oscmd)
    assert_that(len(stderr) == 0, 'expect no err ,but: {0}'.format(stderr))
    results = list(set(re.findall(pattern, stdout)))
    assert_that(len(results)), "regular matching result is empty"
    context.logger.info("regular matching result:{0}".format(results))
    setattr(context, resultName, results)
Exemplo n.º 4
0
def step_impl(context, filename, hostname):
    cmd = "rm -rf {0}".format(filename)
    ssh = get_ssh(hostname)
    rc, stdout, stderr = ssh.exec_command(cmd)
    assert_that(
        len(stderr) == 0,
        "get err {0} with deleting {1}".format(stderr, filename))
Exemplo n.º 5
0
def step_impl(context, path, hostname, exist_or_not):
    ssh = get_ssh(hostname)
    cmd = "find " + path
    rc, stdout, stderr = ssh.exec_command(cmd)
    logger.debug("rc:{0}, stdout:{1}, stderr:{2}\n".format(rc, stdout, stderr))
    assert (exist_or_not == "not exist"
            and stderr != "") or (exist_or_not == "exist" and stderr == "")
Exemplo n.º 6
0
def get_zk_meta_on_zkCli_sh(context, path, info):
    # zk_method : zk cmd means : ls ,get, rmr, set, config ... etc...you can run help on zkCli.sh for more info
    # /dble/cluster-1/conf/sharding
    # info is function name such as:enum_func
    # hostname is dble-1 ,dble-2,dble-3
    cmd = "cd {0}/bin && ./zkCli.sh get {1}|grep '{2}'".format(
        context.cfg_zookeeper['home'], path, info)
    # node = str(hostname)
    cmd_ssh = get_ssh("dble-1")
    rc, sto, ste = cmd_ssh.exec_command(cmd)
    func_name = []
    assert_that(sto, not_(empty()),
                "sto is not empty and it is : {0}".format(sto))
    LOGGER.debug("the sto is empty : {0}".format(sto))
    outcome_dict = json.loads(sto)
    LOGGER.debug(
        "add debug to check the result of executing {0} is :sto:{1}".format(
            cmd, outcome_dict))
    assert_that(
        outcome_dict, has_key("function"),
        "we have a key named function and they are:{0}".format(outcome_dict))
    LOGGER.debug("{0} function is : {1} ".format(path,
                                                 outcome_dict.get('function')))
    func_list = outcome_dict['function']
    for func_obj in func_list:
        if func_obj.get('name'):
            LOGGER.debug("{0} function is : {1} ".format(
                path, func_obj.get('name')))
            func_name.append(func_obj['name'])
        else:
            LOGGER.debug("there are no keys named name in {0} ".format(path))
    LOGGER.debug("we find function name are : {0}".format(func_name))
    return func_name
Exemplo n.º 7
0
def step_impl(context,btraceScript,host):
    sshClient = get_ssh(host)

    isBtraceRunning = check_btrace_running(sshClient,btraceScript)
    context.logger.info("isBtraceRunning:{0} before try to stop {1}".format(isBtraceRunning,btraceScript))
    if isBtraceRunning:
        stop_btrace(sshClient, btraceScript)
Exemplo n.º 8
0
def step_impl(context,hostname,num=None):
    cmd = context.text.strip()
    ssh = get_ssh(hostname)

    rc, stdout, stderr = ssh.exec_command(cmd)
    stderr =  stderr.lower()
    assert stderr.find("error") == -1, "execute cmd: {0}  err:{1}".format(cmd,stderr)
    if num is not None:
        assert int(stdout) >= int(num), "expect {0} less than result {1} ,but not ".format(num, int(stdout))
Exemplo n.º 9
0
def step_impl(context, filename, hostname):
    ssh = get_ssh(hostname)
    for row in context.table:
        str = row["key"]
        num = row["occur_times"]
        cmd = "grep \'{0}\' {1}|wc -l".format(str, filename)
        rc, stdout, stderr = ssh.exec_command(cmd)
        assert_that(stdout == num,
                    "expect the occur times of \"{0}\" is {1} in {2},but the actual value is {3}".format(str, num, filename,
                                                                                                    stdout))
Exemplo n.º 10
0
def step_impl(context,flag,dirname,hostname):
    strs = context.text.strip()
    strs_list = strs.splitlines()

    ssh = get_ssh(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))
Exemplo n.º 11
0
def check_text(context,flag,filename,hostname,checkFromLine=0):
    strs = context.text.strip()
    strs_list = strs.splitlines()

    ssh = get_ssh(hostname)
    for str in strs_list:
        cmd = "tail -n +{2} {1} | grep -n \'{0}\'".format(str,filename,checkFromLine)
        rc, stdout, stderr = ssh.exec_command(cmd)
        if flag =="N":
            assert_that(len(stdout) == 0,"expect \"{0}\" not exist in file {1},but exist".format(str,filename))
        else:#default take flag as Y
            assert_that(len(stdout) > 0, "expect \"{0}\" exist in file {1},but not".format(str, filename))
Exemplo n.º 12
0
def step_impl(context, host1, role, host2, oscmd='cd /usr/local/mysql/data'):
    user = ''
    password = ''
    port = ''
    if host1.startswith('dble'):
        node = get_node(host1)
        if role == "admin":
            user = node.manager_user
            password = node.manager_password
            port = node.manager_port
        else:
            user = node.client_user
            password = node.client_password
            port = node.client_port
    else:
        node = get_node(host1)
        user = node.mysql_user
        password = node.mysql_password
        port = node.mysql_port
    ip = node.ip

    if host2.startswith('dble'):
        ssh = get_ssh(host2)
    else:
        ssh = get_ssh(host2)

    sql_cmd_str = context.text.strip()
    sql_cmd_list = sql_cmd_str.splitlines()
    context.logger.info("sql list: {0}".format(sql_cmd_list))
    for sql_cmd in sql_cmd_list:
        cmd = '{5} && mysql -h{0} -u{1} -p{2} -P{3} -c -e"{4}"'.format(
            ip, user, password, port, sql_cmd, oscmd)
        stdin, stdout, stderr = ssh.exec_command(cmd)
        context.logger.info("execute cmd:{0}".format(cmd))
        stderr = stderr.lower()
        assert stderr.find("error") == -1, "execute cmd: {0}  err:{1}".format(
            cmd, stderr)
        time.sleep(3)
Exemplo n.º 13
0
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.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)
Exemplo n.º 14
0
def step_impl(context,hostname,num=None,rs_name=None):
    cmd = context.text.strip()
    ssh = get_ssh(hostname)

    if rs_name is not None:
        param_value = getattr(context, rs_name)
        assert param_value, "expect parameter not found in {0}".format(rs_name)
        cmd = cmd.format(param_value)

    rc, stdout, stderr = ssh.exec_command(cmd)
    stderr =  stderr.lower()
    assert stderr.find("error") == -1, "execute cmd: {0}  err:{1}".format(cmd,stderr)
    if num is not None:
        assert int(stdout) >= int(num), "expect {0} less than result {1} ,but not ".format(num, int(stdout))
Exemplo n.º 15
0
def step_impl(context, node, target_file, host_name):
    sshClient = get_ssh(host_name)
    cmd = "cat {0}".format(target_file)
    rc, sto, ste = sshClient.exec_command(cmd)
    tree = ET.fromstring(sto)

    nodeXml = eval(node)

    tag = nodeXml.get("tag")
    targetNodes = tree.findall(tag)
    targetNodes_filtered = get_node_by_keyvalue(targetNodes,
                                                nodeXml.get("kv_map"))
    assert len(targetNodes_filtered) > 0, "can't find {0} in xml {1}".format(
        node, target_file)
Exemplo n.º 16
0
def step_impl(context,file,host):
    sshClient = get_ssh(host)
    retry = 0
    isFound = False
    while retry < 5:
        time.sleep(2)  # a interval wait for query run into
        cmd = "cat {0} | grep '{1}' -c".format(file, context.text.strip())
        rc, sto, ste = sshClient.exec_command(cmd)
        assert len(ste) == 0, "check err:{0}".format(ste)
        isFound = int(sto) == 1
        if isFound:
            context.logger.debug("expect text is found in {0}s".format((retry + 1) * 2))
            break
        retry = retry + 1
    assert isFound, "can not find expect text '{0}' in {1}".format(context.text, file)
Exemplo n.º 17
0
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("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")
Exemplo n.º 18
0
def step_impl(context, host):
    sshClient = get_ssh(host)

    kill_query(sshClient, context.text, context)
Exemplo n.º 19
0
def step_impl(context, path, hostname):
    ssh = get_ssh(hostname)
    cmd = "rm -rf " + path
    rc, stdout, stderr = ssh.exec_command(cmd)
    logging.debug("rc:{0}, stdout:{1}, stderr:{2}\n".format(
        rc, stdout, stderr))
Exemplo n.º 20
0
    def restore(self):
        # if "restore_sys_time" in self._scenario.tags:
        #     utils.restore_sys_time()
        #
        # if "aft_reset_replication" in self._scenario.tags:
        #     utils.reset_repl()
        #
        if "restore_network" in self._scenario.tags:
            params_dic = self.get_tag_params("{'restore_network'")
            logger.debug("params_dic is: {0}".format(params_dic))
            if params_dic:
                paras = params_dic["restore_network"].split(",")
                # paras = paras.split(",")
            else:
                paras = ""

            logger.debug("try to restore_network: {0}".format(paras))
            for host_name in paras:
                logger.debug(
                    "the value of host_name is: {0}".format(host_name))
                cmd = "iptables -F"
                ssh = get_ssh(host_name)
                rc, stdout, stderr = ssh.exec_command(cmd)
                assert_that(
                    len(stderr) == 0,
                    "restore network with command:{1}, got err:{0}".format(
                        stderr, cmd))

        if "restore_view" in self._scenario.tags:
            params_dic = self.get_tag_params("{'restore_view'")
            if params_dic:
                paras = params_dic["restore_view"]
            else:
                paras = {}

            for host_name, mysql_vars in paras.items():
                if host_name.find('dble') != -1:
                    mode = "user"
                else:
                    mode = "mysql"
                for k, v in mysql_vars.items():
                    list_value = filter(lambda x: x, v.split(","))
                    view_value = ""
                    for value in list_value:
                        view_value = view_value + "{0}.{1},".format(k, value)
                    query = "drop view if exists " + view_value

                sql = query[:-1]  #delete the last ','
                # logger.debug("the sql is: {0}".format(sql))
                execute_sql_in_host(host_name, {"sql": sql}, mode)

        if "restore_mysql_service" in self._scenario.tags:
            params_dic = self.get_tag_params("{'restore_mysql_service'")

            if params_dic:
                paras = params_dic["restore_mysql_service"]
            else:
                paras = {}

            logger.debug("try to restore_mysql_service: {0}".format(paras))
            for host_name, mysql_vars in paras.items():
                logger.debug(
                    "the value of host_name is: {0}".format(host_name))
                for k, v in mysql_vars.items():
                    if v:
                        mysql = ObjectFactory.create_mysql_object(host_name)
                        mysql.start()

        if "restore_global_setting" in self._scenario.tags:
            params_dic = self.get_tag_params("{'restore_global_setting'")

            if params_dic:
                paras = params_dic["restore_global_setting"]
            else:
                paras = {}

            logger.debug(
                "try to restore_global_setting of mysqls: {0}".format(paras))

            for mysql, mysql_vars in paras.items():
                query = "set global "
                for k, v in mysql_vars.items():
                    query = query + "{0}={1},".format(k, v)

                sql = query[:-1]  #delete the last ','
                execute_sql_in_host(mysql, {"sql": sql})

        if "restore_mysql_config" in self._scenario.tags:
            params_dic = self.get_tag_params("{'restore_mysql_config'")

            if params_dic:
                paras = params_dic["restore_mysql_config"]
            else:
                paras = {}

            logger.debug(
                "try to restore_mysql_config of mysqls: {0}".format(paras))

            for host_name, mysql_vars in paras.items():
                sed_str = ""
                for k, v in mysql_vars.items():
                    sed_str += "/{0}/d\n/server-id/a {0}={1}\n".format(k, v)

                mysql = ObjectFactory.create_mysql_object(host_name)
                mysql.restart(sed_str)