Merge ~cjwatson/launchpad-mojo-specs:utils-check-python-version into launchpad-mojo-specs:master

Proposed by Colin Watson
Status: Merged
Merged at revision: 476e947625c401a29b366bd731abf086a7a3a669
Proposed branch: ~cjwatson/launchpad-mojo-specs:utils-check-python-version
Merge into: launchpad-mojo-specs:master
Diff against target: 248 lines (+65/-16)
17 files modified
lp-codeimport/update-code-asset (+3/-1)
lp-codeimport/upgrade-charms (+3/-1)
mojo-lp-git/run-payload-tests (+3/-1)
mojo-lp-git/update-code-asset (+3/-1)
mojo-lp-git/upgrade-charms (+3/-1)
mojo-lp-signing/update-code-asset (+3/-1)
mojo-lp-signing/upgrade-charms (+3/-1)
utils/add-floating-ip (+3/-1)
utils/check_version.py (+17/-0)
utils/custom-secgroups.py (+3/-1)
utils/get-last-build-label (+3/-1)
utils/get-swift-storage-url (+3/-1)
utils/make-branches (+3/-1)
utils/publish-build-assets (+3/-1)
utils/publish-last-build-label (+3/-1)
utils/set-local-config (+3/-1)
utils/set-service-options (+3/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+404120@code.launchpad.net

Commit message

Re-exec scripts using Python 2 where necessary

Description of the change

wendigo (the devops management host for PS4.5) is old and lacks a number of Python 3 libraries that we use; however, when deploying to PS5, we need to run on Ubuntu 20.04 LTS, which lacks Python 2 versions of the same libraries. To escape this Catch-22, re-exec ourselves using Python 2 if we find ourselves on a system that's known to be too old to support the Python 3 libraries we need.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lp-codeimport/update-code-asset b/lp-codeimport/update-code-asset
2index fdc7fbf..e7386e3 100755
3--- a/lp-codeimport/update-code-asset
4+++ b/lp-codeimport/update-code-asset
5@@ -1,4 +1,6 @@
6-#! /usr/bin/python
7+#! /usr/bin/python3
8+
9+import utils.check_version # noqa: F401
10
11 import os
12 import subprocess
13diff --git a/lp-codeimport/upgrade-charms b/lp-codeimport/upgrade-charms
14index ef477c7..10bf64e 100755
15--- a/lp-codeimport/upgrade-charms
16+++ b/lp-codeimport/upgrade-charms
17@@ -1,4 +1,6 @@
18-#! /usr/bin/python
19+#! /usr/bin/python3
20+
21+import utils.check_version # noqa: F401
22
23 import os.path
24 import subprocess
25diff --git a/mojo-lp-git/run-payload-tests b/mojo-lp-git/run-payload-tests
26index 8d9e5eb..7e61ac4 100755
27--- a/mojo-lp-git/run-payload-tests
28+++ b/mojo-lp-git/run-payload-tests
29@@ -1,4 +1,6 @@
30-#! /usr/bin/python
31+#! /usr/bin/python3
32+
33+import utils.check_version # noqa: F401
34
35 import os
36 import subprocess
37diff --git a/mojo-lp-git/update-code-asset b/mojo-lp-git/update-code-asset
38index bfc3c23..12492d9 100755
39--- a/mojo-lp-git/update-code-asset
40+++ b/mojo-lp-git/update-code-asset
41@@ -1,4 +1,6 @@
42-#! /usr/bin/python
43+#! /usr/bin/python3
44+
45+import utils.check_version # noqa: F401
46
47 import os
48 import subprocess
49diff --git a/mojo-lp-git/upgrade-charms b/mojo-lp-git/upgrade-charms
50index f215db1..4f5d386 100755
51--- a/mojo-lp-git/upgrade-charms
52+++ b/mojo-lp-git/upgrade-charms
53@@ -1,4 +1,6 @@
54-#! /usr/bin/python
55+#! /usr/bin/python3
56+
57+import utils.check_version # noqa: F401
58
59 import os.path
60 import subprocess
61diff --git a/mojo-lp-signing/update-code-asset b/mojo-lp-signing/update-code-asset
62index b140f51..aebf69b 100755
63--- a/mojo-lp-signing/update-code-asset
64+++ b/mojo-lp-signing/update-code-asset
65@@ -1,4 +1,6 @@
66-#! /usr/bin/python
67+#! /usr/bin/python3
68+
69+import utils.check_version # noqa: F401
70
71 import os
72 import subprocess
73diff --git a/mojo-lp-signing/upgrade-charms b/mojo-lp-signing/upgrade-charms
74index 9c69500..aa339ee 100755
75--- a/mojo-lp-signing/upgrade-charms
76+++ b/mojo-lp-signing/upgrade-charms
77@@ -1,4 +1,6 @@
78-#! /usr/bin/python
79+#! /usr/bin/python3
80+
81+import utils.check_version # noqa: F401
82
83 import os.path
84 import subprocess
85diff --git a/utils/add-floating-ip b/utils/add-floating-ip
86index 4540b3f..2024af6 100755
87--- a/utils/add-floating-ip
88+++ b/utils/add-floating-ip
89@@ -1,10 +1,12 @@
90-#!/usr/bin/python
91+#!/usr/bin/python3
92 #
93 # Authors: Paul Gear, Neale Pickett
94 # Description: Manage floating IP allocations in mojo local directory for a juju service or unit.
95 # NOTE: $MOJO_PROJECT and $MOJO_STAGE must be set before calling this script.
96 #
97
98+import check_version # noqa: F401
99+
100 import json
101 import os
102 import subprocess
103diff --git a/utils/check_version.py b/utils/check_version.py
104new file mode 100644
105index 0000000..acf82ea
106--- /dev/null
107+++ b/utils/check_version.py
108@@ -0,0 +1,17 @@
109+# At the time of writing (June 2021), we still need to deploy code to PS4.5.
110+# The devops management host for that cloud runs Ubuntu 14.04, which has
111+# Python 3.4, and which also doesn't have many of the libraries we need
112+# packaged for Python 3. This abominable hack checks whether we're on 3.4,
113+# and if so re-execs itself using Python 2.
114+#
115+# The Python version itself isn't really the important factor here, but it's
116+# a proxy indicator that we can check easily.
117+#
118+# We should drop this as soon as we no longer need to support deploying from
119+# Ubuntu 14.04.
120+
121+import os
122+import sys
123+
124+if sys.version_info[0] == 3 and sys.version_info[1] < 5:
125+ os.execv('/usr/bin/python2', [sys.argv[0]] + sys.argv)
126diff --git a/utils/custom-secgroups.py b/utils/custom-secgroups.py
127index af4eab5..f4e1059 100755
128--- a/utils/custom-secgroups.py
129+++ b/utils/custom-secgroups.py
130@@ -1,9 +1,11 @@
131-#! /usr/bin/python
132+#! /usr/bin/python3
133 # By wgrant, with some neutron manipulation stolen from cjwatson's
134 # clean-up-secgroups.py.
135
136 from __future__ import print_function
137
138+import check_version # noqa: F401
139+
140 __metaclass__ = type
141
142 import argparse
143diff --git a/utils/get-last-build-label b/utils/get-last-build-label
144index fa26837..a12e797 100755
145--- a/utils/get-last-build-label
146+++ b/utils/get-last-build-label
147@@ -1,4 +1,4 @@
148-#! /usr/bin/python
149+#! /usr/bin/python3
150
151 """Print the last build label in a particular state.
152
153@@ -8,6 +8,8 @@ shell.
154
155 from __future__ import print_function
156
157+import check_version # noqa: F401
158+
159 import os
160
161 import utils
162diff --git a/utils/get-swift-storage-url b/utils/get-swift-storage-url
163index 3119867..e34a597 100755
164--- a/utils/get-swift-storage-url
165+++ b/utils/get-swift-storage-url
166@@ -1,9 +1,11 @@
167-#! /usr/bin/python
168+#! /usr/bin/python3
169
170 """Print the Swift storage URL."""
171
172 from __future__ import print_function
173
174+import check_version # noqa: F401
175+
176 import utils
177
178
179diff --git a/utils/make-branches b/utils/make-branches
180index f4ab582..c34bcb5 100755
181--- a/utils/make-branches
182+++ b/utils/make-branches
183@@ -1,4 +1,6 @@
184-#! /usr/bin/python
185+#! /usr/bin/python3
186+
187+import check_version # noqa: F401
188
189 import os
190 import shutil
191diff --git a/utils/publish-build-assets b/utils/publish-build-assets
192index 158bdc8..11ddd18 100755
193--- a/utils/publish-build-assets
194+++ b/utils/publish-build-assets
195@@ -1,4 +1,6 @@
196-#! /usr/bin/python
197+#! /usr/bin/python3
198+
199+import check_version # noqa: F401
200
201 import os
202
203diff --git a/utils/publish-last-build-label b/utils/publish-last-build-label
204index 7bdf13c..0ff812b 100755
205--- a/utils/publish-last-build-label
206+++ b/utils/publish-last-build-label
207@@ -1,8 +1,10 @@
208-#! /usr/bin/python
209+#! /usr/bin/python3
210
211 """Publishes the last attempted build label to a specific swift file
212 for use by other jobs which may trigger a spec run."""
213
214+import check_version # noqa: F401
215+
216 import os
217 import shutil
218 import tempfile
219diff --git a/utils/set-local-config b/utils/set-local-config
220index 21ab9e1..123059c 100755
221--- a/utils/set-local-config
222+++ b/utils/set-local-config
223@@ -1,7 +1,9 @@
224-#! /usr/bin/python
225+#! /usr/bin/python3
226
227 from __future__ import print_function
228
229+import check_version # noqa: F401
230+
231 import argparse
232 import os.path
233
234diff --git a/utils/set-service-options b/utils/set-service-options
235index bb5c1e1..8b12678 100755
236--- a/utils/set-service-options
237+++ b/utils/set-service-options
238@@ -1,7 +1,9 @@
239-#! /usr/bin/python
240+#! /usr/bin/python3
241
242 from __future__ import print_function
243
244+import check_version # noqa: F401
245+
246 import base64
247 import numbers
248 import sys

Subscribers

People subscribed via source and target branches