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

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

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

noelmcloughlin
Copy link
Member

@noelmcloughlin noelmcloughlin commented Jun 9, 2021

PR progress checklist (to be filled in by reviewers)

  • Changes to documentation are appropriate (or tick if not required)
  • Changes to tests are appropriate (or tick if not required)
  • Reviews completed

What type of PR is this?

Primary type

  • [build] Changes related to the build system
  • [chore] Changes to the build process or auxiliary tools and libraries such as documentation generation
  • [ci] Changes to the continuous integration configuration
  • [feat] A new feature
  • [fix] A bug fix
  • [perf] A code change that improves performance
  • [refactor] A code change that neither fixes a bug nor adds a feature
  • [revert] A change used to revert a previous commit
  • [style] Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)

Secondary type

  • [docs] Documentation changes
  • [test] Adding missing or correcting existing tests

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

saltstack/salt#54702
#248
#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 #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 noelmcloughlin requested a review from a team as a code owner June 9, 2021 23:18
@noelmcloughlin noelmcloughlin force-pushed the pycent7 branch 5 times, most recently from 8d214f3 to 4582bb3 Compare June 10, 2021 00:25
@noelmcloughlin noelmcloughlin force-pushed the pycent7 branch 6 times, most recently from 23853ba to c4d87a5 Compare June 10, 2021 01:27
@noelmcloughlin
Copy link
Member Author

I managed to get centos CI working.

@noelmcloughlin noelmcloughlin force-pushed the pycent7 branch 2 times, most recently from 8873525 to 060b43f Compare June 10, 2021 01:54
@ixs
Copy link
Contributor

ixs commented Jul 12, 2021

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
Copy link
Member Author

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 noelmcloughlin requested a review from ixs September 3, 2021 22:23
Copy link
Contributor

@ixs ixs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Did not run this myself but the logic is sound, the package name is right and the CI passes.

:shipit:

@noelmcloughlin noelmcloughlin force-pushed the pycent7 branch 3 times, most recently from 203f807 to dc23ea9 Compare September 3, 2021 23:41
@noelmcloughlin
Copy link
Member Author

Thanks @ixs appreciated.

@noelmcloughlin noelmcloughlin merged commit 8ebc96c into saltstack-formulas:master Sep 3, 2021
@noelmcloughlin noelmcloughlin deleted the pycent7 branch September 3, 2021 23:58
@saltstack-formulas-travis

🎉 This PR is included in version 0.56.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants