From a82e4821fda5823541ba83c624f67699559a25bf Mon Sep 17 00:00:00 2001 From: git-harry Date: Thu, 28 Jan 2016 10:00:12 +0000 Subject: [PATCH] Use Swift venv Python interpreter The use of activate_this to access the venv libraries means that the system site packages are also included when the scripts swift_rings.py and swift_rings_check.py are run. This commit updates the interpreter directive for those scripts, when Swift is deployed in a venv, to use the venv's interpreter. Change-Id: I3ff0bf60c9ca695cddc28b05a8e8cc67d5f240e5 Closes-bug: 1538993 --- .../roles/os_swift_sync/tasks/swift_rings_build.yml | 8 ++++---- .../tasks/swift_rings_post_distribution_check.yml | 8 ++++---- .../roles/os_swift_sync/templates/swift_rings.py.j2 | 9 +-------- .../os_swift_sync/templates/swift_rings_check.py.j2 | 9 +-------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml index 65bdb15729..17e9fa963a 100644 --- a/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml @@ -51,7 +51,7 @@ - swift-rings-contents - name: "build rings for account/container from contents files" - command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item }}.contents" + command: "/etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item }}.contents" with_items: - account - container @@ -65,7 +65,7 @@ - swift-rings-build - name: "build rings for account/container from contents files" - command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" + command: "/etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" with_nested: - [ 'account', 'container' ] - "{{ swift_managed_regions }}" @@ -79,7 +79,7 @@ - swift-rings-build - name: "build rings for storage policies from contents files" - command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" + command: "/etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" with_items: - "{{ swift.storage_policies }}" when: swift_managed_regions is not defined @@ -92,7 +92,7 @@ - swift-rings-build - name: "build rings for storage policies from contents files" - command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" + command: "/etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" with_nested: - "{{ swift.storage_policies }}" - "{{ swift_managed_regions }}" diff --git a/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml index 371e9c87c1..095cfc9b92 100644 --- a/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml @@ -44,7 +44,7 @@ - swift-rings-scripts - name: "Ensure contents file matches ring after ring sync for account/container" - command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item }}.contents" + command: "/etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item }}.contents" with_items: - account - container @@ -58,7 +58,7 @@ - swift-rings-check - name: "Ensure contents file matches ring after ring sync for account/container" - command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" + command: "/etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" with_nested: - [ 'account', 'container' ] - "{{ swift_managed_regions }}" @@ -72,7 +72,7 @@ - swift-rings-check - name: "Ensure contents file matches ring after ring sync for storage policies" - command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" + command: "/etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" with_items: - "{{ swift.storage_policies }}" when: swift_managed_regions is not defined @@ -85,7 +85,7 @@ - swift-rings-check - name: "Ensure contents file matches ring after ring sync for storage policies" - command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" + command: "/etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" with_nested: - "{{ swift.storage_policies }}" - "{{ swift_managed_regions }}" diff --git a/playbooks/roles/os_swift_sync/templates/swift_rings.py.j2 b/playbooks/roles/os_swift_sync/templates/swift_rings.py.j2 index b430323c90..0b10618c89 100644 --- a/playbooks/roles/os_swift_sync/templates/swift_rings.py.j2 +++ b/playbooks/roles/os_swift_sync/templates/swift_rings.py.j2 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!{{ swift_venv_enabled | bool | ternary(swift_venv_bin + "/", "/usr/bin/env ") }}python # Copyright 2014, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,6 @@ from os.path import exists import os -{% if swift_venv_enabled | bool %} - -activate_this = os.path.expanduser("{{ swift_venv_bin }}/activate_this.py") -execfile(activate_this, dict(__file__=activate_this)) - -{% endif %} - from swift.cli.ringbuilder import main as rb_main import json diff --git a/playbooks/roles/os_swift_sync/templates/swift_rings_check.py.j2 b/playbooks/roles/os_swift_sync/templates/swift_rings_check.py.j2 index 827c05d5ac..a9fbe2f7bf 100644 --- a/playbooks/roles/os_swift_sync/templates/swift_rings_check.py.j2 +++ b/playbooks/roles/os_swift_sync/templates/swift_rings_check.py.j2 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!{{ swift_venv_enabled | bool | ternary(swift_venv_bin + "/", "/usr/bin/env ") }}python # Copyright 2014, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,6 @@ from os.path import exists import os -{% if swift_venv_enabled | bool %} - -activate_this = os.path.expanduser("{{ swift_venv_bin }}/activate_this.py") -execfile(activate_this, dict(__file__=activate_this)) - -{% endif %} - import json import pickle import sys