From 0772146a596689840465e2c91bfd6bf6ae4021f8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Wed, 11 Jul 2018 16:37:24 +0200 Subject: [PATCH] Ensure python3 compatibility Currently everything is wired in the venv to work on python2. If the virtualenv was built during repo build with python3, the linking of the library will fail, as the lib folder for python2 doesn't exist. This should solve the issue by ensuring the existing lib folder of the env is used. A problem arises then: Different distros organise packages differently, in different locations. This makes the approach compatible with multi-distros and multiple python versions. Change-Id: I02b296089d5351d68bb14e87e458a4f5d18a4776 --- .../kvm/nova_compute_kvm_install_source.yml | 45 ++++++++----------- vars/redhat-7.yml | 4 ++ vars/suse-42.yml | 4 ++ vars/ubuntu-16.04.yml | 8 ++++ 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/tasks/drivers/kvm/nova_compute_kvm_install_source.yml b/tasks/drivers/kvm/nova_compute_kvm_install_source.yml index eb708ed8..94ca6820 100644 --- a/tasks/drivers/kvm/nova_compute_kvm_install_source.yml +++ b/tasks/drivers/kvm/nova_compute_kvm_install_source.yml @@ -20,44 +20,37 @@ # use the distro packages for these and symlink the appropriate # library files and binding into the venv. -- name: Link guestfs into the venv - file: - src: "{{ linkfiles.name }}" - dest: "{{ nova_bin | dirname }}/lib/python2.7/{{ linkfiles.name | basename }}" - state: "{{ linkfiles.state }}" - force: "yes" - with_items: - - { state: link, name: "/usr/lib/python2.7/dist-packages/libguestfsmod.so" } - - { state: link, name: "/usr/lib/python2.7/dist-packages/guestfs.py" } - loop_control: - loop_var: linkfiles - tags: - - nova-pip-packages +- name: Find the venv's python version + find: + paths: "{{ nova_bin | dirname }}/lib/" + patterns: "python*" + file_type: directory + recurse: no + register: python_venv_details -- name: Register libvirt module path - command: python -c 'import libvirt; print libvirt.__file__' - changed_when: false - register: _libvirt_module_path - tags: - - nova-pip-packages +- name: Set python venvs details + set_fact: + venv_python_version: "{{ (python_venv_details.files[0].path | basename) }}" + venv_python_major_version: "{{ (python_venv_details.files[0].path | basename)[:-2] }}" + venv_python_lib_folder: "{{ python_venv_details.files[0].path }}" -- name: Register libvirt-python files +- name: Search for lib files to link shell: >- - {{ (ansible_pkg_mgr == 'apt') | ternary('dpkg -L python-libvirt', 'rpm -ql libvirt-python') }} - | grep '^{{ _libvirt_module_path.stdout | dirname }}/' + {{ (ansible_pkg_mgr == 'apt') | ternary('dpkg -L ' ~ (nova_compute_kvm_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (nova_compute_kvm_packages_to_symlink | join(' ')) ) }} + | egrep '^.*{{ venv_python_major_version }}.*/(site|dist)-packages/.*' args: warn: no changed_when: false - register: _libvirt_python_files + register: _python_files tags: - nova-pip-packages -- name: Link the libvirt files into venv +- name: Link the python host package files into venv file: src: "{{ item }}" - dest: "{{ nova_bin | dirname }}/lib/python2.7/site-packages/{{ item | basename }}" + dest: "{{ venv_python_lib_folder }}/site-packages/{{ item | basename }}" state: link force: yes - with_items: "{{ _libvirt_python_files.stdout_lines }}" + with_items: "{{ _python_files.stdout_lines }}" tags: - nova-pip-packages diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index b6128516..be26df15 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -87,6 +87,10 @@ nova_compute_kvm_distro_packages: - qemu-img-ev - sysfsutils +nova_compute_kvm_packages_to_symlink: + - libvirt-python + - python-libguestfs + nova_compute_ksm_packages: - ksmtuned diff --git a/vars/suse-42.yml b/vars/suse-42.yml index 88cf0143..b240c967 100644 --- a/vars/suse-42.yml +++ b/vars/suse-42.yml @@ -97,6 +97,10 @@ nova_compute_kvm_distro_packages: - qemu-tools - sysfsutils +nova_compute_kvm_packages_to_symlink: + - libvirt-python + - python-libguestfs + nova_compute_ksm_packages: - qemu-ksm diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index d90714ba..5cdc62e9 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -81,7 +81,9 @@ nova_compute_kvm_distro_packages: - libvirt-bin - open-iscsi - python-guestfs + - python3-guestfs - python-libvirt + - python3-libvirt - qemu - qemu-utils - sysfsutils @@ -102,6 +104,12 @@ nova_compute_kvm_distro_packages: - qemu-user - qemu-kvm +nova_compute_kvm_packages_to_symlink: + - python-libvirt + - python3-libvirt + - python-guestfs + - python3-guestfs + nova_compute_lxd_distro_packages: - bridge-utils - dosfstools