Fresh out of the Christmas/New Year vacation I yesterday received this question from one of my colleagues:
I am trying to set up a demo to show MDC at FKOM. I am trying to configure MDC via the Python script method – although I have an issue where I am missing a file – the error from the convertMDC.Py script says “no module named ConfigMgr.Py”
I remember you demoed this method at the Architecture Summit in Sydney – did you come across this issue?”
Now as I was on my way to see the very nice Andy Warhol – Ai Weiwei exhibition currently on display in Melbourne, I couldn’t logon to my test system to look into the issue.
Due to my “root-cause-analysis reflex” from my stint in SAP support, I followed up today and was able to verify my initial hypothesis: there must be a search path setting not quite right.
These are the steps I took:
1. check the convertMDC.py file:
The first two lines in this Python file are
import os, time, sys, subprocess, getopt import ConfigMgrPy
which is where the error message comes from.
Python is trying to load the listed modules but fails with the ConfigMgr module.
Checking the Python documentation I figured out that there are a couple of places Python looks for the modules.
One option to specify these places is the environment variable PYTHONPATH. Therefore I checked this variable on my system:
2. check PYTHONPATH environment variable:
>echo $PYTHONPATH /usr/sap/T07/SYS/global/hdb/custom/python_support:/usr/sap/T07/HDB07/exe/python_support:/usr/sap/T07/HDB07/dewdftzldc05:/usr/sap/T07/HDB07/exe:/usr/sap/T07/HDB07/exe/testscripts
Reformatting this string gave me this list:
/usr/sap/T07/SYS/global/hdb/custom/python_support /usr/sap/T07/HDB07/exe/python_support /usr/sap/T07/HDB07/dewdftzldc05 /usr/sap/T07/HDB07/exe /usr/sap/T07/HDB07/exe/testscripts
Nice, but didn’t really gain a lot of insight here…
3. Checking the path from within Python:
In hindsight this should have been the first thing to do, but hey, I am thinking and learning on my feet here…
> python Python 2.7.10 (sap:1, Jul 6 2015, 10:21:20) [GCC 4.7.2 20130108 [gcc-4_7-branch revision 195014]] on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "/etc/pythonstart", line 7, in <module> import readline ImportError: No module named readline
I decided to ignore this error message. Not sure why this happens on my system!
From the Python documentation I knew that I need the sys module for further investigation, so I load this and print the current search path via sys.path:
>>> import sys >>> sys.path ['', '/usr/sap/T07/SYS/global/hdb/custom/python_support', '/usr/sap/T07/HDB07/exe/python_support', '/usr/sap/T07/HDB07/dewdftzldc05', '/usr/sap/T07/HDB07/exe', '/usr/sap/T07/HDB07/exe/testscripts', '/usr/sap/T07/HDB07/exe/Python/lib/python27.zip', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7/plat-linux2', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7/lib-tk', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7/lib-old', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7/lib-dynload', '/usr/sap/T07/HDB07/exe/Python/lib/python2.7/site-packages'] >>>
Ok, so there we find all our PYTHONPATH folders as well as some other folders that seem to belong to the Python installation.
4. Load the missing module
Now I thought: “Hey, lets try and load this module manually!”
>>> import ConfigMgr
Ok, no error message so far.
Then the following should work!
>>> dir (ConfigMgrPy) ['CUSTOMER', 'Configuration', 'ConfigurationException', 'HOST', 'LayeredConfiguration', 'READONLY', 'RemoteConfig', '__doc__', '__file__', '__name__', '__package__', 'createUUID', 'expandProfileVars', 'getDaemonInfo', 'getLinkInfo', 'getRootPath', 'sapgparam', 'stringToBool']
Geeze, I am such a great Python hacker… *cough* 😐
But where does the module come from?
Easy as pie:
>>> ConfigMgrPy <module 'ConfigMgrPy' from '/usr/sap/T07/HDB07/exe/ConfigMgrPy.so'>
5. ALL WRONG – this only works on a system where you DON’T have the problem!
Clearly, my fancy schmanzy root cause analysis would not have helped my colleague, because on his system Python didn’t find the module in the first place.
So what to do in this case?
I’d say, looking for the ConfigMgrPy file or folder or whatever Python loads for modules might be a good idea.
Since there is no hint in the Python documentation that ConfigMgr belongs to the standard Python stuff, I have to assume that it belongs to SAP HANA.
Which limits the search area for the object to the SAP HANA installation folders.
On my system that would be the /usr/sap/<SID>/ folder.
Searching for files on Linux always makes me google for examples and this is what I came up with this time:
find -L /usr/sap/T07 -name 'ConfigMgr*'
“So far so good, but what’s the -L for?” you might ask.
When trying this thing out on my system, I didn’t use the -L immediately and found… nothing at all.
Only after trying a couple of name pattern that definitively should have yielded some hits it dawned on me that there might be something else preventing the find program to find the files.
And in fact, find does not follow symbolic links in files systems by default.
Looking into the installation folder on my system I can see that symbolic links are what we use for SAP HANA:
ls -la /usr/sap/T07 total 16 drwxr-xr-x 4 t07adm sapsys 4096 Apr 15 2015 . drwxr-xr-x 17 root sapsys 4096 Dec 10 18:30 .. lrwxrwxrwx 1 t07adm sapsys 22 Apr 15 2015 HDB07 -> /hana/shared/T07/HDB07 [...]
Means: without the -L option, find doesn’t go down this path.
Having figured this out, find of course gave me what I was looking for:
find -L /usr/sap/T07 -name 'ConfigMgr*' /usr/sap/T07/SYS/exe/hdb/ConfigMgrPy.so /usr/sap/T07/HDB07/exe/ConfigMgrPy.so
And with this information my colleague could have modified the PYTHONPATH variable on his system to fix the problem (which he wrote me is what he has done meanwhile anyhow…).
There you go – now you know.
Happy New Year everyone and have a great 2016!