saltstack-formulas / lxd-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
21 stars 18 forks source link

'module' object has no attribute 'which' on 2018.3.0 (Oxygen) #12

Closed markododa closed 6 years ago

markododa commented 6 years ago

When i'm trying to run salt-call --local lxd.version i get [ERROR ] Failed to import module lxd, this is due most likely to a syntax error: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1459, in _load_module mod = imp.load_module(mod_namespace, fn_, fpath, desc) File "/var/cache/salt/minion/extmods/modules/lxd.py", line 114, in <module> @salt.utils.decorators.which('lxd') AttributeError: 'module' object has no attribute 'which' 'lxd' __virtual__ returned False: 'module' object has no attribute 'which'

Checking out the code i see that salt.utils.decorators doesn't have a function named which

` Python 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import salt.utils.decorators.which Traceback (most recent call last): File "", line 1, in ImportError: No module named which `

markododa commented 6 years ago

It seems like the new path is @salt.utils.decorators.path.which Changing salt.utils.decorators.which and adding import salt.utils.decorators.path works just fine

jochumdev commented 6 years ago

@Jetman80 Thanks for fixing this in your branch, please make a PR.

jochumdev commented 6 years ago

@markododa please star this repo if you have it in use :)

keesbos commented 6 years ago

The proposed solution will break on previous (<2018.3) salt versions. Need to do some intelligent/dirty stuff like:

try:
    import salt.utils.decorators.path
except ImportError:
    # Dirty monkey patch salt.utils.decorators to have
    # the relocated 'salt.utils.decorators.which' decorator
    # available as 'salt.utils.decorators.path.which'
    import salt.utils.decorators
    salt.utils.decorators.path = salt.utils.decorators
keesbos commented 6 years ago

Since I'm on this anyway, I've created PR https://github.com/saltstack-formulas/lxd-formula/pull/15

@pcdummy check if this is not too dirty...

jochumdev commented 6 years ago

done by @keesbos