Merge ~jslarraz/ubuntu-security-tools:jslarraz/umt_changelog into ubuntu-security-tools:master

Proposed by Jorge Sancho Larraz
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)
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_version.py has been modified to consider that the original version may end in ~0.XX.YY.1 and ~XX.YY.1.
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.

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

Thanks for this @jslarraz - LGTM!

review: Approve
Revision history for this message
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?)

Revision history for this message
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.

Revision history for this message
Eduardo Barretto (ebarretto) wrote :

just some small comments in a specific case

review: Needs Fixing
Revision history for this message
Jorge Sancho Larraz (jslarraz) :
Revision history for this message
Eduardo Barretto (ebarretto) wrote :

lgtm, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/build-tools/umt b/build-tools/umt
2index 2417175..3cdeee4 100755
3--- a/build-tools/umt
4+++ b/build-tools/umt
5@@ -416,7 +416,8 @@ def cmd_changelog():
6 if not note:
7 note = "No-change re-build upload."
8 else:
9- new_ver = increment_version_security(details['version'], opt.esm)
10+ pkg_list = search_packages(details['package'], use_rmadison=True) # Avoid dependencies on local installation
11+ new_ver = increment_version_security(details['version'], opt.esm, details=details, pkg_list=pkg_list)
12
13 if opt.repeat:
14 repeat_release = opt.release
15diff --git a/package-tools/increment_version.py b/package-tools/increment_version.py
16index 6da79f6..7c48ca3 100644
17--- a/package-tools/increment_version.py
18+++ b/package-tools/increment_version.py
19@@ -1,3 +1,11 @@
20+# add location of source_map.py so this can be found since it is in UCT
21+import os
22+import sys
23+uct_path = os.getenv("UCT")
24+if uct_path is not None:
25+ sys.path.append(os.path.join(uct_path, "scripts"))
26+import cve_lib
27+
28 import re
29
30 def _validate_version(old_version):
31@@ -10,6 +18,68 @@ def _validate_version(old_version):
32
33 return old_version
34
35+def get_suffix(devel, details, pkg_list):
36+ if devel:
37+ suffix = "ubuntu1"
38+ else:
39+ suffix = "ubuntu0.1"
40+ if (details is not None) and (pkg_list is not None):
41+ release_id = get_release_id(details, pkg_list)
42+ if release_id is not None:
43+ suffix = "ubuntu0." + release_id + ".1"
44+ return suffix
45+
46+def get_release_id(details, pkg_list):
47+ release_id = None
48+ if (details is None) or (pkg_list is None) or \
49+ (False in [x in details for x in ['package', 'release']]):
50+ return None
51+
52+ target_release = details['release']
53+ old_version = pkg_list[target_release][0]
54+
55+ if (not 'ubuntu' in old_version) and (not 'esm' in old_version):
56+ base_version = get_base_version(old_version)
57+ for release in pkg_list:
58+ # The same package version is used in several releases
59+ if (
60+ (cve_lib.get_orig_rel_name(release) in cve_lib.releases)
61+ and (cve_lib.get_orig_rel_name(release) != target_release)
62+ and (base_version == get_base_version(pkg_list[release][0]))
63+ and (
64+ cve_lib.is_active_release(release)
65+ or (
66+ cve_lib.is_active_esm_release(release)
67+ and (
68+ is_srcpkg_supported(details['package'], cve_lib.get_esm_name(release, pkg_list[release][2]))
69+ or ('ubuntu' in pkg_list[release][0])
70+ )
71+ )
72+ )
73+ ):
74+ release_name = cve_lib.subprojects['ubuntu/' + target_release]['name']
75+ release_id = release_name.split(' ')[1]
76+ return release_id
77+
78+def get_base_version(version):
79+ if 'build' in version:
80+ return version.split('build')[0]
81+ elif 'ubuntu' in version:
82+ return version.split('ubuntu')[0]
83+ elif re.search("~([0-9]+\\.)?([0-9]{2}\\.[0-9]{2})(\\.[0-9]+)$", version):
84+ return '~'.join(version.split('~')[:-1])
85+ else:
86+ return version
87+
88+def is_srcpkg_supported(srcpkg, esm_release):
89+ file = esm_release.replace('/', '-') + '-supported.txt'
90+ f = open(uct_path + '/' + file, 'r')
91+ supported_packages = f.readlines()
92+ f.close()
93+ for supported_package in supported_packages:
94+ if (srcpkg + '\n' == supported_package):
95+ return True
96+ return False
97
98 def increment_version_build(old_version):
99 """Returns an incremented version number per no-change build rules"""
100@@ -31,14 +101,13 @@ def increment_version_build(old_version):
101 new_version = old_version + "build1"
102 return new_version
103
104-
105-def increment_version_security(old_version, esm=False, devel=False):
106+def increment_version_security(old_version, esm=False, devel=False, details=None, pkg_list=None):
107 """Returns an incremented version number per security update rules"""
108 old_version = _validate_version(old_version)
109
110 if "build" in old_version:
111 # eg 2.0-2build1
112- suffix = "ubuntu0.1" if not devel else "ubuntu1"
113+ suffix = get_suffix(devel, details, pkg_list)
114 new_version = re.sub("build.*", "", old_version) + suffix
115 if esm:
116 new_version = new_version + "~esm1"
117@@ -71,18 +140,27 @@ def increment_version_security(old_version, esm=False, devel=False):
118 )
119 elif not "-" in old_version or re.search("-[+a-z.0-9]+$", old_version):
120 # eg 2.0-2 or 2.0cvs.20060707-2 or 1.5.0-3+cvs20071006
121- suffix = "ubuntu0.1" if not devel else "ubuntu1"
122+ suffix = get_suffix(devel, details, pkg_list)
123 new_version = old_version + suffix
124 if esm:
125 new_version = new_version + "~esm1"
126- elif re.search(r"~\d{2}\.\d{2}$", old_version):
127- # eg ending in ~YY.MM
128+ elif re.search("~([0-9]+\\.)?([0-9]{2}\\.[0-9]{2})(\\.[0-9]+)$", old_version):
129+ # eg. ~XX.YY ~XX.YY.1, ~0.XX.YY.1
130 if devel:
131 new_version = increment_version_security(old_version.split("~")[0], esm=esm, devel=devel)
132 else:
133- new_version = old_version + ".1"
134- if esm:
135- new_version = new_version + "~esm1"
136+ split = old_version.split(".")
137+ if len(split) == 2:
138+ new_version = old_version + ".1"
139+ if esm:
140+ new_version = new_version + "~esm1"
141+ else:
142+ if esm:
143+ new_version = old_version + "+esm1"
144+ else:
145+ new_version = re.sub(
146+ "\\.[0-9]+$", "." + str(int(split[len(split) - 1]) + 1), old_version
147+ )
148 else:
149 raise ValueError("Could not find version for %s" % old_version)
150
151diff --git a/package-tools/tests/test_increment_version.py b/package-tools/tests/test_increment_version.py
152old mode 100644
153new mode 100755
154index 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 class TestIncrementVersion(unittest.TestCase):
159 def test_increment_version_security(self):
160 class TC:
161- def __init__(self, version, expected, esm=False, devel=False):
162+ def __init__(self, version, expected, esm=False, devel=False, details=None, pkg_list=None):
163 self.version = version
164 self.expected = expected
165 self.esm = esm
166 self.devel = devel
167+ self.details = details
168+ self.pkg_list = pkg_list
169
170 test_cases = [
171 TC("2.0-2", "2.0-2ubuntu0.1"),
172@@ -38,10 +40,65 @@ class TestIncrementVersion(unittest.TestCase):
173 TC("2:2.1-3ubuntu0.7.04.1", "2:2.1-3ubuntu1", devel=True),
174 TC("2.0cvs.20060707-2", "2.0cvs.20060707-2ubuntu1", devel=True),
175 TC("2.0-2ubuntu0.1~esm9", "2.0-2ubuntu0.1~esm10", esm=True),
176+ TC("2.1.0-3build2~16.04.1", "2.1.0-3ubuntu0.1~esm1", esm=True),
177+ # The exact same version is not used in other releases (debian build changes)
178+ TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
179+ pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-2', '', '']}),
180+ # The exact same version is used in a debian release
181+ TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
182+ pkg_list={'focal': ['4.3-1', '', ''], 'stretch': ['4.3-1', '', '']}),
183+ # The exact same version is used in other active release
184+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
185+ pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1', '', '']}),
186+ # The exact same version is used in other active release which was rebuilt
187+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
188+ pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1build1', '', '']}),
189+ # The exact same version is used in other active release which is an interim one
190+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
191+ pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}),
192+ # The exact same version is used in other release which is not active anymore
193+ TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
194+ pkg_list={'focal': ['4.3-1', '', ''], 'kinetic': ['4.3-1', '', '']}),
195+ # The exact same version is used also in the development release
196+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
197+ pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}),
198+ # The exact same version is used in a LTS release which is out of standard support but the package is
199+ # supported by esm
200+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'busybox', 'release': 'focal'},
201+ pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}),
202+ # The exact same version is used in a LTS release which is out of standard support, the package is not
203+ # supported by esm and the package was not updated previously for this release
204+ TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
205+ pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}),
206+ # The exact same version is used in a LTS release which is out of standard support, the package is not
207+ # supported by esm but an update already exists for this release (may happen if target release
208+ # is an interim one)
209+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
210+ pkg_list={'focal': ['4.3-1', '', ''], 'trusty/esm': ['4.3-1ubuntu0.16.04.1~esm1', '', '']}),
211+ # The exact same version is used in a LTS release which is out of standard support, the package is not
212+ # supported by esm but an update already exists for this release (this case should never happen
213+ # as focal should also be patched already)
214+ TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
215+ pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1ubuntu0.14.04.1', '', '']}),
216+ # The exact same version is used only in other release which is the esm variant of the target one
217+ TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
218+ pkg_list={'focal': ['4.3-1', '', ''], 'esm-apps/focal': ['4.3-1ubuntu0.1~esm1', '', '']}),
219+ # The exact some version is used in other release, both versions were backported
220+ TC("4.3-1~20.04.1", "4.3-1~20.04.2", details={'package': 'plib', 'release': 'focal'},
221+ pkg_list={'focal': ['4.3-1~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}),
222+ # The exact some version is used in other release, the package was rebuild and then backported
223+ TC("4.3-1build2~20.04.1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
224+ pkg_list={'focal': ['4.3-1build2~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}),
225+ # Target release is an interim one, the exact same version is used in other active release
226+ TC("4.3-1", "4.3-1ubuntu0.23.04.1", details={'package': 'plib', 'release': 'lunar'},
227+ pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}),
228+ # Target release is the development one, the exact same version is used in other active release
229+ TC("4.3-1", "4.3-1ubuntu1", devel=True, details={'package': 'plib', 'release': 'mantic'},
230+ pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}),
231 ]
232 for tc in test_cases:
233- with self.subTest(version=tc.version, esm=tc.esm, devel=tc.devel):
234+ with self.subTest(version=tc.version, esm=tc.esm, devel=tc.devel, details=tc.details, pkg_list=tc.pkg_list):
235 self.assertEqual(
236- increment_version_security(tc.version, esm=tc.esm, devel=tc.devel),
237+ increment_version_security(tc.version, esm=tc.esm, devel=tc.devel, details=tc.details, pkg_list=tc.pkg_list),
238 tc.expected,
239 )

Subscribers

People subscribed via source and target branches