Skip to content

Commit

Permalink
Account for times where __opts__ is not defined
Browse files Browse the repository at this point in the history
This can happen when we mock things in the test suite
  • Loading branch information
dwoz committed Aug 14, 2023
1 parent 0db7908 commit b2d9349
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions salt/loader/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,24 @@ def __getattr__(self, name):
def __call__(self, *args, **kwargs):
run_func = self.func
mod = sys.modules[run_func.__module__]
if isinstance(mod.__opts__, salt.loader.context.NamedLoaderContext):
if mod.__opts__.value() is not None:
mod.__opts__.value()["test"] = self.loader.opts["test"]
else:
mod.__opts__["test"] = self.loader.opts["test"]
# All modules we've imported should have __opts__ defined. There are
# cases in the test suite where mod ends up being something other than
# a module we've loaded.
if hasattr(mod, "__opts__"):
if isinstance(mod.__opts__, salt.loader.context.NamedLoaderContext):
if mod.__opts__.value() is not None:
mod.__opts__.value()["test"] = self.loader.opts["test"]
else:
mod.__opts__["test"] = self.loader.opts["test"]
if self.loader.inject_globals:
run_func = global_injector_decorator(self.loader.inject_globals)(run_func)
ret = self.loader.run(run_func, *args, **kwargs)
if isinstance(mod.__opts__, salt.loader.context.NamedLoaderContext):
if mod.__opts__.value() is not None:
if hasattr(mod, "__opts__"):
if isinstance(mod.__opts__, salt.loader.context.NamedLoaderContext):
if mod.__opts__.value() is not None:
self.loader.opts["test"] = mod.__opts__["test"]
else:
self.loader.opts["test"] = mod.__opts__["test"]
else:
self.loader.opts["test"] = mod.__opts__["test"]
return ret

def __repr__(self):
Expand Down

0 comments on commit b2d9349

Please sign in to comment.