salt: MySQL state and module broken after upgrade to 3000

Description of Issue

MySQL module can’t connect to MySQL socket.

Context

Debian 9 and MariaDB 10.4.

Module configuration: mysql.default_file: '/etc/mysql/debian.cnf'

salt-minion 2019.2.3

~# salt-call mysql.version
local:
    10.4.12-MariaDB-1:10.4.12+maria~stretch-log

salt-minion 3000

~#  salt-call mysql.version
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AttributeError: 'unicode' object has no attribute 'items'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    load_entry_point('salt==3000', 'console_scripts', 'salt-call')()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 445, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 57, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 119, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 218, in call
    ret['return'] = self.minion.executors[fname](self.opts, data, func, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/executors/direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 858, in version
    dbc = _connect(**connection_args)
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 392, in _connect
    dbc = MySQLdb.connect(**connargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 173, in __init__
    for k, v in conv.items():
AttributeError: 'unicode' object has no attribute 'items'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    load_entry_point('salt==3000', 'console_scripts', 'salt-call')()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 445, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 57, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 119, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 218, in call
    ret['return'] = self.minion.executors[fname](self.opts, data, func, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/executors/direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 858, in version
    dbc = _connect(**connection_args)
  File "/usr/lib/python2.7/dist-packages/salt/modules/mysql.py", line 392, in _connect
    dbc = MySQLdb.connect(**connargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 173, in __init__
    for k, v in conv.items():
AttributeError: 'unicode' object has no attribute 'items'

Versions Report

           Salt: 3000
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
       M2Crypto: 0.24.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Sep 26 2018, 18:42:22)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.1
 
System Versions:
           dist: debian 9.12 
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-12-amd64
         system: Linux
        version: debian 9.12

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

Patch

patches/mysql.sls:

{% if grains.saltversion == "3000" %}
patch:
  pkg.installed

mysql_module_patch:
  file.patch:
    - name: '{{ grains.saltpath }}'
    - source: salt://patches/files/3000-mysql.diff
    - strip: 2
    - require:
        - pkg: patch

restart_salt_minion:
  cmd.run:
    - name: 'salt-call service.restart salt-minion'
    - bg: true
    - onchanges:
      - file: mysql_module_patch
{%- endif %}

patches/files/3000-mysql.diff:

diff --git a/salt/modules/mysql.py b/salt/modules/mysql.py
index 87e2361e28..37436206d4 100644
--- a/salt/modules/mysql.py
+++ b/salt/modules/mysql.py
@@ -355,7 +355,7 @@ def _connect(**kwargs):
                 except IndexError:
                     return
             val = __salt__['config.option']('mysql.{0}'.format(name), None)
-            if val is not None:
+            if val != '':
                 connargs[key] = val

     # If a default file is explicitly passed to kwargs, don't grab the

Run sudo MINION state.apply patches.mysql to apply the fix.

@boltronics As a bonus, salt-version detecting and alerting to overrides would help when opening a ticket. Maybe I should open a new feature request.

I can confirm this also happens on CentOS 7. I can’t get any mysql modules or states to execute successfully.

sls

test_db:
  mysql_database.present:
    - name: testing
    - connection_unix_socket: /var/lib/mysql/mysql.sock

output:

mysql-7c88a609-b9f0-5af3-9dca-5a9c5e24c282:
----------
          ID: test_db
    Function: mysql_database.present
        Name: testing
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 1981, in call
                  **cdata['kwargs'])
                File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1977, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/mysql_database.py", line 55, in present
                  existing = __salt__['mysql.db_get'](name, **connection_args)
                File "/usr/lib/python3.6/site-packages/salt/modules/mysql.py", line 1034, in db_get
                  dbc = _connect(**connection_args)
                File "/usr/lib/python3.6/site-packages/salt/modules/mysql.py", line 392, in _connect
                  dbc = MySQLdb.connect(**connargs)
                File "/usr/lib64/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
                  return Connection(*args, **kwargs)
                File "/usr/lib64/python3.6/site-packages/MySQLdb/connections.py", line 172, in __init__
                  for k, v in conv.items():
              AttributeError: 'str' object has no attribute 'items'
     Started: 11:15:00.141229
    Duration: 12.662 ms
     Changes:   

I personally think an INFO message on startup would be good for anything in _states, _modules, etc. that is acting as an override.