From 89c616ff32a2cb3f871c291ac8ec69a66745dfe3 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 18 Apr 2018 11:12:02 +0100 Subject: [PATCH] Replace virtualenv-tools with a script virtualenv-tools has a bug which gets triggered in gates: it can't change the shebang of a virtualenv python bin/ files if they were generated with a virtualenv script whose shebang ends with python2 instead of python. Because we can't modify virtualenv-tools, we use shell scripts instead. Change-Id: Ic37abfb14303b93dfc80398d6e37706a68135cb0 Partial-Bug: #1741634 Partial-Bug: #1764470 --- defaults/main.yml | 1 - tasks/monasca_agent_install.yml | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 057c15b..91d7ba0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -278,7 +278,6 @@ monasca_agent_plugins: ## Monasca-agent packages that must be installed before anything else monasca_agent_requires_pip_packages: - virtualenv - - virtualenv-tools - python-keystoneclient - httplib2 diff --git a/tasks/monasca_agent_install.yml b/tasks/monasca_agent_install.yml index b7c54f4..63c01f8 100644 --- a/tasks/monasca_agent_install.yml +++ b/tasks/monasca_agent_install.yml @@ -107,7 +107,22 @@ - ansible_pkg_mgr == 'yum' - monasca_agent_get_venv | changed -- name: Update virtualenv path - command: > - virtualenv-tools --update-path=auto --reinitialize {{ monasca_agent_bin | dirname }} +# NOTE(odyssey4me): +# We reinitialize the venv to ensure that the right +# version of python is in the venv, but we do not +# want virtualenv to also replace pip, setuptools +# and wheel so we tell it not to. +# We do not use --always-copy for CentOS/SuSE due +# to https://github.com/pypa/virtualenv/issues/565 +- name: Reset virtualenv and update its paths + shell: | + find {{ monasca_agent_bin }} -name \*.pyc -delete + sed -si '1s/^.*python.*$/#!{{ monasca_agent_bin | replace ('/','\/') }}\/python/' {{ monasca_agent_bin }}/* + virtualenv {{ monasca_agent_bin | dirname }} \ + {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \ + --no-pip \ + --no-setuptools \ + --no-wheel when: monasca_agent_get_venv | changed + tags: + - skip_ansible_lint