Beispiel #1
0
 def test_get_local(self, mock_urlretrieve):
     with tempfile.NamedTemporaryFile() as dl, \
             tempfile.NamedTemporaryFile() as ex:
         mgr = PackageManager(dl.name, ex.name)
         pkg = mgr.get("blah")
         mock_urlretrieve.assert_not_called()
         self.assertEqual(pkg._target, ex.name)
Beispiel #2
0
 def test_get_local(self, mock_urlretrieve):
     with tempfile.NamedTemporaryFile() as dl, \
             tempfile.NamedTemporaryFile() as ex:
         mgr = PackageManager(dl.name, ex.name)
         pkg = mgr.get("blah")
         mock_urlretrieve.assert_not_called()
         self.assertEqual(pkg._target, ex.name)
Beispiel #3
0
 def test_get_remote(self, mock_urlretrieve):
     url = "http://server.eng/thefile.tar"
     with tempfile.NamedTemporaryFile() as dl, \
             tempfile.NamedTemporaryFile() as ex:
         mock_urlretrieve.return_value = (dl.name + "/thefile.tar", None)
         mgr = PackageManager(dl.name, ex.name)
         pkg = mgr.get(url)
         mock_urlretrieve.assert_called_with(url, dl.name)
         self.assertEqual(pkg._target, ex.name)
Beispiel #4
0
 def test_get_remote(self, mock_urlretrieve):
     url = "http://server.eng/thefile.tar"
     tmpdir = "/tmp/mib_downloads/"
     expdir = "/tmp/mib_ex/"
     mock_urlretrieve.return_value = (tmpdir + "/thefile.tar", None)
     mgr = PackageManager(tmpdir, expdir)
     pkg = mgr.get(url)
     mock_urlretrieve.assert_called_with(url, tmpdir + "thefile.tar")
     self.assertEqual(pkg._target, expdir)
Beispiel #5
0
 def test_get_remote(self, mock_urlretrieve):
     url = "http://server.eng/thefile.tar"
     tmpdir = "/tmp/mib_downloads/"
     expdir = "/tmp/mib_ex/"
     mock_urlretrieve.return_value = (tmpdir + "/thefile.tar", None)
     mgr = PackageManager(tmpdir, expdir)
     pkg = mgr.get(url)
     mock_urlretrieve.assert_called_with(url, tmpdir+"thefile.tar")
     self.assertEqual(pkg._target, expdir)
Beispiel #6
0
 def __init__(self, log, dmd, options, mibfiles):
     """
     """
     super(MIBFileProcessor, self).__init__(log, dmd, options)
     self._pkgmgr = PackageManager(options.downloaddir, options.extractdir)
     self._savepath = \
         options.pythoncodedir if options.keeppythoncode else None
     self._mibdepsdir = options.mibdepsdir
     self._mibsdir = options.mibsdir
     self._mibfiles = mibfiles
Beispiel #7
0
 def test_cleanup(self):
     dl = tempfile.mkdtemp()
     ex = tempfile.mkdtemp()
     try:
         mgr = PackageManager(dl, ex)
         mgr.cleanup()
         self.assertFalse(os.path.exists(dl))
         self.assertFalse(os.path.exists(ex))
     finally:
         if os.path.exists(dl):
             shutil.rmtree(dl)
         if os.path.exists(ex):
             shutil.rmtree(ex)
Beispiel #8
0
 def test_cleanup(self):
     dl = tempfile.mkdtemp()
     ex = tempfile.mkdtemp()
     try:
         mgr = PackageManager(dl, ex)
         mgr.cleanup()
         self.assertFalse(os.path.exists(dl))
         self.assertFalse(os.path.exists(ex))
     finally:
         if os.path.exists(dl):
             shutil.rmtree(dl)
         if os.path.exists(ex):
             shutil.rmtree(ex)
Beispiel #9
0
class MIBFileProcessor(BaseProcessor):
    """Load MIB files and add them to the DMD.
    """
    def __init__(self, log, dmd, options, mibfiles):
        """
        """
        super(MIBFileProcessor, self).__init__(log, dmd, options)
        self._pkgmgr = PackageManager(options.downloaddir, options.extractdir)
        self._savepath = \
            options.pythoncodedir if options.keeppythoncode else None
        self._mibdepsdir = options.mibdepsdir
        self._mibsdir = options.mibsdir
        self._mibfiles = mibfiles

    def run(self):
        mibfiles = self._getMIBFiles()
        paths = [zenPath("share", "mibs"), self._mibdepsdir]

        # Add the directories of the MIB-files-to-load to the set of
        # paths to search for MIB file dependencies.
        paths.extend(_unique(os.path.dirname(mf.filename) for mf in mibfiles))

        loaderArgs = (self._moduleMgr, self._organizer)

        with SMIConfigFile(path=paths) as cfg, \
                MIBLoader(*loaderArgs, savepath=self._savepath) as loader:
            tool = SMIDumpTool(config=cfg)
            # returns string containing all the MIB definitions found
            # in the provided set of MIBFile objects.
            dump = tool.run(*mibfiles)
            # for defn in dump.definitions:
            #     print defn
            if dump:
                loader.load(dump)

    def _getMIBFiles(self):
        """Returns a list of files containing the MIBs to load into the DMD.

        @returns {list} List of MIBFile objects.
        """
        sources = self._mibfiles if self._mibfiles else [self._mibsdir]

        mibfiles = []
        for source in sources:
            try:
                pkg = self._pkgmgr.get(source)
                mibfiles.extend(pkg.extract())
            except Exception as ex:
                _logException(self._log, "Invalid argument %s: %s", source, ex)

        mibfiles = list(_unique(mibfiles))

        if mibfiles:
            self._log.debug("Found MIB files to load: %s",
                            ', '.join(str(f) for f in mibfiles))

        return mibfiles
Beispiel #10
0
 def __init__(self, log, dmd, options, mibfiles):
     """
     """
     super(MIBFileProcessor, self).__init__(log, dmd, options)
     self._pkgmgr = PackageManager(options.downloaddir, options.extractdir)
     self._savepath = \
         options.pythoncodedir if options.keeppythoncode else None
     self._mibdepsdir = options.mibdepsdir
     self._mibsdir = options.mibsdir
     self._mibfiles = mibfiles
Beispiel #11
0
class MIBFileProcessor(BaseProcessor):
    """Load MIB files and add them to the DMD.
    """

    def __init__(self, log, dmd, options, mibfiles):
        """
        """
        super(MIBFileProcessor, self).__init__(log, dmd, options)
        self._pkgmgr = PackageManager(options.downloaddir, options.extractdir)
        self._savepath = \
            options.pythoncodedir if options.keeppythoncode else None
        self._mibdepsdir = options.mibdepsdir
        self._mibsdir = options.mibsdir
        self._mibfiles = mibfiles

    def run(self):
        mibfiles = self._getMIBFiles()
        paths = [zenPath("share", "mibs"), self._mibdepsdir]

        # Add the directories of the MIB-files-to-load to the set of
        # paths to search for MIB file dependencies.
        paths.extend(_unique(os.path.dirname(mf.filename) for mf in mibfiles))

        loaderArgs = (self._moduleMgr, self._organizer)

        with SMIConfigFile(path=paths) as cfg, \
                MIBLoader(*loaderArgs, savepath=self._savepath) as loader:
            tool = SMIDumpTool(config=cfg)
            # returns string containing all the MIB definitions found
            # in the provided set of MIBFile objects.
            dump = tool.run(*mibfiles)
            # for defn in dump.definitions:
            #     print defn
            if dump:
                loader.load(dump)

    def _getMIBFiles(self):
        """Returns a list of files containing the MIBs to load into the DMD.

        @returns {list} List of MIBFile objects.
        """
        sources = self._mibfiles if self._mibfiles else [self._mibsdir]

        mibfiles = []
        for source in sources:
            try:
                pkg = self._pkgmgr.get(source)
                mibfiles.extend(pkg.extract())
            except Exception as ex:
                _logException(
                    self._log, "Invalid argument %s: %s", source, ex
                )

        mibfiles = list(_unique(mibfiles))

        if mibfiles:
            self._log.debug(
                "Found MIB files to load: %s",
                ', '.join(str(f) for f in mibfiles)
            )

        return mibfiles