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
1=== added symlink 'actions/switch-python-version'
2=== target is '../hooks/hooks.py'
3=== modified file 'hooks/hooks.py'
4--- hooks/hooks.py 2019-04-30 20:50:18 +0000
5+++ hooks/hooks.py 2022-08-30 16:42:00 +0000
6@@ -2,8 +2,11 @@
7
8 import os
9 import sys
10+import shutil
11+import traceback
12 import charmhelpers.contrib.ansible
13 import charmhelpers.payload.execd
14+from charmhelpers.core import hookenv
15
16 # Create the hooks helper which automatically registers the
17 # required hooks based on the available tags in your playbook.
18@@ -69,6 +72,23 @@
19 return {'branch': branch}
20
21
22+@hooks.action()
23+def switch_python_version(python_version, build_label):
24+ # delete the venv and trigger the creation of a new one
25+ conf = hookenv.config()
26+ venv_dir = (
27+ '/srv/{hostname}/{deployment}/code/{build_label}/env'
28+ ).format(**conf)
29+ try:
30+ if os.path.exists(venv_dir):
31+ shutil.rmtree(venv_dir)
32+ except Exception:
33+ # something went terribly wrong, print something and re-raise
34+ print(traceback.format_exc())
35+ raise
36+ return {'python_version': python_version, 'build_label': build_label}
37+
38+
39 if __name__ == "__main__":
40 # workaround install.real script name
41 if 'install.real' in sys.argv[0]:
42
43=== modified file 'playbook.yaml'
44--- playbook.yaml 2022-07-19 21:31:55 +0000
45+++ playbook.yaml 2022-08-30 16:42:00 +0000
46@@ -97,6 +97,7 @@
47 - wsgi-file-relation-changed
48 - preload
49 - migrate
50+ - switch-python-version
51 stat: path={{ current_dir }}
52 register: payload
53
54@@ -145,10 +146,12 @@
55 - preload
56 - migrate
57 - install
58+ - switch-python-version
59 pip:
60 requirements: "{{ current_dir }}/requirements.txt"
61 virtualenv: "{{ venv }}"
62 virtualenv_command: "/usr/bin/virtualenv --never-download"
63+ virtualenv_python: "{{ python_version | default('python2.7') }}"
64 extra_args: "--no-index --find-links={{ wheel_dir }}"
65 virtualenv_site_packages: yes
66 when: build_label != "" and payload.stat.exists
67@@ -159,6 +162,7 @@
68 - memcached-relation-changed
69 - memcached-relation-departed
70 - migrate
71+ - switch-python-version
72 template:
73 src: "{{ charm_dir }}/templates/settings.py.j2"
74 dest: "{{ conf_dir }}/test_settings.py"
75@@ -170,6 +174,7 @@
76 - memcached-relation-changed
77 - memcached-relation-departed
78 - migrate
79+ - switch-python-version
80 become: yes
81 become_user: "{{ user }}"
82 command: "{{ python }} {{ manage }} check --pythonpath={{ conf_dir }} --settings=test_settings"
83@@ -183,6 +188,7 @@
84 - memcached-relation-changed
85 - memcached-relation-departed
86 - migrate
87+ - switch-python-version
88 command: mv "{{ conf_dir }}/test_settings.py" "{{ conf_dir }}/settings.py"
89 when: build_label != "" and payload.stat.exists
90 notify: Restart wsgi
91@@ -193,6 +199,7 @@
92 - memcached-relation-changed
93 - memcached-relation-departed
94 - migrate
95+ - switch-python-version
96 command: rm -f {{ conf_dir }}/test_settings.*
97 when: build_label != "" and payload.stat.exists
98

Subscribers

People subscribed via source and target branches