Browse Source

Use a common python build/install role

In order to radically simplify how we prepare the service
venvs, we use a common role to do the wheel builds and the
venv preparation. This makes the process far simpler to
understand, because the role does its own building and
installing. It also reduces the code maintenance burden,
because instead of duplicating the build processes in the
repo_build role and the service role - we only have it all
done in a single place.

We also change the role venv tag var to use the integrated
build's common venv tag so that we can remove the role's
venv tag in group_vars in the integrated build. This reduces
memory consumption and also reduces the duplication.

This is by no means the final stop in the simplification
process, but it is a step forward. The will be work to follow
which:

1. Replaces 'developer mode' with an equivalent mechanism
   that uses the common role and is simpler to understand.
   We will also simplify the provisioning of pip install
   arguments when doing this.
2. Simplifies the installation of optional pip packages.
   Right now it's more complicated than it needs to be due
   to us needing to keep the py_pkgs plugin working in the
   integrated build.

Depends-On: https://review.openstack.org/598957
Change-Id: I7a6acaa94265b21fb886a775c3b5b86a4142a905
Implements: blueprint python-build-install-simplification
Signed-off-by: Jesse Pretorius <jesse.pretorius@rackspace.co.uk>
Jesse Pretorius 1 year ago
parent
commit
48aaa17291
3 changed files with 44 additions and 129 deletions
  1. 11
    1
      defaults/main.yml
  2. 9
    3
      handlers/main.yml
  3. 24
    125
      tasks/gnocchi_install.yml

+ 11
- 1
defaults/main.yml View File

@@ -54,8 +54,18 @@ gnocchi_secure_proxy_ssl_header: HTTP_X_FORWARDED_PROTO
54 54
 #: Set this to false to disable API service through Apache + mod_wsgi
55 55
 gnocchi_use_mod_wsgi: true
56 56
 
57
+# TODO(odyssey4me):
58
+# This can be simplified once all the roles are using
59
+# python_venv_build. We can then switch to using a
60
+# set of constraints in pip.conf inside the venv,
61
+# perhaps prepared by giving a giving a list of
62
+# constraints to the role.
63
+gnocchi_pip_install_args: >-
64
+  {{ gnocchi_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
65
+  {{ pip_install_options | default('') }}
66
+
57 67
 #: Name of the virtual env to deploy into
58
-gnocchi_venv_tag: untagged
68
+gnocchi_venv_tag: "{{ venv_tag | default('untagged') }}"
59 69
 gnocchi_bin: "/openstack/venvs/gnocchi-{{ gnocchi_venv_tag }}/bin"
60 70
 gnocchi_venv_pkgs: "/openstack/venvs/gnocchi-{{ gnocchi_venv_tag }}/lib/python2.7/site-packages"
61 71
 

+ 9
- 3
handlers/main.yml View File

@@ -27,7 +27,9 @@
27 27
   until: _stop is success
28 28
   retries: 5
29 29
   delay: 2
30
-  listen: Restart gnocchi services
30
+  listen:
31
+    - "Restart gnocchi services"
32
+    - "venv changed"
31 33
 
32 34
 # Note (odyssey4me):
33 35
 # The policy.json file is currently read continually by the services
@@ -45,7 +47,9 @@
45 47
     group: "{{ gnocchi_system_group_name }}"
46 48
     mode: "0640"
47 49
     remote_src: yes
48
-  listen: Restart gnocchi services
50
+  listen:
51
+    - "Restart gnocchi services"
52
+    - "venv changed"
49 53
 
50 54
 - name: Start services
51 55
   service:
@@ -61,7 +65,9 @@
61 65
   until: _start is success
62 66
   retries: 5
63 67
   delay: 2
64
-  listen: Restart gnocchi services
68
+  listen:
69
+    - "Restart gnocchi services"
70
+    - "venv changed"
65 71
 
66 72
 - name: Restart web server
67 73
   service:

+ 24
- 125
tasks/gnocchi_install.yml View File

@@ -13,17 +13,12 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
-- name: Install distro packages
17
-  package:
18
-    name: "{{ gnocchi_distro_packages }}"
19
-    state: "{{ gnocchi_package_state }}"
20
-    update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
21
-    cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
22
-  register: install_packages
23
-  until: install_packages is success
24
-  retries: 5
25
-  delay: 2
26
-
16
+# TODO(odyssey4me):
17
+# This can be simplified once all the roles are using
18
+# python_venv_build. We can then switch to using a
19
+# set of constraints in pip.conf inside the venv,
20
+# perhaps prepared by giving a giving a list of
21
+# constraints to the role.
27 22
 - name: Create developer mode constraint file
28 23
   copy:
29 24
     dest: "/opt/developer-pip-constraints.txt"
@@ -33,118 +28,22 @@
33 28
       {% endfor %}
34 29
   when: gnocchi_developer_mode | bool
35 30
 
36
-- name: Retrieve checksum for venv download
37
-  uri:
38
-    url: "{{ gnocchi_venv_download_url | replace('tgz', 'checksum') }}"
39
-    return_content: yes
40
-  register: gnocchi_venv_checksum
41
-  when: gnocchi_venv_download | bool
42
-
43
-- name: Attempt venv download
44
-  get_url:
45
-    url: "{{ gnocchi_venv_download_url }}"
46
-    dest: "/var/cache/{{ gnocchi_venv_download_url | basename }}"
47
-    checksum: "sha1:{{ gnocchi_venv_checksum.content | trim }}"
48
-  register: gnocchi_get_venv
49
-  when: gnocchi_venv_download | bool
50
-
51
-- name: Remove existing venv
52
-  file:
53
-    path: "{{ gnocchi_bin | dirname }}"
54
-    state: absent
55
-  when: gnocchi_get_venv  is changed
56
-
57
-- name: Create gnocchi venv dir
58
-  file:
59
-    path: "{{ gnocchi_bin | dirname }}"
60
-    state: directory
61
-    mode: "0755"
62
-  register: gnocchi_venv_dir
63
-  when: gnocchi_get_venv  is changed
64
-
65
-- name: Unarchive pre-built venv
66
-  unarchive:
67
-    src: "/var/cache/{{ gnocchi_venv_download_url | basename }}"
68
-    dest: "{{ gnocchi_bin | dirname }}"
69
-    copy: "no"
70
-  when: gnocchi_get_venv  is changed
71
-  notify:
72
-    - Restart gnocchi services
73
-    - Restart web server
74
-
75
-- name: Create the python venv and install packages into it
76
-  when: gnocchi_get_venv | failed or gnocchi_get_venv | skipped
77
-  block:
78
-    - name: Create the virtualenv (if it does not exist)
79
-      command: "virtualenv --never-download --no-site-packages {{ gnocchi_bin | dirname }}"
80
-      args:
81
-        creates: "{{ gnocchi_bin }}/activate"
82
-
83
-    - name: Upgrade pip/setuptools/wheel to the versions we want
84
-      pip:
85
-        name:
86
-          - pip
87
-          - setuptools
88
-          - wheel
89
-        state: "{{ gnocchi_pip_package_state }}"
90
-        virtualenv: "{{ gnocchi_bin | dirname }}"
91
-        virtualenv_site_packages: "no"
92
-        extra_args: >-
93
-          {{ gnocchi_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
94
-          {{ pip_install_options | default('') }}
95
-      register: install_packages
96
-      until: install_packages is success
97
-      retries: 5
98
-      delay: 2
99
-
100
-    - name: Install pip packages
101
-      pip:
102
-        name: "{{ gnocchi_pip_packages }}"
103
-        state: "{{ gnocchi_pip_package_state }}"
104
-        virtualenv: "{{ gnocchi_bin | dirname }}"
105
-        virtualenv_site_packages: "no"
106
-        extra_args: >-
107
-          {{ gnocchi_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
108
-          {{ pip_install_options | default('') }}
109
-      register: install_packages
110
-      until: install_packages is success
111
-      retries: 5
112
-      delay: 2
113
-      notify:
114
-        - Restart gnocchi services
115
-        - Restart web server
116
-
117
-- name: Remove python from path first (CentOS, openSUSE)
118
-  file:
119
-    path:  "{{ gnocchi_bin | dirname }}/bin/python2.7"
120
-    state: "absent"
31
+- name: Ensure remote wheel building is disabled in developer mode
32
+  set_fact:
33
+    venv_build_host: "{{ ansible_hostname }}"
121 34
   when:
122
-    - ansible_pkg_mgr in ['yum', 'dnf', 'zypper']
123
-    - gnocchi_get_venv  is changed
124
-
125
-# NOTE(odyssey4me):
126
-# We reinitialize the venv to ensure that the right
127
-# version of python is in the venv, but we do not
128
-# want virtualenv to also replace pip, setuptools
129
-# and wheel so we tell it not to.
130
-# We do not use --always-copy for CentOS/SuSE due
131
-# to https://github.com/pypa/virtualenv/issues/565
132
-- name: Update virtualenv path
133
-  shell: |
134
-    find {{ gnocchi_bin }} -name \*.pyc -delete
135
-    sed -si '1s/^.*python.*$/#!{{ gnocchi_bin | replace ('/','\/') }}\/python/' {{ gnocchi_bin }}/*
136
-    virtualenv {{ gnocchi_bin | dirname }} \
137
-        {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \
138
-        --no-pip \
139
-        --no-setuptools \
140
-        --no-wheel
141
-  when: gnocchi_get_venv  is changed
142
-  tags:
143
-    - skip_ansible_lint
144
-
145
-- name: Record the venv tag deployed
146
-  ini_file:
147
-    dest: "/etc/ansible/facts.d/openstack_ansible.fact"
148
-    section: gnocchi
149
-    option: venv_tag
150
-    value: "{{ gnocchi_venv_tag }}"
35
+    - gnocchi_developer_mode | bool
36
+
37
+- name: Install the python venv
38
+  include_role:
39
+    name: "python_venv_build"
40
+    private: yes
41
+  vars:
42
+    venv_install_destination_path: "{{ gnocchi_bin | dirname }}"
43
+    venv_install_distro_package_list: "{{ gnocchi_distro_packages }}"
44
+    venv_pip_install_args: "{{ gnocchi_pip_install_args }}"
45
+    venv_pip_packages: "{{ gnocchi_pip_packages }}"
46
+    venv_facts_when_changed:
47
+      - section: "gnocchi"
48
+        option: "venv_tag"
49
+        value: "{{ gnocchi_venv_tag }}"

Loading…
Cancel
Save