]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/PyModule: put mgr_module_path first in sys.path 26777/head
authorTim Serong <tserong@suse.com>
Mon, 25 Feb 2019 03:47:12 +0000 (14:47 +1100)
committerPrashant D <pdhange@redhat.com>
Wed, 6 Mar 2019 04:28:18 +0000 (23:28 -0500)
If the various python site packages appear first in sys.path, and there
happens to be a package whose name is the same as an mgr module, mgr will
try to load that thing instead of the expected mgr module.  This results
in a very terse couple of errors:

  mgr[py] Class not found in module 'deepsea'
  mgr[py] Error loading module 'deepsea': (22) Invalid argument

Before this commit, sys.path on my SLE 11 SP1 dev system is:

  /usr/lib/python36.zip
  /usr/lib64/python3.6
  /usr/lib64/python3.6
  /usr/lib64/python3.6/lib-dynload
  /usr/lib64/python3.6/site-packages
  /usr/lib/python3.6/site-packages
  /usr/local/lib64/python3.6/site-packages
  /usr/local/lib/python3.6/site-packages
  /usr/lib64/ceph/mgr

After this commit, /usr/share/ceph/mgr comes before python's site-packages,
and everything works properly:

  /usr/lib/python36.zip
  /usr/lib64/python3.6
  /usr/lib64/python3.6
  /usr/lib64/python3.6/lib-dynload
  /usr/share/ceph/mgr
  /usr/lib64/python3.6/site-packages
  /usr/lib/python3.6/site-packages
  /usr/local/lib64/python3.6/site-packages
  /usr/local/lib/python3.6/site-packages

(If you're interested in seeing what's in sys.path, turn "debug mgr" up
to at least 10, then grep the logs for "Computed sys.path")

Fixes: https://tracker.ceph.com/issues/38469
Signed-off-by: Tim Serong <tserong@suse.com>
(cherry picked from commit 7e34b27676e12c1333c5f34ef1b561c8713cddbd)

Conflicts:
src/mgr/PyModule.cc : Resolved in load

src/mgr/PyModule.cc

index 65656d0a60a864ced379399089e14d73f622f0c4..0f9932fddf3e4f84473d071abec953201607fd5a 100644 (file)
@@ -336,8 +336,8 @@ int PyModule::load(PyThreadState *pMainThreadState)
       PySys_SetArgv(1, (char**)argv);
 #endif
       // Configure sys.path to include mgr_module_path
-      string paths = (":" + get_site_packages() +
-                     ":" + g_conf->get_val<std::string>("mgr_module_path"));
+      string paths = (":" + g_conf->get_val<std::string>("mgr_module_path") +
+                     ":" + get_site_packages());
 #if PY_MAJOR_VERSION >= 3
       wstring sys_path(Py_GetPath() + wstring(begin(paths), end(paths)));
       PySys_SetPath(const_cast<wchar_t*>(sys_path.c_str()));