Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Saltcheck module doesn't work with Pyobjects Renderer #62523

Closed
nicholasmhughes opened this issue Aug 23, 2022 · 0 comments · Fixed by #62726
Closed

[BUG] Saltcheck module doesn't work with Pyobjects Renderer #62523

nicholasmhughes opened this issue Aug 23, 2022 · 0 comments · Fixed by #62726
Labels
Bug broken, incorrect, or confusing behavior needs-triage Renderers

Comments

@nicholasmhughes
Copy link
Collaborator

nicholasmhughes commented Aug 23, 2022

Description
The Saltcheck module doesn't work with the Pyobjects Renderer.

Setup

Create a directory structure with empty files as shown below:

/srv/salt/pyobj
├── init.sls
└── saltcheck-tests
    └── init.tst

Enter this information into the init.sls file:

#!pyobjects

# /srv/salt/pyobj/init.sls
File.touch("/tmp/pyobj")

Enter this information into the init.tst file:

# /srv/salt/pyobj/saltcheck-tests/init.tst
is_stuff_there:
  module_and_function: file.file_exists
  args:
    - "/tmp/pyobj"
  assertion: assertTrue

Steps to Reproduce the behavior

Running the state tests as shown in this command:

salt-call saltcheck.run_state_tests pyobj

Fails with this error:

[ERROR   ] An un-handled exception was caught by Salt's global exception handler:
AttributeError: 'NoneType' object has no attribute 'saltenv'
Traceback (most recent call last):
  File "/usr/local/bin/salt-call", line 10, in <module>
    sys.exit(salt_call())
  File "/usr/local/lib/python3.7/dist-packages/salt/scripts.py", line 443, in salt_call
    client.run()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/call.py", line 50, in run
    caller.run()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/caller.py", line 95, in run
    ret = self.call()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/caller.py", line 203, in call
    self.opts, data, func, args, kwargs
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/executors/direct_call.py", line 10, in execute
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 471, in run_state_tests
    stl.load_test_suite()
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 1170, in load_test_suite
    self._load_file_salt_rendered(myfile)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 1178, in _load_file_salt_rendered
    tests = _render_file(filepath, self.saltenv)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 623, in _render_file
    rendered = __salt__["slsutil.renderer"](file_path, saltenv=global_scheck.saltenv)
AttributeError: 'NoneType' object has no attribute 'saltenv'
Traceback (most recent call last):
  File "/usr/local/bin/salt-call", line 10, in <module>
    sys.exit(salt_call())
  File "/usr/local/lib/python3.7/dist-packages/salt/scripts.py", line 443, in salt_call
    client.run()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/call.py", line 50, in run
    caller.run()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/caller.py", line 95, in run
    ret = self.call()
  File "/usr/local/lib/python3.7/dist-packages/salt/cli/caller.py", line 203, in call
    self.opts, data, func, args, kwargs
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/executors/direct_call.py", line 10, in execute
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 471, in run_state_tests
    stl.load_test_suite()
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 1170, in load_test_suite
    self._load_file_salt_rendered(myfile)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 1178, in _load_file_salt_rendered
    tests = _render_file(filepath, self.saltenv)
  File "/usr/local/lib/python3.7/dist-packages/salt/modules/saltcheck.py", line 623, in _render_file
    rendered = __salt__["slsutil.renderer"](file_path, saltenv=global_scheck.saltenv)
AttributeError: 'NoneType' object has no attribute 'saltenv'

The global_scheck global variable is intact before the following lines of code, but set to None after it runs.

salt/salt/modules/saltcheck.py

Lines 1309 to 1311 in 1f78f9b

ret = __salt__["state.show_low_sls"](
sls_name, saltenv=self.saltenv, test=True
)

I suspect that the Pyobjects Renderer is obliterating the Saltcheck module globals when it invokes the Loader inside of load_states.

lazy_funcs = salt.loader.minion_mods(__opts__, utils=lazy_utils)

Expected behavior

Converting the Pyobjects code to "normal" YAML causes the problem to cease.

/tmp/pyobj:
  file.touch

The Saltcheck code should work properly with any renderer.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3005+0na.d5dec79
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.4
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: 2.6.1
  pycryptodome: 3.15.0
        pygit2: Not Installed
        Python: 3.7.3 (default, Jan 22 2021, 20:04:44)
  python-gnupg: Not Installed
        PyYAML: 6.0
         PyZMQ: 23.2.1
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
System Versions:
          dist: debian 10 buster
        locale: UTF-8
       machine: x86_64
       release: 4.19.0-21-amd64
        system: Linux
       version: Debian GNU/Linux 10 buster

Additional context
Also verified as an issue in version 3004.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage Renderers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants