ipv6流失容灾适配及ping6命令补充适配
This commit is contained in:
parent
4e095945ce
commit
0824825dc5
@ -45,7 +45,9 @@ class CmdUtil(object):
|
||||
ENV_SOURCE_CMD = "source /etc/profile;source ~/.bashrc;" \
|
||||
"if [ $MPPDB_ENV_SEPARATE_PATH ]; " \
|
||||
"then source $MPPDB_ENV_SEPARATE_PATH; fi"
|
||||
|
||||
PING_IPV4_TOOL = "ping"
|
||||
PING_IPV6_TOOL = "ping6"
|
||||
|
||||
@staticmethod
|
||||
def execCmd(cmd, noexcept=False):
|
||||
"""
|
||||
@ -200,12 +202,22 @@ class CmdUtil(object):
|
||||
input : host, count, interval, packet_size
|
||||
output : str
|
||||
"""
|
||||
ping_tool = CmdUtil.PING_IPV4_TOOL
|
||||
if os.getenv("IP_TYPE") == "ipv6":
|
||||
ping_tool = CmdUtil.PING_IPV6_TOOL
|
||||
opts = " "
|
||||
if int(packet_size) != int(56):
|
||||
opts = " -s " + str(packet_size)
|
||||
return CmdUtil.findCmdInPath('ping') + BLANK_SPACE + host + " -c " + \
|
||||
return CmdUtil.findCmdInPath(ping_tool) + BLANK_SPACE + host + " -c " + \
|
||||
count + " -i " + interval + opts
|
||||
|
||||
@staticmethod
|
||||
def get_ping_tool():
|
||||
ping_tool = CmdUtil.PING_IPV4_TOOL
|
||||
if os.getenv("IP_TYPE") == "ipv6":
|
||||
ping_tool = CmdUtil.PING_IPV6_TOOL
|
||||
return ping_tool
|
||||
|
||||
@staticmethod
|
||||
def getWcCmd():
|
||||
"""
|
||||
|
@ -171,6 +171,19 @@ class NetUtil(object):
|
||||
else:
|
||||
return NetUtil.IPV4_SUBMASK_LEN
|
||||
|
||||
@staticmethod
|
||||
def get_ip_cidr_segment(self, ip_address):
|
||||
# Determine the IP type based on the environment variable
|
||||
if os.getenv("IP_TYPE") == NetUtil.NET_IPV4:
|
||||
ip_split = '.'
|
||||
cidr_segment = ".0.0/16" # IPv4 Default subnet segment
|
||||
elif os.getenv("IP_TYPE") == NetUtil.NET_IPV6:
|
||||
ip_split = ':'
|
||||
cidr_segment = "::/64" # IPv6 Default subnet segment
|
||||
else:
|
||||
return ""
|
||||
return ip_split.join(ip_address.split(ip_split)[:2]) + cidr_segment
|
||||
|
||||
@staticmethod
|
||||
def executePingCmd(ip_address):
|
||||
"""
|
||||
|
@ -849,10 +849,10 @@ General options:
|
||||
# add hostname when using root user
|
||||
for _, hostname in result.items():
|
||||
try:
|
||||
host = socket.gethostbyname(hostname)
|
||||
addr_info = socket.getaddrinfo(hostname, None, socket.AF_UNSPEC)
|
||||
except Exception as e:
|
||||
host = ""
|
||||
if host:
|
||||
addr_info = ""
|
||||
if addr_info:
|
||||
hostnameList.append(hostname)
|
||||
for hostname in hostnameList:
|
||||
cmd = '%s;/usr/bin/ssh-keyscan -t ed25519 %s >> %s ' % (SYSTEM_SSH_ENV, hostname, self.known_hosts_fname)
|
||||
|
@ -1714,7 +1714,7 @@ class DefaultValue():
|
||||
"""
|
||||
ping node with short timeout
|
||||
"""
|
||||
cmd = "ping %s -c 1 -w 4" % node_ip
|
||||
cmd = "%s %s -c 1 -w 4" % (CmdUtil.get_ping_tool(), node_ip)
|
||||
proc = FastPopen(cmd, stdout=PIPE, stderr=PIPE, preexec_fn=os.setsid, close_fds=True)
|
||||
proc.communicate()
|
||||
status = proc.returncode
|
||||
@ -1726,7 +1726,8 @@ class DefaultValue():
|
||||
"""
|
||||
Ping on remote node with -I
|
||||
"""
|
||||
cmd = "ping %s -c 1 -w 4" % on_node
|
||||
ping_tool = CmdUtil.get_ping_tool()
|
||||
cmd = "%s %s -c 1 -w 4" % (ping_tool, on_node)
|
||||
proc = FastPopen(cmd, stdout=PIPE, stderr=PIPE,
|
||||
preexec_fn=os.setsid, close_fds=True)
|
||||
proc.communicate()
|
||||
@ -1735,10 +1736,10 @@ class DefaultValue():
|
||||
logger.debug("Node:%s ping failed, can not execute remote check." % on_node)
|
||||
return on_node, False
|
||||
if on_node == NetUtil.GetHostIpOrName():
|
||||
cmd_remote = "ping %s -I %s -c 1 -w 4" % (to_ip, from_ip)
|
||||
cmd_remote = "%s %s -I %s -c 1 -w 4" % (ping_tool, to_ip, from_ip)
|
||||
else:
|
||||
cmd_remote = "source %s && pssh -s -H %s 'ping %s -I %s -c 1 -w 4'" \
|
||||
% (EnvUtil.getMpprcFile(), on_node, to_ip, from_ip)
|
||||
cmd_remote = "source %s && pssh -s -H %s '%s %s -I %s -c 1 -w 4'" \
|
||||
% (EnvUtil.getMpprcFile(), on_node, ping_tool, to_ip, from_ip)
|
||||
proc = FastPopen(cmd_remote, stdout=PIPE, stderr=PIPE,
|
||||
preexec_fn=os.setsid, close_fds=True)
|
||||
proc.communicate()
|
||||
|
@ -548,7 +548,7 @@ class DN_OLAP(Kernel):
|
||||
% (pg_user, dn_ip, subnet_length, METHOD_TRUST)
|
||||
guc_paras_str += "-h \"host all all %s/%s %s\" " \
|
||||
% (dn_ip, subnet_length, METHOD_SHA)
|
||||
ip_segment = '.'.join(dn_ip.split('.')[:2]) + ".0.0/16"
|
||||
ip_segment = NetUtil.get_ip_cidr_segment(dn_ip)
|
||||
guc_paras_str += "-h \"host replication all %s sha256\" " % ip_segment
|
||||
|
||||
if (guc_paras_str != ""):
|
||||
|
@ -148,6 +148,7 @@ class Kernel(BaseComponent):
|
||||
def build(self, buidMode="full", standByBuildTimeout=300):
|
||||
"""
|
||||
"""
|
||||
ping_tool = CmdUtil.get_ping_tool()
|
||||
cmd = "%s/gs_ctl build -D %s -M standby -b %s -r %d " % (
|
||||
self.binPath, self.instInfo.datadir, buidMode, standByBuildTimeout)
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
@ -160,11 +161,11 @@ class Kernel(BaseComponent):
|
||||
raise Exception("cat /etc/hosts failed! cmd: %s; Error: %s " % (hostname_cmd, result))
|
||||
host_list = result.splitlines()
|
||||
for host in host_list:
|
||||
ping_cmd = f"ping {host} -c 5"
|
||||
ping_cmd = f"{ping_tool} {host} -c 5"
|
||||
(status, result) = subprocess.getstatusoutput(ping_cmd)
|
||||
self.logger.debug("cmd is %s; output: %s" % (ping_cmd, result))
|
||||
if status != 0:
|
||||
raise Exception(f"ping {host} failed! {output}")
|
||||
raise Exception(f"{ping_tool} {host} failed! {output}")
|
||||
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +
|
||||
" Error: \n%s " % output)
|
||||
|
||||
|
@ -1462,13 +1462,10 @@ remoteservice={remoteservice}'"\
|
||||
check if network delay greater than 1000ms
|
||||
"""
|
||||
backips = self.context.newHostList
|
||||
ping_tool = CmdUtil.get_ping_tool()
|
||||
for backip in backips:
|
||||
if NetUtil.get_ip_version(backip) == NetUtil.NET_IPV6:
|
||||
ck_net_delay = "ping6 -s 8192 -c 5 -i 0.3 %s | " \
|
||||
"awk -F / '{print $5}'| awk '{print $1}'" % backip
|
||||
else:
|
||||
ck_net_delay = "ping -s 8192 -c 5 -i 0.3 %s | "\
|
||||
"awk -F / '{print $5}'| awk '{print $1}'" % backip
|
||||
ck_net_delay = "%s -s 8192 -c 5 -i 0.3 %s | "\
|
||||
"awk -F / '{print $5}'| awk '{print $1}'" % (ping_tool, backip)
|
||||
(status, output) = subprocess.getstatusoutput(ck_net_delay)
|
||||
if status == 0:
|
||||
try:
|
||||
|
@ -230,8 +230,7 @@ class ConfigHba(LocalBaseOM):
|
||||
"""
|
||||
remove dn & cn pg_hba for streaming stop
|
||||
"""
|
||||
ip_segment_list = list(set(['.'.join(
|
||||
remove_ip.split('.')[:2]) + ".0.0/16" for remove_ip in self.removeIps]))
|
||||
ip_segment_list = list(set([NetUtil.get_ip_cidr_segment(remove_ip) for remove_ip in self.removeIps]))
|
||||
for ip_segment in ip_segment_list:
|
||||
ip_remove_str = "-h \"host replication all %s\" " % ip_segment
|
||||
component.doGUCConfig("set", ip_remove_str, True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user