From 390414b2a7a6ea9b8553bb7bd91374382af10a71 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Tue, 14 Mar 2017 07:55:40 +0000 Subject: [PATCH] Fix some virtualenv-related places - on Ubuntu Xenial, `python-virtualenv` package no longer installs `virtualenv` shell script. Change all `virtualenv` invocations to 'python -m virtualenv', which is more portable. - in `pip_install.yml`, add `virtualenv_command` argument using the same portable invocation. - in `install-deps.sh`, the condition to install `python-virtualenv` was missing the `not` part - the venv is created with `sudo` elevation in `install-deps.sh`, thus in `env-setup.sh` Ansible must be installed into venv using `sudo` elevation as well. - in `install.yml`, fix passing `bifrost_venv_dir` var to `pip_install.yml` Change-Id: Ifaa54a0dc97ed59ca8360e62878b603a04105e46 --- playbooks/roles/bifrost-ironic-install/tasks/install.yml | 4 ++-- .../roles/bifrost-ironic-install/tasks/pip_install.yml | 7 +++++++ scripts/env-setup.sh | 2 +- scripts/install-deps.sh | 4 ++-- scripts/test-bifrost.sh | 3 +-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/playbooks/roles/bifrost-ironic-install/tasks/install.yml b/playbooks/roles/bifrost-ironic-install/tasks/install.yml index 53905f481..59af5fdcd 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/install.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/install.yml @@ -80,10 +80,10 @@ source_install={{ ironicclient_source_install }} when: skip_install is not defined - name: "Install configparser in venv if using" - include: pip_install.yml package=configparser virtualenv=bifrost_venv_dir + include: pip_install.yml package=configparser virtualenv={{ bifrost_venv_dir }} when: skip_install is not defined and (enable_venv | bool == true) - name: "Install pymysql in venv if using" - include: pip_install.yml package=pymysql virtualenv=bifrost_venv_dir + include: pip_install.yml package=pymysql virtualenv={{ bifrost_venv_dir }} when: skip_install is not defined and (enable_venv | bool == true) - name: "Install Ironic using pip" include: pip_install.yml diff --git a/playbooks/roles/bifrost-ironic-install/tasks/pip_install.yml b/playbooks/roles/bifrost-ironic-install/tasks/pip_install.yml index 6dcdfb811..4ee2eb16a 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/pip_install.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/pip_install.yml @@ -13,12 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. --- + +- name: set virtualenv_command + set_fact: + venv_command: "{{ hostvars[inventory_hostname].ansible_python.executable }} -m virtualenv" + when: enable_venv + - name: "Install {{ package }} package from pip" pip: name: "{{ package }}" state: "{{ state | default(omit) }}" version: "{{ version | default(omit) }}" virtualenv: "{{ bifrost_venv_dir if enable_venv else omit }}" + virtualenv_command: "{{ venv_command | default(omit) }}" extra_args: "{{ extra_args | default(omit) }}" when: source_install is not defined or source_install == false # NOTE (cinerama): We should be able to use the pip module here and diff --git a/scripts/env-setup.sh b/scripts/env-setup.sh index c2d1b3d34..ba96931ba 100755 --- a/scripts/env-setup.sh +++ b/scripts/env-setup.sh @@ -10,7 +10,7 @@ ANSIBLE_PIP_VERSION=${ANSIBLE_PIP_VERSION:-${ANSIBLE_GIT_BRANCH:-stable-2.1}} ANSIBLE_PIP_STRING=$(${PYTHON} $(dirname $0)/ansible-pip-str.py ${ANSIBLE_PIP_VERSION}) if [ -n "${VENV-}" ]; then - ${PIP} install --upgrade "${ANSIBLE_PIP_STRING}" + sudo -H -E ${PIP} install --upgrade "${ANSIBLE_PIP_STRING}" ANSIBLE=${VENV}/bin/ansible else ${PIP} install --user --upgrade "${ANSIBLE_PIP_STRING}" diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh index 89c49f805..b622593ff 100644 --- a/scripts/install-deps.sh +++ b/scripts/install-deps.sh @@ -82,7 +82,7 @@ if ! $(wget --version &>/dev/null); then ${INSTALLER_CMD} ${PKG_MAP[wget]} fi if [ -n "${VENV-}" ]; then - if $(virtualenv --version &>/dev/null); then + if ! $(python -m virtualenv --version &>/dev/null); then ${INSTALLER_CMD} ${PKG_MAP[venv]} fi fi @@ -105,7 +105,7 @@ if [ -n "${VENV-}" ]; then echo "NOTICE: Using virtualenv for this installation." if [ ! -f ${VENV}/bin/activate ]; then # only create venv if one doesn't exist - sudo -H -E virtualenv --no-site-packages ${VENV} + sudo -H -E python -m virtualenv --no-site-packages ${VENV} fi # Note(cinerama): activate is not compatible with "set -u"; # disable it just for this line. diff --git a/scripts/test-bifrost.sh b/scripts/test-bifrost.sh index dc82be2eb..db84d2f33 100755 --- a/scripts/test-bifrost.sh +++ b/scripts/test-bifrost.sh @@ -94,12 +94,11 @@ fi if [ ${USE_VENV} = "true" ]; then export VENV=/opt/stack/bifrost - export PATH=${VENV}/bin:${PATH} $SCRIPT_HOME/env-setup.sh # Note(cinerama): activate is not compatible with "set -u"; # disable it just for this line. set +u - source /opt/stack/bifrost/bin/activate + source ${VENV}/bin/activate set -u ANSIBLE=${VENV}/bin/ansible-playbook ENABLE_VENV="true"