Merge ~jslarraz/ubuntu-security-tools:jslarraz/umt_changelog into ubuntu-security-tools:master
- Git
- lp:~jslarraz/ubuntu-security-tools
- jslarraz/umt_changelog
- Merge into master
Status: | Merged |
---|---|
Merged at revision: | 5dbd3217ff97bc7a988b865219791cda61186929 |
Proposed branch: | ~jslarraz/ubuntu-security-tools:jslarraz/umt_changelog |
Merge into: | ubuntu-security-tools:master |
Diff against target: |
239 lines (+149/-13) 3 files modified
build-tools/umt (+2/-1) package-tools/increment_version.py (+87/-9) package-tools/tests/test_increment_version.py (+60/-3) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Eduardo Barretto | Approve | ||
Alex Murray | Approve | ||
Review via email: mp+450145@code.launchpad.net |
Commit message
1) Adding support to umt changelog for ~0.XX.YY.1 and ~XX.YY.1 ending version names. 2) Enable changelog to suggest correct new version name when several releases are using the same original package version
Description of the change
The increment_
changelog has been modified to use rmadison to check whether other ubuntu releases are using the same package version to include the XX.YY in the proposed version when necessary.
Alex Murray (alexmurray) wrote : | # |
I like the idea of having umt changelog try and be more helpful but if possible can we add a test for this? (or could you include as a comment here what the new output is compared to the old behaviour so it is easier to review?)
Jorge Sancho Larraz (jslarraz) wrote : | # |
I have added some test cases to verify (hopefully) the expected behavior. Please check not only the code looks good but also that test cases are correct.
Eduardo Barretto (ebarretto) wrote : | # |
just some small comments in a specific case
Jorge Sancho Larraz (jslarraz) : | # |
Eduardo Barretto (ebarretto) wrote : | # |
lgtm, thanks!
Preview Diff
1 | diff --git a/build-tools/umt b/build-tools/umt | |||
2 | index 2417175..3cdeee4 100755 | |||
3 | --- a/build-tools/umt | |||
4 | +++ b/build-tools/umt | |||
5 | @@ -416,7 +416,8 @@ def cmd_changelog(): | |||
6 | 416 | if not note: | 416 | if not note: |
7 | 417 | note = "No-change re-build upload." | 417 | note = "No-change re-build upload." |
8 | 418 | else: | 418 | else: |
10 | 419 | new_ver = increment_version_security(details['version'], opt.esm) | 419 | pkg_list = search_packages(details['package'], use_rmadison=True) # Avoid dependencies on local installation |
11 | 420 | new_ver = increment_version_security(details['version'], opt.esm, details=details, pkg_list=pkg_list) | ||
12 | 420 | 421 | ||
13 | 421 | if opt.repeat: | 422 | if opt.repeat: |
14 | 422 | repeat_release = opt.release | 423 | repeat_release = opt.release |
15 | diff --git a/package-tools/increment_version.py b/package-tools/increment_version.py | |||
16 | index 6da79f6..7c48ca3 100644 | |||
17 | --- a/package-tools/increment_version.py | |||
18 | +++ b/package-tools/increment_version.py | |||
19 | @@ -1,3 +1,11 @@ | |||
20 | 1 | # add location of source_map.py so this can be found since it is in UCT | ||
21 | 2 | import os | ||
22 | 3 | import sys | ||
23 | 4 | uct_path = os.getenv("UCT") | ||
24 | 5 | if uct_path is not None: | ||
25 | 6 | sys.path.append(os.path.join(uct_path, "scripts")) | ||
26 | 7 | import cve_lib | ||
27 | 8 | |||
28 | 1 | import re | 9 | import re |
29 | 2 | 10 | ||
30 | 3 | def _validate_version(old_version): | 11 | def _validate_version(old_version): |
31 | @@ -10,6 +18,68 @@ def _validate_version(old_version): | |||
32 | 10 | 18 | ||
33 | 11 | return old_version | 19 | return old_version |
34 | 12 | 20 | ||
35 | 21 | def get_suffix(devel, details, pkg_list): | ||
36 | 22 | if devel: | ||
37 | 23 | suffix = "ubuntu1" | ||
38 | 24 | else: | ||
39 | 25 | suffix = "ubuntu0.1" | ||
40 | 26 | if (details is not None) and (pkg_list is not None): | ||
41 | 27 | release_id = get_release_id(details, pkg_list) | ||
42 | 28 | if release_id is not None: | ||
43 | 29 | suffix = "ubuntu0." + release_id + ".1" | ||
44 | 30 | return suffix | ||
45 | 31 | |||
46 | 32 | def get_release_id(details, pkg_list): | ||
47 | 33 | release_id = None | ||
48 | 34 | if (details is None) or (pkg_list is None) or \ | ||
49 | 35 | (False in [x in details for x in ['package', 'release']]): | ||
50 | 36 | return None | ||
51 | 37 | |||
52 | 38 | target_release = details['release'] | ||
53 | 39 | old_version = pkg_list[target_release][0] | ||
54 | 40 | |||
55 | 41 | if (not 'ubuntu' in old_version) and (not 'esm' in old_version): | ||
56 | 42 | base_version = get_base_version(old_version) | ||
57 | 43 | for release in pkg_list: | ||
58 | 44 | # The same package version is used in several releases | ||
59 | 45 | if ( | ||
60 | 46 | (cve_lib.get_orig_rel_name(release) in cve_lib.releases) | ||
61 | 47 | and (cve_lib.get_orig_rel_name(release) != target_release) | ||
62 | 48 | and (base_version == get_base_version(pkg_list[release][0])) | ||
63 | 49 | and ( | ||
64 | 50 | cve_lib.is_active_release(release) | ||
65 | 51 | or ( | ||
66 | 52 | cve_lib.is_active_esm_release(release) | ||
67 | 53 | and ( | ||
68 | 54 | is_srcpkg_supported(details['package'], cve_lib.get_esm_name(release, pkg_list[release][2])) | ||
69 | 55 | or ('ubuntu' in pkg_list[release][0]) | ||
70 | 56 | ) | ||
71 | 57 | ) | ||
72 | 58 | ) | ||
73 | 59 | ): | ||
74 | 60 | release_name = cve_lib.subprojects['ubuntu/' + target_release]['name'] | ||
75 | 61 | release_id = release_name.split(' ')[1] | ||
76 | 62 | return release_id | ||
77 | 63 | |||
78 | 64 | def get_base_version(version): | ||
79 | 65 | if 'build' in version: | ||
80 | 66 | return version.split('build')[0] | ||
81 | 67 | elif 'ubuntu' in version: | ||
82 | 68 | return version.split('ubuntu')[0] | ||
83 | 69 | elif re.search("~([0-9]+\\.)?([0-9]{2}\\.[0-9]{2})(\\.[0-9]+)$", version): | ||
84 | 70 | return '~'.join(version.split('~')[:-1]) | ||
85 | 71 | else: | ||
86 | 72 | return version | ||
87 | 73 | |||
88 | 74 | def is_srcpkg_supported(srcpkg, esm_release): | ||
89 | 75 | file = esm_release.replace('/', '-') + '-supported.txt' | ||
90 | 76 | f = open(uct_path + '/' + file, 'r') | ||
91 | 77 | supported_packages = f.readlines() | ||
92 | 78 | f.close() | ||
93 | 79 | for supported_package in supported_packages: | ||
94 | 80 | if (srcpkg + '\n' == supported_package): | ||
95 | 81 | return True | ||
96 | 82 | return False | ||
97 | 13 | 83 | ||
98 | 14 | def increment_version_build(old_version): | 84 | def increment_version_build(old_version): |
99 | 15 | """Returns an incremented version number per no-change build rules""" | 85 | """Returns an incremented version number per no-change build rules""" |
100 | @@ -31,14 +101,13 @@ def increment_version_build(old_version): | |||
101 | 31 | new_version = old_version + "build1" | 101 | new_version = old_version + "build1" |
102 | 32 | return new_version | 102 | return new_version |
103 | 33 | 103 | ||
106 | 34 | 104 | def increment_version_security(old_version, esm=False, devel=False, details=None, pkg_list=None): | |
105 | 35 | def increment_version_security(old_version, esm=False, devel=False): | ||
107 | 36 | """Returns an incremented version number per security update rules""" | 105 | """Returns an incremented version number per security update rules""" |
108 | 37 | old_version = _validate_version(old_version) | 106 | old_version = _validate_version(old_version) |
109 | 38 | 107 | ||
110 | 39 | if "build" in old_version: | 108 | if "build" in old_version: |
111 | 40 | # eg 2.0-2build1 | 109 | # eg 2.0-2build1 |
113 | 41 | suffix = "ubuntu0.1" if not devel else "ubuntu1" | 110 | suffix = get_suffix(devel, details, pkg_list) |
114 | 42 | new_version = re.sub("build.*", "", old_version) + suffix | 111 | new_version = re.sub("build.*", "", old_version) + suffix |
115 | 43 | if esm: | 112 | if esm: |
116 | 44 | new_version = new_version + "~esm1" | 113 | new_version = new_version + "~esm1" |
117 | @@ -71,18 +140,27 @@ def increment_version_security(old_version, esm=False, devel=False): | |||
118 | 71 | ) | 140 | ) |
119 | 72 | elif not "-" in old_version or re.search("-[+a-z.0-9]+$", old_version): | 141 | elif not "-" in old_version or re.search("-[+a-z.0-9]+$", old_version): |
120 | 73 | # eg 2.0-2 or 2.0cvs.20060707-2 or 1.5.0-3+cvs20071006 | 142 | # eg 2.0-2 or 2.0cvs.20060707-2 or 1.5.0-3+cvs20071006 |
122 | 74 | suffix = "ubuntu0.1" if not devel else "ubuntu1" | 143 | suffix = get_suffix(devel, details, pkg_list) |
123 | 75 | new_version = old_version + suffix | 144 | new_version = old_version + suffix |
124 | 76 | if esm: | 145 | if esm: |
125 | 77 | new_version = new_version + "~esm1" | 146 | new_version = new_version + "~esm1" |
128 | 78 | elif re.search(r"~\d{2}\.\d{2}$", old_version): | 147 | elif re.search("~([0-9]+\\.)?([0-9]{2}\\.[0-9]{2})(\\.[0-9]+)$", old_version): |
129 | 79 | # eg ending in ~YY.MM | 148 | # eg. ~XX.YY ~XX.YY.1, ~0.XX.YY.1 |
130 | 80 | if devel: | 149 | if devel: |
131 | 81 | new_version = increment_version_security(old_version.split("~")[0], esm=esm, devel=devel) | 150 | new_version = increment_version_security(old_version.split("~")[0], esm=esm, devel=devel) |
132 | 82 | else: | 151 | else: |
136 | 83 | new_version = old_version + ".1" | 152 | split = old_version.split(".") |
137 | 84 | if esm: | 153 | if len(split) == 2: |
138 | 85 | new_version = new_version + "~esm1" | 154 | new_version = old_version + ".1" |
139 | 155 | if esm: | ||
140 | 156 | new_version = new_version + "~esm1" | ||
141 | 157 | else: | ||
142 | 158 | if esm: | ||
143 | 159 | new_version = old_version + "+esm1" | ||
144 | 160 | else: | ||
145 | 161 | new_version = re.sub( | ||
146 | 162 | "\\.[0-9]+$", "." + str(int(split[len(split) - 1]) + 1), old_version | ||
147 | 163 | ) | ||
148 | 86 | else: | 164 | else: |
149 | 87 | raise ValueError("Could not find version for %s" % old_version) | 165 | raise ValueError("Could not find version for %s" % old_version) |
150 | 88 | 166 | ||
151 | diff --git a/package-tools/tests/test_increment_version.py b/package-tools/tests/test_increment_version.py | |||
152 | 89 | old mode 100644 | 167 | old mode 100644 |
153 | 90 | new mode 100755 | 168 | new mode 100755 |
154 | index 5c49aa7..49dfa86 | |||
155 | --- a/package-tools/tests/test_increment_version.py | |||
156 | +++ b/package-tools/tests/test_increment_version.py | |||
157 | @@ -5,11 +5,13 @@ from increment_version import increment_version_security | |||
158 | 5 | class TestIncrementVersion(unittest.TestCase): | 5 | class TestIncrementVersion(unittest.TestCase): |
159 | 6 | def test_increment_version_security(self): | 6 | def test_increment_version_security(self): |
160 | 7 | class TC: | 7 | class TC: |
162 | 8 | def __init__(self, version, expected, esm=False, devel=False): | 8 | def __init__(self, version, expected, esm=False, devel=False, details=None, pkg_list=None): |
163 | 9 | self.version = version | 9 | self.version = version |
164 | 10 | self.expected = expected | 10 | self.expected = expected |
165 | 11 | self.esm = esm | 11 | self.esm = esm |
166 | 12 | self.devel = devel | 12 | self.devel = devel |
167 | 13 | self.details = details | ||
168 | 14 | self.pkg_list = pkg_list | ||
169 | 13 | 15 | ||
170 | 14 | test_cases = [ | 16 | test_cases = [ |
171 | 15 | TC("2.0-2", "2.0-2ubuntu0.1"), | 17 | TC("2.0-2", "2.0-2ubuntu0.1"), |
172 | @@ -38,10 +40,65 @@ class TestIncrementVersion(unittest.TestCase): | |||
173 | 38 | TC("2:2.1-3ubuntu0.7.04.1", "2:2.1-3ubuntu1", devel=True), | 40 | TC("2:2.1-3ubuntu0.7.04.1", "2:2.1-3ubuntu1", devel=True), |
174 | 39 | TC("2.0cvs.20060707-2", "2.0cvs.20060707-2ubuntu1", devel=True), | 41 | TC("2.0cvs.20060707-2", "2.0cvs.20060707-2ubuntu1", devel=True), |
175 | 40 | TC("2.0-2ubuntu0.1~esm9", "2.0-2ubuntu0.1~esm10", esm=True), | 42 | TC("2.0-2ubuntu0.1~esm9", "2.0-2ubuntu0.1~esm10", esm=True), |
176 | 43 | TC("2.1.0-3build2~16.04.1", "2.1.0-3ubuntu0.1~esm1", esm=True), | ||
177 | 44 | # The exact same version is not used in other releases (debian build changes) | ||
178 | 45 | TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'}, | ||
179 | 46 | pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-2', '', '']}), | ||
180 | 47 | # The exact same version is used in a debian release | ||
181 | 48 | TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'}, | ||
182 | 49 | pkg_list={'focal': ['4.3-1', '', ''], 'stretch': ['4.3-1', '', '']}), | ||
183 | 50 | # The exact same version is used in other active release | ||
184 | 51 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
185 | 52 | pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1', '', '']}), | ||
186 | 53 | # The exact same version is used in other active release which was rebuilt | ||
187 | 54 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
188 | 55 | pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1build1', '', '']}), | ||
189 | 56 | # The exact same version is used in other active release which is an interim one | ||
190 | 57 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
191 | 58 | pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}), | ||
192 | 59 | # The exact same version is used in other release which is not active anymore | ||
193 | 60 | TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'}, | ||
194 | 61 | pkg_list={'focal': ['4.3-1', '', ''], 'kinetic': ['4.3-1', '', '']}), | ||
195 | 62 | # The exact same version is used also in the development release | ||
196 | 63 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
197 | 64 | pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}), | ||
198 | 65 | # The exact same version is used in a LTS release which is out of standard support but the package is | ||
199 | 66 | # supported by esm | ||
200 | 67 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'busybox', 'release': 'focal'}, | ||
201 | 68 | pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}), | ||
202 | 69 | # The exact same version is used in a LTS release which is out of standard support, the package is not | ||
203 | 70 | # supported by esm and the package was not updated previously for this release | ||
204 | 71 | TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'}, | ||
205 | 72 | pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}), | ||
206 | 73 | # The exact same version is used in a LTS release which is out of standard support, the package is not | ||
207 | 74 | # supported by esm but an update already exists for this release (may happen if target release | ||
208 | 75 | # is an interim one) | ||
209 | 76 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
210 | 77 | pkg_list={'focal': ['4.3-1', '', ''], 'trusty/esm': ['4.3-1ubuntu0.16.04.1~esm1', '', '']}), | ||
211 | 78 | # The exact same version is used in a LTS release which is out of standard support, the package is not | ||
212 | 79 | # supported by esm but an update already exists for this release (this case should never happen | ||
213 | 80 | # as focal should also be patched already) | ||
214 | 81 | TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
215 | 82 | pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1ubuntu0.14.04.1', '', '']}), | ||
216 | 83 | # The exact same version is used only in other release which is the esm variant of the target one | ||
217 | 84 | TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'}, | ||
218 | 85 | pkg_list={'focal': ['4.3-1', '', ''], 'esm-apps/focal': ['4.3-1ubuntu0.1~esm1', '', '']}), | ||
219 | 86 | # The exact some version is used in other release, both versions were backported | ||
220 | 87 | TC("4.3-1~20.04.1", "4.3-1~20.04.2", details={'package': 'plib', 'release': 'focal'}, | ||
221 | 88 | pkg_list={'focal': ['4.3-1~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}), | ||
222 | 89 | # The exact some version is used in other release, the package was rebuild and then backported | ||
223 | 90 | TC("4.3-1build2~20.04.1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'}, | ||
224 | 91 | pkg_list={'focal': ['4.3-1build2~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}), | ||
225 | 92 | # Target release is an interim one, the exact same version is used in other active release | ||
226 | 93 | TC("4.3-1", "4.3-1ubuntu0.23.04.1", details={'package': 'plib', 'release': 'lunar'}, | ||
227 | 94 | pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}), | ||
228 | 95 | # Target release is the development one, the exact same version is used in other active release | ||
229 | 96 | TC("4.3-1", "4.3-1ubuntu1", devel=True, details={'package': 'plib', 'release': 'mantic'}, | ||
230 | 97 | pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}), | ||
231 | 41 | ] | 98 | ] |
232 | 42 | for tc in test_cases: | 99 | for tc in test_cases: |
234 | 43 | with self.subTest(version=tc.version, esm=tc.esm, devel=tc.devel): | 100 | with self.subTest(version=tc.version, esm=tc.esm, devel=tc.devel, details=tc.details, pkg_list=tc.pkg_list): |
235 | 44 | self.assertEqual( | 101 | self.assertEqual( |
237 | 45 | increment_version_security(tc.version, esm=tc.esm, devel=tc.devel), | 102 | increment_version_security(tc.version, esm=tc.esm, devel=tc.devel, details=tc.details, pkg_list=tc.pkg_list), |
238 | 46 | tc.expected, | 103 | tc.expected, |
239 | 47 | ) | 104 | ) |
Thanks for this @jslarraz - LGTM!