Skip to content

Commit

Permalink
fix(packages): python2 libvirt library is unusable by Python3 minion
Browse files Browse the repository at this point in the history
We need a mechanism to select which python library to install
depending on the environment of the minion.

We do not generated keys when the python library is not available for
the current OS.

BREAKING CHANGE: the Python2 package is now “python2_pkg”.

* libvirt/python.sls: use “switch_python32” macro to select the python
  package and do nothing if it's not available.

* libvirt/keys.sls: ditoo.

* libvirt/python.jinja: new macro “switch_python32” to select one of
  the two arguments based on the environment of the SaltStack minion.

* libvirt/defaults.yaml: distinguish python2 and python3 packages.

* libvirt/osfamilymap.yaml (Debian): distinguish python2 and python3
  packages.
  • Loading branch information
baby-gnu committed Jul 22, 2019
1 parent 6679340 commit e16bfad
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libvirt/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
libvirt:
libvirt_pkg: libvirt
qemu_pkg: qemu
python_pkg: libvirt-python
python2_pkg: libvirt-python
python3_pkg: libvirt-python3
libvirt_service: libvirtd
libvirtd_config: /etc/libvirt/libvirtd.conf
daemon_config_path: {}
Expand Down
8 changes: 8 additions & 0 deletions libvirt/keys.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{%- from "libvirt/map.jinja" import libvirt_settings with context %}
{%- from "libvirt/python.jinja" import switch_python32 with context %}
{%- set package = switch_python32(libvirt_settings.python3_pkg, libvirt_settings.python2_pkg) %}
{%- set salt_version = salt['grains.get']('saltversioninfo', '') %}
{#- Some OS do not have the python3 library #}
{%- if package %}
include:
- .python
- .config
Expand All @@ -14,3 +21,4 @@ libvirt.keys:
- require:
- pkg: libvirt.pkg
- pkg: libvirt-python
{%- endif %}
3 changes: 2 additions & 1 deletion libvirt/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Debian:
libvirt_pkg: libvirt-daemon-system
libvirt_service: libvirtd
qemu_pkg: qemu-kvm
python_pkg: python-libvirt
python2_pkg: python-libvirt
python3_pkg: python3-libvirt
extra_pkgs:
- libguestfs0
- libguestfs-tools
Expand Down
34 changes: 34 additions & 0 deletions libvirt/python.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{%- macro switch_python32(python3, python2) %}
{#-
Returns arguments depending on the Python environment of the
SaltStack minion.
A `none` argument is returned as an empty string `''`.
Params:
* python3: the parameter to return in case of a Python3 minion.
* python2: the parameter to return in case of a Python2 minion.
Example:
{%- set package = switch_python32('python3-library', 'python2-library') %}
{%- if package %}
pkg-install-{{ package }}:
pkg.installed:
- name: {{ package }}
{%- endif %}
The `package` will be `python3-library` when the SaltStack minion
runs under Python3 or `python2-library` otherwise.
#}
{%- if salt['grains.get']('pythonversion')[0] == 3 %}
{%- set selected = python3 %}
{%- else %}
{%- set selected = python2 %}
{%- endif %}
{#- Coerce null value to empty string to make tests simpler #}
{%- if not selected or selected is none -%}
{%- else -%}
{{ selected }}
{%- endif -%}
{%- endmacro -%}
10 changes: 8 additions & 2 deletions libvirt/python.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{% from "libvirt/map.jinja" import libvirt_settings with context %}
{%- from "libvirt/map.jinja" import libvirt_settings with context %}
{%- from "libvirt/python.jinja" import switch_python32 with context %}
{%- set package = switch_python32(libvirt_settings.python3_pkg, libvirt_settings.python2_pkg) %}
{#- Some OS do not have the python3 library #}
{%- if package %}
libvirt-python:
pkg.installed:
- name: {{ libvirt_settings.python_pkg }}
- name: {{ package }}
{%- endif %}

0 comments on commit e16bfad

Please sign in to comment.