Add mis-configured netns detection

Change-Id: I904288dddbc0fd607475b0d6d0e4e68c96953a4f
This commit is contained in:
Mohammed Naser 2020-09-07 08:01:02 -04:00
parent 14e08c59fe
commit 12a27195a8
2 changed files with 46 additions and 10 deletions

View File

@ -27,14 +27,46 @@ import time
import os
import psutil
from pyroute2 import NetNS
def get_pid_files(state_path):
"""Get all PID files for Keepalived."""
ha_conf_dir = os.path.join(state_path, 'ha_confs')
pid_glob = os.path.join(ha_conf_dir, '*.pid.keepalived-vrrp')
return glob.glob(pid_glob)
def verify_router_configured(router_id, master):
"""Verify is the router is properly configured on the system."""
namespace = NetNS('qrouter-%s' % router_id)
for link in namespace.get_links():
name = link.get_attr('IFLA_IFNAME')
if name[:3] not in ('qg-', 'qr-'):
continue
addr = namespace.get_addr(label=name)
# Router is not master but addresses are configured.
if master == 0 and len(addr) != 0:
return 0
# Router is master but addresses are not configured.
if master == 1 and len(addr) == 0:
return 0
return 1
def main():
"""Entry-point for script."""
parser = argparse.ArgumentParser()
parser.add_argument("--metric", default="node_openstack_l3_router_master",
help="Name of metric")
parser.add_argument("--prefix", default="node_openstack_l3_router",
help="Prefix of metric")
parser.add_argument("--state", default="/var/lib/neutron",
help="Neutron state path")
parser.add_argument("--loop", type=int, help="Loop every N seconds")
@ -42,12 +74,8 @@ def main():
args = parser.parse_args()
while True:
ha_conf_dir = os.path.join(args.state, 'ha_confs')
pid_glob = os.path.join(ha_conf_dir, '*.pid.keepalived-vrrp')
pid_files = glob.glob(pid_glob)
output = ""
for pid_file in pid_files:
for pid_file in get_pid_files(args.state):
with open(pid_file) as pid_fd:
pid = int(pid_fd.read())
@ -62,8 +90,15 @@ def main():
with open(state_file) as state_fd:
master = 1 if 'master' in state_fd.read() else 0
output += '%s{router_id="%s"} %d\n' % (
args.metric,
configured = verify_router_configured(router_id, master)
output += '%s_configured{router_id="%s"} %d\n' % (
args.prefix,
router_id,
configured
)
output += '%s_master{router_id="%s"} %d\n' % (
args.prefix,
router_id,
master
)

View File

@ -1,2 +1,3 @@
ovs
psutil
psutil
pyroute2