From 5a1cb3ff2851018d7569008d4055eb5204b08cb7 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Wed, 27 Feb 2019 07:44:31 +0100 Subject: Fix `MibBuilder.loadModules()` no respect missing MIB failure Missing MIB condition has been ignored if MIB compiler is not configured. --- pysnmp/smi/builder.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'pysnmp') diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py index 513bc19a..e2d8d42f 100644 --- a/pysnmp/smi/builder.py +++ b/pysnmp/smi/builder.py @@ -419,23 +419,25 @@ class MibBuilder(object): self.loadModule(modName, **userCtx) except error.MibNotFoundError: - if self._mibCompiler: - debug.logger & debug.FLAG_BLD and debug.logger( - 'loadModules: calling MIB compiler for %s' % modName) + if not self._mibCompiler: + raise + + debug.logger & debug.FLAG_BLD and debug.logger( + 'loadModules: calling MIB compiler for %s' % modName) - status = self._mibCompiler.compile(modName, genTexts=self.loadTexts) + status = self._mibCompiler.compile(modName, genTexts=self.loadTexts) - errs = '; '.join( - hasattr(x, 'error') and str(x.error) or x - for x in status.values() - if x in ('failed', 'missing')) + errs = '; '.join( + hasattr(x, 'error') and str(x.error) or x + for x in status.values() + if x in ('failed', 'missing')) - if errs: - raise error.MibNotFoundError( - '%s compilation error(s): %s' % (modName, errs)) + if errs: + raise error.MibNotFoundError( + '%s compilation error(s): %s' % (modName, errs)) - # compilation succeeded, MIB might load now - self.loadModule(modName, **userCtx) + # compilation succeeded, MIB might load now + self.loadModule(modName, **userCtx) return self -- cgit v1.2.1