Correctly upgrading your Python application with SaltStack

If you work with Python applications or deal with configuration management in general, you might have run into limitations with the pip tool. Unfortunately, their implementation of upgrade doesn’t really perform an “upgrade” as most people would think. If you are frustrated familiar with SaltStack’s pip state not upgrading already installed packages when you run a highstate, its not Salt’s fault. Lets blame pip!

To upgrade a single package, you would run pip install --upgrade foobar. This would upgrade foobar to the most recent version found in PyPI, but it has the unfortunate side effect of upgrading ALL other packages, whether they require it or not.

So SaltStack’s implementation is true to pip. If a package is installed, yet there is a newer version available, Salt will see it is installed and move on. It will not install the newer package. You can include - upgrade: True and that will upgrade the package, but it will also blindly upgrade ALL packages.

This is a problem that the pip team has been actively working on for quite a while and it looks like they are getting close to a solution. Someone graciously gave instructions on how properly upgrade a package and its dependencies, only if required. Here is a simple implementation in a Salt state.

From the command line, you would execute:

pip install --upgrade --no-deps SomePackage
pip install SomePackage

In a Salt state:

SomePackage-step1:
  pip.installed:
    - name: SomePackage
    - upgrade: True
    - no_deps: True

SomePackage-step2:
  pip.installed:
    - name: SomePackage

Leave a Reply

Your email address will not be published. Required fields are marked *