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

mysql module gives traceback if no working authentication #33582

Closed
waxie opened this issue May 27, 2016 · 3 comments
Closed

mysql module gives traceback if no working authentication #33582

waxie opened this issue May 27, 2016 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE Execution-Module P3 Priority 3 RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@waxie
Copy link

waxie commented May 27, 2016

Description of Issue/Question

If:

  • mysql is configured with authentication
  • no mysql authentication information is provided to saltstack

Then:

  • the mysql module in Jinja will fail with a python traceback where it cannot get a cursor
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 366, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 60, in top-level template code
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1958, in get_slave_status
    rtnv = __do_query_into_hash(conn, "SHOW SLAVE STATUS")
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1837, in __do_query_into_hash
    cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'

Setup

{% if not salt['mysql.get_slave_status']()['Master_Host'] %}    <======================
            read_only: true
{% else %}
            read_only: false
{% endif %}
[...]

---
2016-05-27 15:16:30,203 [salt.pillar      ][CRITICAL][1401] Rendering SLS 'mysql.db' failed, render error:
Jinja error: 'NoneType' object has no attribute 'cursor'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 366, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 60, in top-level template code
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1958, in get_slave_status
    rtnv = __do_query_into_hash(conn, "SHOW SLAVE STATUS")
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 1837, in __do_query_into_hash
    cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'

Steps to Reproduce Issue

  • Configure mysql with authentication so that root cannot authenticate without a password
  • Try to use salt mysql module in Jinja

Versions Report

Salt Version:
           Salt: 2015.8.10

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: Not Installed
           Mako: 0.9.1
         PyYAML: 3.10
          PyZMQ: 14.0.1
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.4
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.3.0
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: 0.8.2
        timelib: Not Installed

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.13.0-71-generic
         system: Ubuntu 14.04 trusty
@Ch3LL
Copy link
Contributor

Ch3LL commented May 27, 2016

@waxie it seems that this is the culprit in the configuration file: mysql.unix_socket: '/tmp/mysql.sock'

[ERROR   ] MySQL Error 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[DEBUG   ] __do_query_into_hash<--(SHOW SLAVE STATUS)
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AttributeError: 'NoneType' object has no attribute 'cursor'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 338, in salt_call
    client.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/call.py", line 53, in run
    caller.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 197, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/salt/modules/mysql.py", line 1958, in get_slave_status
    rtnv = __do_query_into_hash(conn, "SHOW SLAVE STATUS")
  File "/usr/lib/python2.6/site-packages/salt/modules/mysql.py", line 1837, in __do_query_into_hash
    cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 338, in salt_call
    client.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/call.py", line 53, in run
    caller.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 197, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/salt/modules/mysql.py", line 1958, in get_slave_status
    rtnv = __do_query_into_hash(conn, "SHOW SLAVE STATUS")
  File "/usr/lib/python2.6/site-packages/salt/modules/mysql.py", line 1837, in __do_query_into_hash
    cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'

Do you see the stacktrace when that configuration is removed?

@Ch3LL Ch3LL added Bug broken, incorrect, or confusing behavior P3 Priority 3 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. Execution-Module labels May 27, 2016
@Ch3LL Ch3LL added this to the Approved milestone May 27, 2016
@Ch3LL Ch3LL added the Confirmed Salt engineer has confirmed bug/feature - often including a MCVE label May 27, 2016
danslimmon added a commit to danslimmon/salt that referenced this issue May 30, 2016
cachedout pushed a commit that referenced this issue May 31, 2016
Fix crash on unconnectable MySQL server (resolves #33582)
@cachedout
Copy link
Contributor

Resolved via #33615

@waxie
Copy link
Author

waxie commented Jun 1, 2016

@Ch3LL actually no mysql.unix_socket setting in my configuration.

But I see they addressed it already. Thanks!

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 Confirmed Salt engineer has confirmed bug/feature - often including a MCVE Execution-Module P3 Priority 3 RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

3 participants