salt icon indicating copy to clipboard operation
salt copied to clipboard

crash when using `--output=compact`

Open mpaolini opened this issue 12 years ago • 11 comments

tested on 2014.7

[ERROR   ] An un-handled exception was caught by salt's global exception handler:
NameError: global name '__opts__' is not defined
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 122, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/__init__.py", line 419, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 235, in run
    self.opts)
  File "/usr/lib/python2.7/dist-packages/salt/output/__init__.py", line 44, in display_output
    display_data = get_printout(out, opts)(data).rstrip()
  File "/usr/lib/python2.7/dist-packages/salt/output/compact.py", line 34, in output
    return salt.output.highstate.output(tmp)
  File "/usr/lib/python2.7/dist-packages/salt/output/highstate.py", line 74, in output
    return _format_host(host, hostdata)[0]
  File "/usr/lib/python2.7/dist-packages/salt/output/highstate.py", line 78, in _format_host
    colors = salt.utils.get_colors(__opts__.get('color'))
NameError: global name '__opts__' is not defined
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 122, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/__init__.py", line 419, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 235, in run
    self.opts)
  File "/usr/lib/python2.7/dist-packages/salt/output/__init__.py", line 44, in display_output
    display_data = get_printout(out, opts)(data).rstrip()
  File "/usr/lib/python2.7/dist-packages/salt/output/compact.py", line 34, in output
    return salt.output.highstate.output(tmp)
  File "/usr/lib/python2.7/dist-packages/salt/output/highstate.py", line 74, in output
    return _format_host(host, hostdata)[0]
  File "/usr/lib/python2.7/dist-packages/salt/output/highstate.py", line 78, in _format_host
    colors = salt.utils.get_colors(__opts__.get('color'))
NameError: global name '__opts__' is not defined

mpaolini avatar Dec 01 '14 20:12 mpaolini

Thanks for the report @mpaolini! This is definitely broken. We will take a look here.

I have confirmed that this is broken and tested at the HEAD of 2014.7: 3ea390f4b55a8b047f60df48ddfe8fabfc6b7a27

To reproduce, I created the following sls files: /srv/salt/top.sls:

base:
  '*':
    - test

/srv/salt/test.sls:

test_state:
  cmd.run:
    - name: ls

And then ran: salt-call --local state.highstate --output=compact

root@nt-master:~# salt --versions
           Salt: 2014.7.0-633-g3ea390f
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.3.0
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.0.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: Not Installed

rallytime avatar Dec 01 '14 22:12 rallytime

Finally got to the "why does salt spit out pages upon pages of information for each host" on my todo list. Discovered this. running state.highstate across hundreds of hosts and trying to see if there were any errors is impossible.

           Salt: 2015.5.3
         Python: 2.7.5 (default, Jun 24 2015, 00:41:19)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.4.6
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.5.0
           RAET: Not Installed
            ZMQ: 4.0.5
           Mako: Not Installed
        Tornado: Not Installed

scbunn avatar Sep 10 '15 23:09 scbunn

Still hitting this on develop, although the trace is different.

[root@core /opt/local/salt_dev/sls]# /opt/local/salt/bin/salt-call --local test.ping --out compact
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
TypeError: 'bool' object is not iterable
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "__main__.py", line 128, in <module>
  File "__main__salt-call__.py", line 14, in <module>
  File "salt/scripts.py", line 333, in salt_call
  File "salt/cli/call.py", line 58, in run
  File "salt/cli/caller.py", line 148, in run
  File "salt/output/__init__.py", line 86, in display_output
  File "salt/output/__init__.py", line 39, in try_printout
  File "salt/output/compact.py", line 21, in output
TypeError: 'bool' object is not iterable
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "__main__.py", line 128, in <module>
  File "__main__salt-call__.py", line 14, in <module>
  File "salt/scripts.py", line 333, in salt_call
  File "salt/cli/call.py", line 58, in run
  File "salt/cli/caller.py", line 148, in run
  File "salt/output/__init__.py", line 86, in display_output
  File "salt/output/__init__.py", line 39, in try_printout
  File "salt/output/compact.py", line 21, in output
TypeError: 'bool' object is not iterable

For reference here is the raw output

[root@core /opt/local/salt_dev/sls]# /opt/local/salt/bin/salt-call --local test.ping --out raw
{'local': True}

sjorge avatar Nov 11 '15 23:11 sjorge

I'm also seeing this in 2015.8.3 version:

[DEBUG   ] LazyLoaded compact.output
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
NameError: global name '__opts__' is not defined
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 454, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 204, in run
    self._output_ret(ret_, out)
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 303, in _output_ret
    salt.output.display_output(ret, out, self.config)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
    display_data = try_printout(data, out, opts)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 39, in try_printout
    return get_printout(out, opts)(data).rstrip()
  File "/usr/lib/python2.7/site-packages/salt/output/compact.py", line 33, in output
    return salt.output.highstate.output(tmp)
  File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
    return _format_host(host, hostdata)[0]
  File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 92, in _format_host
    __opts__.get('color'),
NameError: global name '__opts__' is not defined
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 454, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 204, in run
    self._output_ret(ret_, out)
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 303, in _output_ret
    salt.output.display_output(ret, out, self.config)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
    display_data = try_printout(data, out, opts)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 39, in try_printout
    return get_printout(out, opts)(data).rstrip()
  File "/usr/lib/python2.7/site-packages/salt/output/compact.py", line 33, in output
    return salt.output.highstate.output(tmp)
  File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 85, in output
    return _format_host(host, hostdata)[0]
  File "/usr/lib/python2.7/site-packages/salt/output/highstate.py", line 92, in _format_host
    __opts__.get('color'),
NameError: global name '__opts__' is not defined

That's could also be related to #29796

vutny avatar Jan 26 '16 11:01 vutny

Ok, so after digging into this issue today, there are a couple of things happening. The first thing is that the --ouput=compact ouputter option was originally written to function as a way to display "changes, errors, and a summary" from state runs. The original request is in #14470. This functionality was implemented in the 2014.7 branch, but unfortunately broke shortly thereafter, it appears that this never worked in an released version of Salt.

The way that the compact outputter docs display the ouput, actually looks more like the --output=raw functionality. @sjorge Based on your sample command, this is probably more what you're looking for, since the compact outputter was only intended to handled state runs.

It also appears that setting state_verbose: False is actually what everyone else in this thread is probably looking for. The docs for setting state_verbose are as follows:

state_verbose:
    By default `state_verbose` is set to `True`, setting this to `False` will
    instruct the highstate outputter to omit displaying anything in green, this
    means that nothing with a result of True and no changes will not be printed.

Which appears to be what the actual feature request was originally looking for. I put together this sample state run that displays how this works. There are 3 states in the file. One that is True without changes, one that returns False, and one that returns True with changes. Only the ouput from two states is shown, along with the summary:

# salt rallytime state.sls state_output_false
rallytime:
----------
          ID: always-fails
    Function: test.fail_without_changes
        Name: foo
      Result: False
     Comment: Failure!
     Started: 00:06:40.284713
    Duration: 0.447 ms
     Changes:
----------
          ID: always-changes-and-succeeds
    Function: test.succeed_with_changes
        Name: foo
      Result: True
     Comment: Success!
     Started: 00:06:40.285244
    Duration: 0.245 ms
     Changes:
              ----------
              testing:
                  ----------
                  new:
                      Something pretended to change
                  old:
                      Unchanged

Summary for rallytime
------------
Succeeded: 2 (changed=1)
Failed:    1
------------
Total states run:     3

Does this do what you all were expecting? Does a combination of state_verbose: False and --output=raw cover all of the cases here?

One thing to note is that there isn't a way to set state_verbose from the CLI, but that would be easy to add, instead of repeating code via the compact (which is broken anyway). Thoughts?

rallytime avatar Feb 06 '16 00:02 rallytime

Edit: "One thing to note is that there isn't a way to set state_verbose from the CLI"

That isn't true, actually. You can achieve this via using the --state_verbose=False option.

# salt-call --local state.sls state_output_false --state_verbose=False
local:
----------
          ID: always-fails
    Function: test.fail_without_changes
        Name: foo
      Result: False
     Comment: Failure!
     Started: 00:03:57.707360
    Duration: 0.642 ms
     Changes:
----------
          ID: always-changes-and-succeeds
    Function: test.succeed_with_changes
        Name: foo
      Result: True
     Comment: Success!
     Started: 00:03:57.708196
    Duration: 0.633 ms
     Changes:
              ----------
              testing:
                  ----------
                  new:
                      Something pretended to change
                  old:
                      Unchanged

Summary for local
------------
Succeeded: 2 (changed=1)
Failed:    1
------------
Total states run:     3

rallytime avatar Feb 17 '16 00:02 rallytime

I have a slightly different output:

Salt Version:
           Salt: 2015.8.10

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
           Mako: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.7.0
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: 0.8.6
       cherrypy: 3.2.2
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: 0.21.0
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.21.4
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.18.2.el7.x86_64
         system: CentOS Linux 7.2.1511 Core

and the trace:

$ salt '*' state.highstate --out=compact
[ERROR   ] Nested output failed:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 43, in try_printout
    return get_printout('nested', opts)(data).rstrip()
AttributeError: 'NoneType' object has no attribute 'rstrip'
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AttributeError: 'NoneType' object has no attribute 'rstrip'
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 461, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 208, in run
    self._output_ret(ret_, out)
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 307, in _output_ret
    salt.output.display_output(ret, out, self.config)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
    display_data = try_printout(data, out, opts)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
    return get_printout('raw', opts)(data).rstrip()
AttributeError: 'NoneType' object has no attribute 'rstrip'
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 461, in salt_main
    client.run()
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 208, in run
    self._output_ret(ret_, out)
  File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 307, in _output_ret
    salt.output.display_output(ret, out, self.config)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 86, in display_output
    display_data = try_printout(data, out, opts)
  File "/usr/lib/python2.7/site-packages/salt/output/__init__.py", line 46, in try_printout
    return get_printout('raw', opts)(data).rstrip()
AttributeError: 'NoneType' object has no attribute 'rstrip'

devster31 avatar May 21 '16 16:05 devster31

So, since --output=compact is broken for a long time and we have a workaround to achieve the same output result... Are there any plans to cut this outputter in the future versions of Salt?

vutny avatar Aug 01 '16 10:08 vutny

@vutny Yes, this is on my radar to cut this and document appropriately. I was waiting for some feedback on my latest comments above to make sure I had covered all of the potential options that people were hoping to achieve with the compact option, but I think I covered them all. Thanks for the bump - I can move forward on this.

rallytime avatar Aug 01 '16 15:08 rallytime

Hi,

I am trying to manage the output from salt-run jobs.list_job. I want to only output the states that failed or changed within the specified job as I am sending the output in an email notification. --state_verbose=False does not seem to work with salt-run.

aabognah avatar Aug 04 '16 17:08 aabognah

Hi everyone! I have removed the compact outputter in #35918.

@aabognah Can you file a new issue for your situation? I think we just need to make the highstate outputter work in conjunction with state_verbose to be used with salt-run.

rallytime avatar Aug 30 '16 20:08 rallytime