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.
3. Deduplicates the distro package installs. Right now the
   role installs the distro packages twice - just before
   building the venv, and during the python_venv_build role
   execution.

Depends-On: https://review.openstack.org/598957
Change-Id: I29833c41eba9b3ff80200b7f567a120f589e170e
Implements: blueprint python-build-install-simplification
Signed-off-by: Jesse Pretorius <jesse.pretorius@rackspace.co.uk>
Jesse Pretorius 1 year ago
parent
commit
faee049e24
6 changed files with 49 additions and 123 deletions
  1. 12
    1
      defaults/main.yml
  2. 9
    3
      handlers/main.yml
  3. 25
    116
      tasks/designate_install_source.yml
  4. 1
    1
      vars/redhat-7.yml
  5. 1
    1
      vars/suse-42.yml
  6. 1
    1
      vars/ubuntu.yml

+ 12
- 1
defaults/main.yml View File

@@ -42,8 +42,19 @@ designate_developer_mode: False
42 42
 designate_developer_constraints:
43 43
   - "git+{{ designate_git_repo }}@{{ designate_git_install_branch }}#egg=designate"
44 44
 
45
+# TODO(odyssey4me):
46
+# This can be simplified once all the roles are using
47
+# python_venv_build. We can then switch to using a
48
+# set of constraints in pip.conf inside the venv,
49
+# perhaps prepared by giving a giving a list of
50
+# constraints to the role.
51
+designate_pip_install_args: >-
52
+  {{ designate_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
53
+  {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''), '') }}
54
+  {{ pip_install_options | default('') }}
55
+
45 56
 # Name of the virtual env to deploy into
46
-designate_venv_tag: untagged
57
+designate_venv_tag: "{{ venv_tag | default('untagged') }}"
47 58
 designate_bin: "{{ _designate_bin }}"
48 59
 
49 60
 # Set the etc dir path where designate is installed.

+ 9
- 3
handlers/main.yml View File

@@ -23,7 +23,9 @@
23 23
   until: _stop is success
24 24
   retries: 5
25 25
   delay: 2
26
-  listen: Restart designate services
26
+  listen:
27
+    - "Restart designate services"
28
+    - "venv changed"
27 29
 
28 30
 # Note (odyssey4me):
29 31
 # The policy.json file is currently read continually by the services
@@ -41,7 +43,9 @@
41 43
     group: "{{ designate_system_group_name }}"
42 44
     mode: "0640"
43 45
     remote_src: yes
44
-  listen: Restart designate services
46
+  listen:
47
+    - "Restart designate services"
48
+    - "venv changed"
45 49
 
46 50
 - name: Start services
47 51
   systemd:
@@ -52,4 +56,6 @@
52 56
   until: _start is success
53 57
   retries: 5
54 58
   delay: 2
55
-  listen: Restart designate services
59
+  listen:
60
+    - "Restart designate services"
61
+    - "venv changed"

+ 25
- 116
tasks/designate_install_source.yml View File

@@ -13,18 +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 designate distro packages
17
-  package:
18
-    name: "{{ designate_developer_mode_distro_packages }}"
19
-    state: "{{ designate_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
-  when: designate_developer_mode | bool
23
-  register: install_packages
24
-  until: install_packages|success
25
-  retries: 5
26
-  delay: 2
27
-
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.
28 22
 - name: Create developer mode constraint file
29 23
   copy:
30 24
     dest: "/opt/developer-pip-constraints.txt"
@@ -34,108 +28,23 @@
34 28
       {% endfor %}
35 29
   when: designate_developer_mode | bool
36 30
 
37
-- name: Retrieve checksum for venv download
38
-  uri:
39
-    url: "{{ designate_venv_download_url | replace('tgz', 'checksum') }}"
40
-    return_content: yes
41
-  register: designate_venv_checksum
42
-  when: designate_venv_download | bool
43
-
44
-- name: Attempt venv download
45
-  get_url:
46
-    url: "{{ designate_venv_download_url }}"
47
-    dest: "/var/cache/{{ designate_venv_download_url | basename }}"
48
-    checksum: "sha1:{{ designate_venv_checksum.content | trim }}"
49
-  register: designate_get_venv
50
-  when: designate_venv_download | bool
51
-
52
-- name: Remove existing venv
53
-  file:
54
-    path: "{{ designate_bin | dirname }}"
55
-    state: absent
56
-  when: designate_get_venv is changed
57
-
58
-- name: Create designate venv dir
59
-  file:
60
-    path: "{{ designate_bin | dirname }}"
61
-    state: directory
62
-    mode: "0755"
63
-  register: designate_venv_dir
64
-  when: designate_get_venv is changed
65
-
66
-- name: Unarchive pre-built venv
67
-  unarchive:
68
-    src: "/var/cache/{{ designate_venv_download_url | basename }}"
69
-    dest: "{{ designate_bin | dirname }}"
70
-    copy: "no"
71
-  when: designate_get_venv is changed
72
-  notify:
73
-    - Restart designate services
74
-
75
-- name: Install pip packages
76
-  pip:
77
-    name: "{{ designate_pip_packages }}"
78
-    state: "{{ designate_pip_package_state }}"
79
-    virtualenv: "{{ designate_bin | dirname }}"
80
-    virtualenv_site_packages: "no"
81
-    extra_args: >-
82
-      {{ designate_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
83
-      {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
84
-      {{ pip_install_options | default('') }}
85
-  register: install_packages
86
-  until: install_packages is success
87
-  retries: 5
88
-  delay: 2
89
-  when: designate_get_venv | failed or designate_get_venv | skipped
90
-  notify:
91
-    - Restart designate services
92
-
93
-- name: Remove python from path first (CentOS, openSUSE)
94
-  file:
95
-    path:  "{{ designate_bin | dirname }}/bin/python2.7"
96
-    state: "absent"
31
+- name: Ensure remote wheel building is disabled in developer mode
32
+  set_fact:
33
+    venv_build_host: "{{ ansible_hostname }}"
97 34
   when:
98
-    - ansible_pkg_mgr in ['yum', 'dnf', 'zypper']
99
-    - not designate_developer_mode | bool
100
-    - designate_get_venv is changed
101
-
102
-# NOTE(odyssey4me):
103
-# We reinitialize the venv to ensure that the right
104
-# version of python is in the venv, but we do not
105
-# want virtualenv to also replace pip, setuptools
106
-# and wheel so we tell it not to.
107
-# We do not use --always-copy for CentOS/SuSE due
108
-# to https://github.com/pypa/virtualenv/issues/565
109
-- name: Update virtualenv path
110
-  shell: |
111
-    find {{ designate_bin }} -name \*.pyc -delete
112
-    sed -si '1s/^.*python.*$/#!{{ designate_bin | replace ('/','\/') }}\/python/' {{ designate_bin }}/*
113
-    virtualenv {{ designate_bin | dirname }} \
114
-        {{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \
115
-        --no-pip \
116
-        --no-setuptools \
117
-        --no-wheel
118
-  when: designate_get_venv is changed
119
-  tags:
120
-    - skip_ansible_lint
121
-
122
-- name: Install optional pip packages
123
-  pip:
124
-    name: "{{ designate_optional_oslomsg_amqp1_pip_packages }}"
125
-    state: "{{ designate_pip_package_state }}"
126
-    virtualenv: "{{ designate_bin | dirname }}"
127
-    virtualenv_site_packages: "no"
128
-  when: designate_oslomsg_amqp1_enabled
129
-  register: install_optional_packages
130
-  until: install_optional_packages is success
131
-  retries: 5
132
-  delay: 2
133
-  notify:
134
-    - Restart designate services
135
-
136
-- name: Record the venv tag deployed
137
-  ini_file:
138
-    dest: "/etc/ansible/facts.d/openstack_ansible.fact"
139
-    section: designate
140
-    option: venv_tag
141
-    value: "{{ designate_venv_tag }}"
35
+    - designate_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_build_distro_package_list: "{{ designate_devel_distro_packages }}"
43
+    venv_install_destination_path: "{{ designate_bin | dirname }}"
44
+    venv_install_distro_package_list: "{{ designate_distro_packages }}"
45
+    venv_pip_install_args: "{{ designate_pip_install_args }}"
46
+    venv_pip_packages: "{{ (designate_oslomsg_amqp1_enabled | bool) | ternary(designate_pip_packages + designate_optional_oslomsg_amqp1_pip_packages, designate_pip_packages) }}"
47
+    venv_facts_when_changed:
48
+      - section: "designate"
49
+        option: "venv_tag"
50
+        value: "{{ designate_venv_tag }}"

+ 1
- 1
vars/redhat-7.yml View File

@@ -32,5 +32,5 @@ designate_service_distro_packages:
32 32
 designate_rndc_packages:
33 33
   - bind
34 34
 
35
-designate_developer_mode_distro_packages:
35
+designate_devel_distro_packages:
36 36
   - systemd-devel

+ 1
- 1
vars/suse-42.yml View File

@@ -30,6 +30,6 @@ designate_service_distro_packages:
30 30
 designate_rndc_packages:
31 31
   - bind-utils
32 32
 
33
-designate_developer_mode_distro_packages:
33
+designate_devel_distro_packages:
34 34
   - pkg-config
35 35
   - systemd-devel

+ 1
- 1
vars/ubuntu.yml View File

@@ -35,7 +35,7 @@ designate_service_distro_packages:
35 35
 designate_rndc_packages:
36 36
   - bind9utils
37 37
 
38
-designate_developer_mode_distro_packages:
38
+designate_devel_distro_packages:
39 39
   - build-essential
40 40
   - libsystemd-dev
41 41
   - pkg-config

Loading…
Cancel
Save