Use ntpq refid to tell if peer controller reaches reliable time source
This is a partial fix only for ipv4. The ntpq.py verify if a valid source is the reference of peer controller when the peer controller is selected as time server. This change will avoid raising false alarm when a controller uses peer controller as time server while the peer uses a reliable time source (e.g, external time server, or accurate time device). Partial-Bug: 1834071 Change-Id: I9140e14b79cb09088c8061a06fae22df97526a70 Signed-off-by: Bin Qian <bin.qian@windriver.com>
This commit is contained in:
parent
13ecf0f821
commit
e5bf093cc8
@ -61,6 +61,7 @@ import collectd
|
||||
from fm_api import constants as fm_constants
|
||||
from fm_api import fm_api
|
||||
import tsconfig.tsconfig as tsc
|
||||
import socket
|
||||
|
||||
api = fm_api.FaultAPIsV2()
|
||||
|
||||
@ -432,6 +433,38 @@ def _is_controller(ip):
|
||||
return False
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Name : _is_ip_address
|
||||
#
|
||||
# Description: This private interface returns:
|
||||
# AF_INET if val is ipv4
|
||||
# AF_INET6 if val is ipv6
|
||||
# False if val is not a valid ip address
|
||||
#
|
||||
# Parameters : val is a uuid string
|
||||
#
|
||||
# Returns : socket.AF_INET for ipv4, socket.AF_INET6 for ipv6
|
||||
# or False for invalid
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
def _is_ip_address(val):
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, val)
|
||||
return socket.AF_INET
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, val)
|
||||
return socket.AF_INET6
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Name : is_uuid_like
|
||||
@ -688,8 +721,9 @@ def read_func():
|
||||
ip = obj.ntpq[i].split(' ')[0][1:]
|
||||
|
||||
elif obj.ntpq[i][0] == '*':
|
||||
# remove the '+' and get the ip
|
||||
ip = obj.ntpq[i].split(' ')[0][1:]
|
||||
# remove the '*' and get the ip
|
||||
cols = obj.ntpq[i].split(' ')
|
||||
ip = cols[0][1:]
|
||||
if ip:
|
||||
if _is_controller(ip) is False:
|
||||
if obj.selected_server:
|
||||
@ -704,9 +738,24 @@ def read_func():
|
||||
collectd.debug("%s selected server is '%s'" %
|
||||
(PLUGIN, obj.selected_server))
|
||||
else:
|
||||
collectd.debug("%s local controller '%s' marked "
|
||||
"as selected server ; ignoring" %
|
||||
(PLUGIN, ip))
|
||||
# refer to peer
|
||||
refid = ''
|
||||
for i in range(1, len(cols)):
|
||||
if cols[i] != '':
|
||||
refid = cols[i]
|
||||
break
|
||||
|
||||
if refid not in ('', '127.0.0.1') and \
|
||||
not _is_controller(refid) and \
|
||||
socket.AF_INET == _is_ip_address(ip):
|
||||
# ipv4, peer controller refer to a time source is not
|
||||
# itself or a controller (this node)
|
||||
obj.selected_server = ip
|
||||
collectd.debug("peer controller has a reliable "
|
||||
"source")
|
||||
else:
|
||||
collectd.debug("peer controller does not have a "
|
||||
"reliable source")
|
||||
|
||||
# anything else is unreachable
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user