def get_dlm_lockspace_max_sys_inode_number(ip_addr, mount_point): """ Return the max inode number of the file system that mounted on the "mount_point" """ uuid = _trans_uuid(get_dlm_lockspace_mp(ip_addr, mount_point)) if not uuid: eprint("\no2locktop: error: can't find the mount point: {0}, please cheack and retry\n" .format(mount_point)) prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "blkid | grep {0}".format(uuid) output = shell.shell(prefix + cmd).output() if len(output) == 1: filesystem = output[0].split()[0].strip()[:-1] if filesystem[-1] == '/': filesystem = filesystem[:-1] else: return None if ip_addr != None: prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "'debugfs.ocfs2 -R \"ls //\" {0}'".format(filesystem) output = shell.shell(prefix + cmd).output() else: cmd = "debugfs.ocfs2 -R \"ls //\" {0}".format(filesystem) output = os.popen(cmd).readlines() if output: return int(output[-1].split()[0]) return None
def get_remote_path(ip_addr): """ Get the remote node's environmet variable PATH """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else '' cmd = "echo '$PATH'" shell_obj = shell.shell(prefix + cmd) ret = shell_obj.output() return ret
def get_one_cat(lockspace, ip=None): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "cat /sys/kernel/debug/ocfs2/{lockspace}/locking_state".format( lockspace=lockspace) sh = shell.shell(prefix + cmd) ret = sh.output() if len(ret) == 0: eprint("{cmd} on {ip} return len=0".format(cmd=cmd, ip=ip)) return ret
def uname_r(ip_addr=None): """ Get the result of command "uname -r" on remote node """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "uname -r" shell_obj = shell.shell(prefix + cmd) ret = shell_obj.output() return ret
def get_dlm_lockspaces(ip=None): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "dlm_tool ls | grep ^name" sh = shell.shell(prefix + cmd) output = sh.output() lockspace_list = [i.split()[1] for i in output] if len(lockspace_list): return lockspace_list return None
def get_dlm_lockspace_mp(ip, mount_point): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "o2info --volinfo {0} | grep UUID".format(mount_point) sh = shell.shell(prefix + cmd) output = sh.output() if (len(output) == 1): if config.UUID == None or config.UUID == "": config.UUID = output[0].split()[1] return output[0].split()[1] return None
def is_passwdless_ssh_set(ip_addr, user="******"): """Check if the remote host is set sshpasswordless for localhost Parameters: ip_addr(str): The node's ip that to be tested user(str): The username for the remote node """ prefix = "ssh -oBatchMode=yes {user}@{ip_addr} ".format(user=user, ip_addr=ip_addr) if ip_addr else '' shell_obj = shell.shell(prefix + "uname") ret = shell_obj.output() return len(ret) != 0
def lockspace_to_device(uuid, ip_addr=None): """ According the uuid to get the major, minor and mount point of the device """ cmd = "cat /sys/kernel/debug/ocfs2/{uuid}/fs_state | grep 'Device =>'"\ .format(uuid=uuid) prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" shell_obj = shell.shell(prefix + cmd) output = shell_obj.output() if not output: err_msg = "\nError while detecting the mount point {uuid} on {ip_addr}\n".format( uuid=uuid, ip_addr=ip_addr) eprint(err_msg) sys.exit(0) # os._exit(0) # return None, None, None #output should be like """ Device => Id: 253,16 Uuid: 7635D31F539A483C8E2F4CC606D5D628 Gen: 0x6434F530 Label: """ dev_major, dev_minor = output[0].split()[3].split(",") # the space must be required cmd = "lsblk -o MAJ:MIN,KNAME,MOUNTPOINT -l | grep '{major}:{minor} '"\ .format(major=dev_major, minor=dev_minor) shell_obj = shell.shell(prefix + cmd) #before grep output should be like """ MAJ:MIN KNAME MOUNTPOINT 253:0 vda 253:1 vda1 [SWAP] 253:2 vda2 / 253:16 vdb /mnt/ocfs2-1 """ #after grep """ 253:16 vdb /mnt/ocfs2-1 """ output = shell_obj.output() assert output # device_name, mount_point = output[0].split()[1:] _, mount_point = output[0].split()[1:] return dev_major, dev_minor, mount_point
def get_one_cat(lockspace, ip_addr=None): """ Cat the locking_state according to the fs uuid(lockspace) and ip """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "cat /sys/kernel/debug/ocfs2/{lockspace}/locking_state".format( lockspace=lockspace) shell_obj = shell.shell(prefix + cmd) ret = shell_obj.output() if not ret and config.DEBUG: eprint("[DEBUG] {cmd} on {ip_addr} return len=0".format(cmd=cmd, ip_addr=ip_addr)) return ret
def get_dlm_lockspaces(ip_addr=None): """ Get the dlm lockspace(fs uuid) of remote ip """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "dlm_tool ls | grep ^name" shell_obj = shell.shell(prefix + cmd) output = shell_obj.output() lockspace_list = [i.split()[1] for i in output] if lockspace_list: return lockspace_list return None
def check_support_debug_v4_and_get_interval(lockspace, ip_addr): """Check if the node support ocfs2 debug information version4 Parameters: lockspace(str): the ocfs2 file system uuid ip_addr(str): The node's ip that to be tested """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else '' cmd = "cat /sys/kernel/debug/ocfs2/{lockspace}/locking_filter".format( lockspace=lockspace) shell_obj = shell.shell(prefix + cmd) ret = shell_obj.output() return ret
def get_remote_cmd_list(ip): path = get_remote_path(ip) prefix = "ssh root@{0} ".format(ip) ret = [] #cmd = 'for i in `echo $PATH|sed "s/:/ /g"`; do ls $i | grep -v "^d"; done' if len(path) == 0: return [] for i in path[0].split(':'): cmd = 'ls {0}'.format(i) sh = shell.shell(prefix + cmd) ret = ret + sh.output() return ret
def is_kernel_ocfs2_fs_stats_enabled(ip=None): uname = uname_r(ip) prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "grep \"CONFIG_OCFS2_FS_STATS=y\" /boot/config-{uname}".format( uname=" ".join(uname)) sh = shell.shell(prefix + cmd) ret = sh.output() if len(ret) == 0: return False if ret[0] == "CONFIG_OCFS2_FS_STATS=y": return True return False
def get_dlm_lockspace_mp(ip_addr, mount_point): """ According the mount point get the lockspace info of remote host and check if the ssh-copy-id is set to the remote node """ prefix = "ssh -oBatchMode=yes -oConnectTimeout=6 root@{0} ".format(ip_addr) if ip_addr else "" cmd = "o2info --volinfo {0} | grep UUID".format(mount_point) shell_obj = shell.shell(prefix + cmd) output = shell_obj.output() if len(output) == 1: if (not config.UUID) or (not config.UUID): config.UUID = output[0].split()[1] return output[0].split()[1] return None
def get_dlm_lockspace_max_sys_inode_number(ip, mount_point): uuid = _trans_uuid(get_dlm_lockspace_mp(ip, mount_point)) if not uuid: eprint( "o2locktop: error: can't find the mount point: {0}, please cheach and retry" .format(mount_point)) prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "blkid | grep {0}".format(uuid) output = shell.shell(prefix + cmd).output() if (len(output) == 1): filesystem = output[0].split()[0].strip()[:-1] if filesystem[-1] == '/': filesystem = filesystem[:-1] else: return None # TODO:fix shell prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "debugfs.ocfs2 -R \"ls //\" {0}".format(filesystem) output = shell.shell(prefix + cmd).output() if len(output) > 0: return int(output[-1].split()[0]) return None
def device_to_mount_points(device, ip=None): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "mount | grep 'type ocfs2'" sh = shell.shell(prefix + cmd) output = sh.output() dev_stat = os.stat(device) dev_num = dev_stat.st_rdev ret = [] for i in output: i = i.split() _dev = i[0] if os.stat(_dev).st_rdev == dev_num: ret.append(i[2]) return list(set(ret))
def lockspace_to_device(uuid, ip=None): cmd = "cat /sys/kernel/debug/ocfs2/{uuid}/fs_state | grep 'Device =>'"\ .format(uuid=uuid) prefix = "ssh root@{0} ".format(ip) if ip else "" sh = shell.shell(prefix + cmd) output = sh.output() if len(output) == 0: err_msg = "\n\nError while detecting the mount point {uuid} on {ip}\n\n".format( uuid=uuid, ip=ip) eprint(err_msg) return #output should be like """ Device => Id: 253,16 Uuid: 7635D31F539A483C8E2F4CC606D5D628 Gen: 0x6434F530 Label: """ dev_major, dev_minor = output[0].split()[3].split(",") # the space must be required cmd = "lsblk -o MAJ:MIN,KNAME,MOUNTPOINT -l | grep '{major}:{minor} '" \ .format(major=dev_major,minor=dev_minor) sh = shell.shell(prefix + cmd) #before grep output should be like """ MAJ:MIN KNAME MOUNTPOINT 253:0 vda 253:1 vda1 [SWAP] 253:2 vda2 / 253:16 vdb /mnt/ocfs2-1 """ #after grep """ 253:16 vdb /mnt/ocfs2-1 """ output = sh.output() assert (len(output) > 0) device_name, mount_point = output[0].split()[1:] return dev_major, dev_minor, mount_point
def get_remote_cmd_list(ip_addr): """ Split the remote node's environmet variable PATH to list array """ path = get_remote_path(ip_addr) prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else '' ret = [] #cmd = 'for i in `echo $PATH|sed "s/:/ /g"`; do ls $i | grep -v "^d"; done' if not path: return [] for i in path[0].split(':'): cmd = 'ls {0}'.format(i) shell_obj = shell.shell(prefix + cmd) ret = ret + shell_obj.output() return ret
def is_kernel_ocfs2_fs_stats_enabled(ip_addr=None): """ Check if the CONFIG_OCFS2_FS_STATS macro is set on remote node """ uname = uname_r(ip_addr) prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "grep \"CONFIG_OCFS2_FS_STATS=y\" /boot/config-{uname}".format( uname=" ".join(uname)) shell_obj = shell.shell(prefix + cmd) ret = shell_obj.output() if not ret: return False if ret[0] == "CONFIG_OCFS2_FS_STATS=y": return True return False
def major_minor_to_device_path(major, minor, ip=None): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "lsblk -o MAJ:MIN,KNAME,MOUNTPOINT -l | grep '{major}:{minor}'"\ .format( major=major,minor=minor) output = shell.shell(prefix + cmd) #output should be like """ MAJ:MIN KNAME 253:0 vda 253:1 vda1 253:2 vda2 253:16 vdb """ assert (len(output) > 0) device_name = output[0].split()[1] return device_name
def set_debug_v4_interval(lockspace, ip_addr, interval=0): """Set ocfs2 filter interval Parameters: lockspace(str): the ocfs2 file system uuid ip_addr(str): The node's ip that to be tested interval(int): The ocfs2 filter interval(will be wrote to locking_filter) """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else '' if ip_addr: cmd = r"echo {interval} \> /sys/kernel/debug/ocfs2/{lockspace}/locking_filter".format( lockspace=lockspace, interval=interval) else: cmd = r"echo {interval} > /sys/kernel/debug/ocfs2/{lockspace}/locking_filter".format( lockspace=lockspace, interval=interval) shell_obj = shell.shell(prefix + cmd) shell_obj.output()
def major_minor_to_device_path(major, minor, ip_addr=None): """ Trans the major,minor pair to the device path """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "lsblk -o MAJ:MIN,KNAME,MOUNTPOINT -l | grep '{major}:{minor}'".format( major=major, minor=minor) output = shell.shell(prefix + cmd).output() #output should be like """ MAJ:MIN KNAME 253:0 vda 253:1 vda1 253:2 vda2 253:16 vdb """ assert output device_name = output[0].split()[1] return device_name
def device_to_mount_points(device, ip_addr=None): """ According the device get the mount point, the fs on the device must be ocfs2 /dev/sda => /mnt/ocfs2 """ prefix = "ssh root@{0} ".format(ip_addr) if ip_addr else "" cmd = "mount | grep 'type ocfs2'" shell_obj = shell.shell(prefix + cmd) output = shell_obj.output() dev_stat = os.stat(device) dev_num = dev_stat.st_rdev ret = [] for i in output: i = i.split() _dev = i[0] if os.stat(_dev).st_rdev == dev_num: ret.append(i[2]) return list(set(ret))
def uname_r(ip=None): prefix = "ssh root@{0} ".format(ip) if ip else "" cmd = "uname -r" sh = shell.shell(prefix + cmd) ret = sh.output() return ret
def get_remote_path(ip): prefix = "ssh root@{0} ".format(ip) cmd = "echo '$PATH'" sh = shell.shell(prefix + cmd) ret = sh.output() return ret