From: Christian Franke Date: Fri, 23 Mar 2018 19:36:56 +0000 (+0100) Subject: lib: check presence of mpls modules, not exitcode of modprobe X-Git-Tag: frr-7.1-dev~151^2~56 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f2d6ce41ca8d50750a4e667efd2a78f617c748c8;p=mirror%2Ffrr.git lib: check presence of mpls modules, not exitcode of modprobe Signed-off-by: Christian Franke --- diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 52b3353f32..8340d9187b 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -132,9 +132,9 @@ class Topogen(object): # Test for MPLS Kernel modules available self.hasmpls = False - if os.system('/sbin/modprobe mpls-router') != 0: + if not topotest.module_present('mpls-router'): logger.info('MPLS tests will not run (missing mpls-router kernel module)') - elif os.system('/sbin/modprobe mpls-iptunnel') != 0: + elif not topotest.module_present('mpls-iptunnel'): logger.info('MPLS tests will not run (missing mpls-iptunnel kernel module)') else: self.hasmpls = True @@ -1039,9 +1039,9 @@ def diagnose_env(): logger.info('LDPd tests will not run (have kernel "{}", but it requires 4.5)'.format(krel)) # Test for MPLS Kernel modules available - if os.system('/sbin/modprobe -n mpls-router') != 0: + if not topotest.module_present('mpls-router', load=False) != 0: logger.info('LDPd tests will not run (missing mpls-router kernel module)') - if os.system('/sbin/modprobe -n mpls-iptunnel') != 0: + if not topotest.module_present('mpls-iptunnel', load=False) != 0: logger.info('LDPd tests will not run (missing mpls-iptunnel kernel module)') # TODO remove me when we start supporting exabgp >= 4 diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index b817766048..11e2a57219 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -265,6 +265,22 @@ def normalize_text(text): text = re.sub(r'\r', '', text) return text +def module_present(module, load=True): + """ + Returns whether `module` is present. + + If `load` is true, it will try to load it via modprobe. + """ + with open('/proc/modules', 'r') as modules_file: + if module.replace('-','_') in modules_file.read(): + return True + cmd = '/sbin/modprobe {}{}'.format('' if load else '-n ', + module) + if os.system(cmd) != 0: + return False + else: + return True + def version_cmp(v1, v2): """ Compare two version strings and returns: @@ -673,9 +689,9 @@ class Router(Node): else: # Test for MPLS Kernel modules available self.hasmpls = False - if os.system('/sbin/modprobe mpls-router') != 0: + if not module_present('mpls-router'): logger.info('MPLS tests will not run (missing mpls-router kernel module)') - elif os.system('/sbin/modprobe mpls-iptunnel') != 0: + elif not module_present('mpls-iptunnel'): logger.info('MPLS tests will not run (missing mpls-iptunnel kernel module)') else: self.hasmpls = True @@ -884,12 +900,12 @@ class Router(Node): if (daemon == 'ldpd'): if version_cmp(platform.release(), '4.5') < 0: return False - if self.cmd('/sbin/modprobe -n mpls-router' ) != "": + if not module_present('mpls-router', load=False): return False - if self.cmd('/sbin/modprobe -n mpls-iptunnel') != "": + if not module_present('mpls-iptunnel', load=False): return False - return True + def get_routertype(self): "Return the type of Router (frr or quagga)"