saltstack-formulas / mysql-formula

Install the MySQL client and/or server
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
85 stars 367 forks source link

fix(centos7): add correct pymysql package on cent7/saltpy3 #262

Closed noelmcloughlin closed 3 years ago

noelmcloughlin commented 3 years ago

PR progress checklist (to be filled in by reviewers)


What type of PR is this?

Primary type

Secondary type

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

https://github.com/saltstack/salt/issues/54702 https://github.com/saltstack-formulas/mysql-formula/pull/248 https://github.com/saltstack-formulas/mysql-formula/pull/252

Describe the changes you're proposing

Problem: On Centos7 the MySQL-python package provides python2.7 support for MySQL. However, if salt is installed using python3 (salt-bootstrap -x python3) the salt MySQL state requires python3.6 support. The result is that this formula fails on CentOS7.

A solution This PR checks python version grain to choose the correct package to install on CentOS7.
The solution is not ideal but I see no other solution for CentOS7.

Pillar / config required to test the proposed changes

Debug log showing how the proposed changes work

BEFORE

          ID: mysql_python
    Function: pkg.installed
        Name: MySQL-python
      Result: True
     Comment: The following packages were installed/updated: MySQL-python
     Started: 21:35:15.551836
    Duration: 3358.682 ms
     Changes:
              ----------
              MySQL-python:
                  ----------
                  new:
                      1.2.5-1.el7
                  old:
----------
          ID: mysql_delete_anonymous_user_localhost
    Function: mysql_user.absent
        Name:
      Result: False
     Comment: State 'mysql_user.absent' was not found in SLS 'mysql.server'
              Reason: 'mysql_user' __virtual__ returned False: mysql module could not be loaded
     Changes:
----------
          ID: mysql_delete_anonymous_user_localhost.localdomain
    Function: mysql_user.absent
        Name:
      Result: False
     Comment: State 'mysql_user.absent' was not found in SLS 'mysql.server'
              Reason: 'mysql_user' __virtual__ returned False: mysql module could not be loaded
     Changes:

VERSIONS

[root@localhost saltstack-formulas]# salt-call grains.items --local | grep -A2 pythonversion
    pythonversion:
        - 3
        - 6

[root@localhost saltstack-formulas]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

[root@localhost saltstack-formulas]# salt --version
salt 3003

Try python3-pyMySQL https://github.com/saltstack-formulas/mysql-formula/pull/252

        ID: mysql_python
    Function: pkg.installed
        Name: python3-PyMySQL
      Result: False
     Comment: The following packages failed to install/update: python3-PyMySQL
     Started: 22:46:20.552165
    Duration: 14220.153 ms
     Changes:
              ----------
              python36-PyMySQL:
                  ----------
                  new:
                      0.9.3-1.el7
                  old:
----------
          ID: mysql_delete_anonymous_user_localhost
    Function: mysql_user.absent
        Name:
      Result: False
     Comment: One or more requisite failed: mysql.python.mysql_python
     Started: 22:46:36.629242
    Duration: 0.003 ms
     Changes:
----------
          ID: mysql_delete_anonymous_user_localhost.localdomain
    Function: mysql_user.absent
        Name:
      Result: False
     Comment: One or more requisite failed: mysql.python.mysql_python
     Started: 22:46:36.629510
    Duration: 0.002 ms

Try python36-mysql

          ID: mysql_python
    Function: pkg.installed
        Name: python36-mysql
      Result: True
     Comment: The following packages were installed/updated: python36-mysql
     Started: 22:30:09.846993
    Duration: 15459.45 ms
     Changes:
              ----------
              python36-mysql:
                  ----------
                  new:
                      1.3.12-2.el7
                  old:
----------
          ID: mysql_delete_anonymous_user_localhost
    Function: mysql_user.absent
        Name:
      Result: True
     Comment: User @localhost is not present, so it cannot be removed
     Started: 22:30:26.883642
    Duration: 8.302 ms
     Changes:
----------
          ID: mysql_delete_anonymous_user_localhost.localdomain
    Function: mysql_user.absent
        Name:
      Result: True
     Comment: User @localhost.localdomain is not present, so it cannot be removed
     Started: 22:30:26.892263
    Duration: 3.298 ms

Try python36-PyMySQL


          ID: mysql_python
    Function: pkg.installed
        Name: python36-PyMySQL
      Result: True
     Comment: The following packages were installed/updated: python36-PyMySQL
     Started: 22:52:41.540460
    Duration: 21308.042 ms
     Changes:
              ----------
              python36-PyMySQL:
                  ----------
                  new:
                      0.9.3-1.el7
                  old:
---------
          ID: mysql_delete_anonymous_user_localhost
    Function: mysql_user.absent
        Name:
      Result: True
     Comment: User @localhost is not present, so it cannot be removed
     Started: 22:53:04.420969
    Duration: 11.397 ms
     Changes:
----------
          ID: mysql_delete_anonymous_user_localhost.localdomain
    Function: mysql_user.absent
        Name:
      Result: True
     Comment: User @localhost.localdomain is not present, so it cannot be removed
     Started: 22:53:04.432724
    Duration: 4.35 ms

---------

### Documentation checklist
<!-- Please tick each box that is relevant (after creating the PR). -->

- [ ] Updated the `README` (e.g. `Available states`).
- [ ] Updated `pillar.example`.

### Testing checklist
<!-- Please tick each box that is relevant (after creating the PR). -->

- [ ] Included in Kitchen (i.e. under `state_top`).
- [ ] Covered by new/existing tests (e.g. InSpec, Serverspec, etc.).
- [ ] Updated the relevant test pillar.

### Additional context
<!-- Add any other context about the proposed changes here. -->
noelmcloughlin commented 3 years ago

I managed to get centos CI working.

ixs commented 3 years ago

Just a note, this might be a breaking change for existing systems. If anyone is still running salt on the system default python 2.7, it would break.

Maybe wrap the logic in a something like this:

{%- if salt["grains.get"]("pythonversion")[0] == 2 %}
  foo
{%- else %}
  bar
{%- endif %}
noelmcloughlin commented 3 years ago

Maybe wrap the logic in a something like this:

Done.

     {%- if 'pythonversion' in grains and grains.pythonversion[0]|int == 3 %}
  pythonpkg: python36-PyMySQL   # python36-mysql works too
      {%- else %}
  pythonpkg: MySQL-python
      {%- endif %}
noelmcloughlin commented 3 years ago

Thanks @ixs appreciated.

saltstack-formulas-travis commented 3 years ago

:tada: This PR is included in version 0.56.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: