Merge lp:~verterok/canonical-identity-provider/charm_switch-python-version into lp:~ubuntuone-pqm-team/canonical-identity-provider/charm

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 108
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~verterok/canonical-identity-provider/charm_switch-python-version
Merge into: lp:~ubuntuone-pqm-team/canonical-identity-provider/charm
Diff against target: 97 lines (+27/-0)
2 files modified
hooks/hooks.py (+20/-0)
playbook.yaml (+7/-0)
To merge this branch: bzr merge lp:~verterok/canonical-identity-provider/charm_switch-python-version
Reviewer Review Type Date Requested Status
John Paraskevopoulos Approve
Review via email: mp+429158@code.launchpad.net

Commit message

Add switch-python-version action to replace venv on a running unit

To post a comment you must log in.
Revision history for this message
John Paraskevopoulos (quantifics) wrote :

let's go and flip the switch!

review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
108. By Guillermo Gonzalez

fix lint

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added symlink 'actions/switch-python-version'
=== target is '../hooks/hooks.py'
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2019-04-30 20:50:18 +0000
+++ hooks/hooks.py 2022-08-30 16:42:00 +0000
@@ -2,8 +2,11 @@
22
3import os3import os
4import sys4import sys
5import shutil
6import traceback
5import charmhelpers.contrib.ansible7import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd8import charmhelpers.payload.execd
9from charmhelpers.core import hookenv
710
8# Create the hooks helper which automatically registers the11# Create the hooks helper which automatically registers the
9# required hooks based on the available tags in your playbook.12# required hooks based on the available tags in your playbook.
@@ -69,6 +72,23 @@
69 return {'branch': branch}72 return {'branch': branch}
7073
7174
75@hooks.action()
76def switch_python_version(python_version, build_label):
77 # delete the venv and trigger the creation of a new one
78 conf = hookenv.config()
79 venv_dir = (
80 '/srv/{hostname}/{deployment}/code/{build_label}/env'
81 ).format(**conf)
82 try:
83 if os.path.exists(venv_dir):
84 shutil.rmtree(venv_dir)
85 except Exception:
86 # something went terribly wrong, print something and re-raise
87 print(traceback.format_exc())
88 raise
89 return {'python_version': python_version, 'build_label': build_label}
90
91
72if __name__ == "__main__":92if __name__ == "__main__":
73 # workaround install.real script name93 # workaround install.real script name
74 if 'install.real' in sys.argv[0]:94 if 'install.real' in sys.argv[0]:
7595
=== modified file 'playbook.yaml'
--- playbook.yaml 2022-07-19 21:31:55 +0000
+++ playbook.yaml 2022-08-30 16:42:00 +0000
@@ -97,6 +97,7 @@
97 - wsgi-file-relation-changed97 - wsgi-file-relation-changed
98 - preload98 - preload
99 - migrate99 - migrate
100 - switch-python-version
100 stat: path={{ current_dir }}101 stat: path={{ current_dir }}
101 register: payload102 register: payload
102103
@@ -145,10 +146,12 @@
145 - preload146 - preload
146 - migrate147 - migrate
147 - install148 - install
149 - switch-python-version
148 pip:150 pip:
149 requirements: "{{ current_dir }}/requirements.txt"151 requirements: "{{ current_dir }}/requirements.txt"
150 virtualenv: "{{ venv }}"152 virtualenv: "{{ venv }}"
151 virtualenv_command: "/usr/bin/virtualenv --never-download"153 virtualenv_command: "/usr/bin/virtualenv --never-download"
154 virtualenv_python: "{{ python_version | default('python2.7') }}"
152 extra_args: "--no-index --find-links={{ wheel_dir }}"155 extra_args: "--no-index --find-links={{ wheel_dir }}"
153 virtualenv_site_packages: yes156 virtualenv_site_packages: yes
154 when: build_label != "" and payload.stat.exists157 when: build_label != "" and payload.stat.exists
@@ -159,6 +162,7 @@
159 - memcached-relation-changed162 - memcached-relation-changed
160 - memcached-relation-departed163 - memcached-relation-departed
161 - migrate164 - migrate
165 - switch-python-version
162 template:166 template:
163 src: "{{ charm_dir }}/templates/settings.py.j2"167 src: "{{ charm_dir }}/templates/settings.py.j2"
164 dest: "{{ conf_dir }}/test_settings.py"168 dest: "{{ conf_dir }}/test_settings.py"
@@ -170,6 +174,7 @@
170 - memcached-relation-changed174 - memcached-relation-changed
171 - memcached-relation-departed175 - memcached-relation-departed
172 - migrate176 - migrate
177 - switch-python-version
173 become: yes178 become: yes
174 become_user: "{{ user }}"179 become_user: "{{ user }}"
175 command: "{{ python }} {{ manage }} check --pythonpath={{ conf_dir }} --settings=test_settings"180 command: "{{ python }} {{ manage }} check --pythonpath={{ conf_dir }} --settings=test_settings"
@@ -183,6 +188,7 @@
183 - memcached-relation-changed188 - memcached-relation-changed
184 - memcached-relation-departed189 - memcached-relation-departed
185 - migrate190 - migrate
191 - switch-python-version
186 command: mv "{{ conf_dir }}/test_settings.py" "{{ conf_dir }}/settings.py"192 command: mv "{{ conf_dir }}/test_settings.py" "{{ conf_dir }}/settings.py"
187 when: build_label != "" and payload.stat.exists193 when: build_label != "" and payload.stat.exists
188 notify: Restart wsgi194 notify: Restart wsgi
@@ -193,6 +199,7 @@
193 - memcached-relation-changed199 - memcached-relation-changed
194 - memcached-relation-departed200 - memcached-relation-departed
195 - migrate201 - migrate
202 - switch-python-version
196 command: rm -f {{ conf_dir }}/test_settings.*203 command: rm -f {{ conf_dir }}/test_settings.*
197 when: build_label != "" and payload.stat.exists204 when: build_label != "" and payload.stat.exists
198205

Subscribers

People subscribed via source and target branches