Broken imports from custom modules

295 views
Skip to first unread message

ende...@gmail.com

unread,
Feb 11, 2021, 10:44:44 AM2/11/21
to Salt-users
I'm in the processing of trying to upgrade from salt 3000.5 to 3002.2 on a CentOS 7 machine.  In testing the new version I discovered my custom state is broken due, I believe, to changes in the way imports are being handled.  

I have the files:
/srv/salt/_satess/asdt/__init__.py
/srv/salt/_states/asdt/Pkg.py

In __init__.py I have "from _Pkg import parsePkg"

Prior to upgrading to 3002 this worked and my state did its thing.  Since upgrading I now get:

[DEBUG   ] Failed to import states asdt:
Traceback (most recent call last):
 File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1686, in _load_module
   mod = spec.loader.load_module()
 File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
 File "<frozen importlib._bootstrap_external>", line 823, in load_module
 File "<frozen importlib._bootstrap_external>", line 682, in load_module
 File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
 File "<frozen importlib._bootstrap>", line 684, in _load
 File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
 File "<frozen importlib._bootstrap_external>", line 678, in exec_module
 File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
 File "/var/cache/salt/minion/extmods/states/asdt/__init__.py", line 8, in <module>
   from _Pkg import parsePkg
ModuleNotFoundError: No module named '_Pkg'

I've tried changing the import from _Pkg to asdt._Pkg but that didn't improve things.  If anyone has any suggestions, or can point me towards documentation, on how to get imports working properly in custom states under salt 3002.2 I'd appreciate it.

Thanks




ende...@gmail.com

unread,
Feb 24, 2021, 9:08:44 AM2/24/21
to Salt-users
The root cause of this was the fact that salt 3002 (or possibly 3001 which we skipped) on CentOS 7 switched from using python 2.7 to python 3.6 and the latter changed how imports were handled.  Between the details I found in the JEP [1] and this porting guide [2] I was able to get it sorted out.  

Reply all
Reply to author
Forward
0 new messages