Skip to content

Commit

Permalink
Merge pull request #15 from opensourcerouting/tgen-diag
Browse files Browse the repository at this point in the history
topotest diagnostics
  • Loading branch information
mwinter-osr authored Jul 21, 2017
2 parents dd75b48 + 4f8b97c commit 535b887
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 31 deletions.
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer1/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 1 10";
run "/etc/exabgp/exa-send.py 1 10";
}

process receive-routes {
run "./exa-receive.py 1";
run "/etc/exabgp/exa-receive.py 1";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer2/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 2 10";
run "/etc/exabgp/exa-send.py 2 10";
}

process receive-routes {
run "./exa-receive.py 2";
run "/etc/exabgp/exa-receive.py 2";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer3/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 3 10";
run "/etc/exabgp/exa-send.py 3 10";
}

process receive-routes {
run "./exa-receive.py 3";
run "/etc/exabgp/exa-receive.py 3";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer4/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 4 10";
run "/etc/exabgp/exa-send.py 4 10";
}

process receive-routes {
run "./exa-receive.py 4";
run "/etc/exabgp/exa-receive.py 4";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer5/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 5 10";
run "/etc/exabgp/exa-send.py 5 10";
}

process receive-routes {
run "./exa-receive.py 5";
run "/etc/exabgp/exa-receive.py 5";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer6/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 6 10";
run "/etc/exabgp/exa-send.py 6 10";
}

process receive-routes {
run "./exa-receive.py 6";
run "/etc/exabgp/exa-receive.py 6";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer7/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 7 10";
run "/etc/exabgp/exa-send.py 7 10";
}

process receive-routes {
run "./exa-receive.py 7";
run "/etc/exabgp/exa-receive.py 7";
receive-routes;
encoder text;
}
Expand Down
4 changes: 2 additions & 2 deletions bgp_multiview_topo1/peer8/exabgp.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group controller {

process announce-routes {
run "./exa-send.py 8 10";
run "/etc/exabgp/exa-send.py 8 10";
}

process receive-routes {
run "./exa-receive.py 8";
run "/etc/exabgp/exa-receive.py 8";
receive-routes;
encoder text;
}
Expand Down
7 changes: 6 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Topotest conftest.py file.
"""

from lib.topogen import get_topogen
from lib.topogen import get_topogen, diagnose_env
from lib.topotest import json_cmp_result
import pytest

Expand Down Expand Up @@ -40,3 +40,8 @@ def pytest_assertrepr_compare(op, left, right):
return None

return json_result.errors

def pytest_configure(config):
"Assert that the environment is correctly configured."
if not diagnose_env():
pytest.exit('enviroment has errors, please read the logs')
154 changes: 146 additions & 8 deletions lib/topogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import ConfigParser
import glob
import grp
import platform
import pwd
import re
import subprocess

from mininet.net import Mininet
from mininet.log import setLogLevel
Expand Down Expand Up @@ -78,6 +82,15 @@ def set_topogen(tgen):
# Main class: topology builder
#

# Topogen configuration defaults
tgen_defaults = {
'verbosity': 'info',
'frrdir': '/usr/lib/frr',
'quaggadir': '/usr/lib/quagga',
'routertype': 'frr',
'memleak_path': None,
}

class Topogen(object):
"A topology test builder helper."

Expand Down Expand Up @@ -130,14 +143,7 @@ def _load_config(self):
Loads the configuration file `pytest.ini` located at the root dir of
topotests.
"""
defaults = {
'verbosity': 'info',
'frrdir': '/usr/lib/frr',
'quaggadir': '/usr/lib/quagga',
'routertype': 'frr',
'memleak_path': None,
}
self.config = ConfigParser.ConfigParser(defaults)
self.config = ConfigParser.ConfigParser(tgen_defaults)
pytestini_path = os.path.join(CWD, '../pytest.ini')
self.config.read(pytestini_path)

Expand Down Expand Up @@ -836,3 +842,135 @@ def start(self, peer_dir, env_file=None):
def stop(self):
"Stop ExaBGP peer and kill the daemon"
self.run('kill `cat /var/run/exabgp/exabgp.pid`')


#
# Diagnostic function
#

# Disable linter branch warning. It is expected to have these here.
# pylint: disable=R0912
def diagnose_env():
"""
Run diagnostics in the running environment. Returns `True` when everything
is ok, otherwise `False`.
"""
ret = True
logger.info('Running environment diagnostics')

# Load configuration
config = ConfigParser.ConfigParser(tgen_defaults)
pytestini_path = os.path.join(CWD, '../pytest.ini')
config.read(pytestini_path)

# Assert that we are running as root
if os.getuid() != 0:
logger.error('you must run topotest as root')
ret = False

# Assert that we have mininet
if os.system('which mn >/dev/null 2>/dev/null') != 0:
logger.error('could not find mininet binary (mininet is not installed)')
ret = False

# Assert that we have iproute installed
if os.system('which ip >/dev/null 2>/dev/null') != 0:
logger.error('could not find ip binary (iproute is not installed)')
ret = False

# Assert that we have gdb installed
if os.system('which gdb >/dev/null 2>/dev/null') != 0:
logger.error('could not find gdb binary (gdb is not installed)')
ret = False

# Assert that FRR utilities exist
frrdir = config.get('topogen', 'frrdir')
hasfrr = False
if not os.path.isdir(frrdir):
logger.error('could not find {} directory'.format(frrdir))
ret = False
else:
hasfrr = True
try:
pwd.getpwnam('frr')[2]
except KeyError:
logger.warning('could not find "frr" user')

try:
grp.getgrnam('frr')[2]
except KeyError:
logger.warning('could not find "frr" group')

try:
if 'frr' not in grp.getgrnam('frrvty').gr_mem:
logger.error('"frr" user and group exist, but user is not under "frrvty"')
except KeyError:
logger.warning('could not find "frrvty" group')

for fname in ['zebra', 'ospfd', 'ospf6d', 'bgpd', 'ripd', 'ripngd',
'isisd', 'pimd', 'ldpd']:
path = os.path.join(frrdir, fname)
if not os.path.isfile(path):
# LDPd is an exception
if fname == 'ldpd':
logger.info('could not find {} in {}'.format(fname, frrdir) +
'(LDPd tests will not run)')
continue

logger.warning('could not find {} in {}'.format(fname, frrdir))
ret = False

# Assert that Quagga utilities exist
quaggadir = config.get('topogen', 'quaggadir')
if hasfrr:
# if we have frr, don't check for quagga
pass
elif not os.path.isdir(quaggadir):
logger.info('could not find {} directory (quagga tests will not run)'.format(quaggadir))
else:
ret = True
try:
pwd.getpwnam('quagga')[2]
except KeyError:
logger.info('could not find "quagga" user')

try:
grp.getgrnam('quagga')[2]
except KeyError:
logger.info('could not find "quagga" group')

try:
if 'quagga' not in grp.getgrnam('quaggavty').gr_mem:
logger.error('"quagga" user and group exist, but user is not under "quaggavty"')
except KeyError:
logger.warning('could not find "quaggavty" group')

for fname in ['zebra', 'ospfd', 'ospf6d', 'bgpd', 'ripd', 'ripngd',
'isisd', 'pimd']:
path = os.path.join(quaggadir, fname)
if not os.path.isfile(path):
logger.warning('could not find {} in {}'.format(fname, quaggadir))
ret = False

if not os.path.isdir('/tmp'):
logger.warning('could not find /tmp for logs')

# Test MPLS availability
krel = platform.release()
if topotest.version_cmp(krel, '4.5') < 0:
logger.info('LDPd tests will not run (have kernel "{}", but it requires 4.5)'.format(krel))

# TODO remove me when we start supporting exabgp >= 4
try:
output = subprocess.check_output(['exabgp', '-v'])
line = output.split('\n')[0]
version = line.split(' ')[2]
if topotest.version_cmp(version, '4') >= 0:
logger.warning('BGP topologies are still using exabgp version 3, expect failures')

# We want to catch all exceptions
# pylint: disable=W0702
except:
logger.warning('failed to find exabgp or returned error')

return ret
9 changes: 3 additions & 6 deletions lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,10 @@ def startRouter(self):
if not os.path.isfile(ldpd_path):
logger.warning("LDP Test, but no ldpd compiled or installed")
return "LDP Test, but no ldpd compiled or installed"
kernel_version = re.search(r'([0-9]+)\.([0-9]+).*', platform.release())

if kernel_version:
if (float(kernel_version.group(1)) < 4 or
(float(kernel_version.group(1)) == 4 and float(kernel_version.group(2)) < 5)):
logger.warning("LDP Test need Linux Kernel 4.5 minimum")
return "LDP Test need Linux Kernel 4.5 minimum"
if version_cmp(platform.release(), '4.5') < 0:
logger.warning("LDP Test need Linux Kernel 4.5 minimum")
return "LDP Test need Linux Kernel 4.5 minimum"

self.cmd('/sbin/modprobe mpls-router')
self.cmd('/sbin/modprobe mpls-iptunnel')
Expand Down

0 comments on commit 535b887

Please sign in to comment.