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
diff --git a/build-tools/umt b/build-tools/umt
index 2417175..3cdeee4 100755
--- a/build-tools/umt
+++ b/build-tools/umt
@@ -416,7 +416,8 @@ def cmd_changelog():
416 if not note:416 if not note:
417 note = "No-change re-build upload."417 note = "No-change re-build upload."
418 else:418 else:
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
420 new_ver = increment_version_security(details['version'], opt.esm, details=details, pkg_list=pkg_list)
420421
421 if opt.repeat:422 if opt.repeat:
422 repeat_release = opt.release423 repeat_release = opt.release
diff --git a/package-tools/increment_version.py b/package-tools/increment_version.py
index 6da79f6..7c48ca3 100644
--- a/package-tools/increment_version.py
+++ b/package-tools/increment_version.py
@@ -1,3 +1,11 @@
1# add location of source_map.py so this can be found since it is in UCT
2import os
3import sys
4uct_path = os.getenv("UCT")
5if uct_path is not None:
6 sys.path.append(os.path.join(uct_path, "scripts"))
7import cve_lib
8
1import re9import re
210
3def _validate_version(old_version):11def _validate_version(old_version):
@@ -10,6 +18,68 @@ def _validate_version(old_version):
1018
11 return old_version19 return old_version
1220
21def get_suffix(devel, details, pkg_list):
22 if devel:
23 suffix = "ubuntu1"
24 else:
25 suffix = "ubuntu0.1"
26 if (details is not None) and (pkg_list is not None):
27 release_id = get_release_id(details, pkg_list)
28 if release_id is not None:
29 suffix = "ubuntu0." + release_id + ".1"
30 return suffix
31
32def get_release_id(details, pkg_list):
33 release_id = None
34 if (details is None) or (pkg_list is None) or \
35 (False in [x in details for x in ['package', 'release']]):
36 return None
37
38 target_release = details['release']
39 old_version = pkg_list[target_release][0]
40
41 if (not 'ubuntu' in old_version) and (not 'esm' in old_version):
42 base_version = get_base_version(old_version)
43 for release in pkg_list:
44 # The same package version is used in several releases
45 if (
46 (cve_lib.get_orig_rel_name(release) in cve_lib.releases)
47 and (cve_lib.get_orig_rel_name(release) != target_release)
48 and (base_version == get_base_version(pkg_list[release][0]))
49 and (
50 cve_lib.is_active_release(release)
51 or (
52 cve_lib.is_active_esm_release(release)
53 and (
54 is_srcpkg_supported(details['package'], cve_lib.get_esm_name(release, pkg_list[release][2]))
55 or ('ubuntu' in pkg_list[release][0])
56 )
57 )
58 )
59 ):
60 release_name = cve_lib.subprojects['ubuntu/' + target_release]['name']
61 release_id = release_name.split(' ')[1]
62 return release_id
63
64def get_base_version(version):
65 if 'build' in version:
66 return version.split('build')[0]
67 elif 'ubuntu' in version:
68 return version.split('ubuntu')[0]
69 elif re.search("~([0-9]+\\.)?([0-9]{2}\\.[0-9]{2})(\\.[0-9]+)$", version):
70 return '~'.join(version.split('~')[:-1])
71 else:
72 return version
73
74def is_srcpkg_supported(srcpkg, esm_release):
75 file = esm_release.replace('/', '-') + '-supported.txt'
76 f = open(uct_path + '/' + file, 'r')
77 supported_packages = f.readlines()
78 f.close()
79 for supported_package in supported_packages:
80 if (srcpkg + '\n' == supported_package):
81 return True
82 return False
1383
14def increment_version_build(old_version):84def increment_version_build(old_version):
15 """Returns an incremented version number per no-change build rules"""85 """Returns an incremented version number per no-change build rules"""
@@ -31,14 +101,13 @@ def increment_version_build(old_version):
31 new_version = old_version + "build1"101 new_version = old_version + "build1"
32 return new_version102 return new_version
33103
34104def increment_version_security(old_version, esm=False, devel=False, details=None, pkg_list=None):
35def increment_version_security(old_version, esm=False, devel=False):
36 """Returns an incremented version number per security update rules"""105 """Returns an incremented version number per security update rules"""
37 old_version = _validate_version(old_version)106 old_version = _validate_version(old_version)
38107
39 if "build" in old_version:108 if "build" in old_version:
40 # eg 2.0-2build1109 # eg 2.0-2build1
41 suffix = "ubuntu0.1" if not devel else "ubuntu1"110 suffix = get_suffix(devel, details, pkg_list)
42 new_version = re.sub("build.*", "", old_version) + suffix111 new_version = re.sub("build.*", "", old_version) + suffix
43 if esm:112 if esm:
44 new_version = new_version + "~esm1"113 new_version = new_version + "~esm1"
@@ -71,18 +140,27 @@ def increment_version_security(old_version, esm=False, devel=False):
71 )140 )
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):
73 # eg 2.0-2 or 2.0cvs.20060707-2 or 1.5.0-3+cvs20071006142 # eg 2.0-2 or 2.0cvs.20060707-2 or 1.5.0-3+cvs20071006
74 suffix = "ubuntu0.1" if not devel else "ubuntu1"143 suffix = get_suffix(devel, details, pkg_list)
75 new_version = old_version + suffix144 new_version = old_version + suffix
76 if esm:145 if esm:
77 new_version = new_version + "~esm1"146 new_version = new_version + "~esm1"
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):
79 # eg ending in ~YY.MM148 # eg. ~XX.YY ~XX.YY.1, ~0.XX.YY.1
80 if devel:149 if devel:
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)
82 else:151 else:
83 new_version = old_version + ".1"152 split = old_version.split(".")
84 if esm:153 if len(split) == 2:
85 new_version = new_version + "~esm1"154 new_version = old_version + ".1"
155 if esm:
156 new_version = new_version + "~esm1"
157 else:
158 if esm:
159 new_version = old_version + "+esm1"
160 else:
161 new_version = re.sub(
162 "\\.[0-9]+$", "." + str(int(split[len(split) - 1]) + 1), old_version
163 )
86 else:164 else:
87 raise ValueError("Could not find version for %s" % old_version)165 raise ValueError("Could not find version for %s" % old_version)
88166
diff --git a/package-tools/tests/test_increment_version.py b/package-tools/tests/test_increment_version.py
89old mode 100644167old mode 100644
90new mode 100755168new mode 100755
index 5c49aa7..49dfa86
--- a/package-tools/tests/test_increment_version.py
+++ b/package-tools/tests/test_increment_version.py
@@ -5,11 +5,13 @@ from increment_version import increment_version_security
5class TestIncrementVersion(unittest.TestCase):5class TestIncrementVersion(unittest.TestCase):
6 def test_increment_version_security(self):6 def test_increment_version_security(self):
7 class TC:7 class TC:
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):
9 self.version = version9 self.version = version
10 self.expected = expected10 self.expected = expected
11 self.esm = esm11 self.esm = esm
12 self.devel = devel12 self.devel = devel
13 self.details = details
14 self.pkg_list = pkg_list
1315
14 test_cases = [16 test_cases = [
15 TC("2.0-2", "2.0-2ubuntu0.1"),17 TC("2.0-2", "2.0-2ubuntu0.1"),
@@ -38,10 +40,65 @@ class TestIncrementVersion(unittest.TestCase):
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),
39 TC("2.0cvs.20060707-2", "2.0cvs.20060707-2ubuntu1", devel=True),41 TC("2.0cvs.20060707-2", "2.0cvs.20060707-2ubuntu1", devel=True),
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),
43 TC("2.1.0-3build2~16.04.1", "2.1.0-3ubuntu0.1~esm1", esm=True),
44 # The exact same version is not used in other releases (debian build changes)
45 TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
46 pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-2', '', '']}),
47 # The exact same version is used in a debian release
48 TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
49 pkg_list={'focal': ['4.3-1', '', ''], 'stretch': ['4.3-1', '', '']}),
50 # The exact same version is used in other active release
51 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
52 pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1', '', '']}),
53 # The exact same version is used in other active release which was rebuilt
54 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
55 pkg_list={'focal': ['4.3-1', '', ''], 'jammy': ['4.3-1build1', '', '']}),
56 # The exact same version is used in other active release which is an interim one
57 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
58 pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}),
59 # The exact same version is used in other release which is not active anymore
60 TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
61 pkg_list={'focal': ['4.3-1', '', ''], 'kinetic': ['4.3-1', '', '']}),
62 # The exact same version is used also in the development release
63 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
64 pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}),
65 # The exact same version is used in a LTS release which is out of standard support but the package is
66 # supported by esm
67 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'busybox', 'release': 'focal'},
68 pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}),
69 # The exact same version is used in a LTS release which is out of standard support, the package is not
70 # supported by esm and the package was not updated previously for this release
71 TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
72 pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1', '', '']}),
73 # The exact same version is used in a LTS release which is out of standard support, the package is not
74 # supported by esm but an update already exists for this release (may happen if target release
75 # is an interim one)
76 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
77 pkg_list={'focal': ['4.3-1', '', ''], 'trusty/esm': ['4.3-1ubuntu0.16.04.1~esm1', '', '']}),
78 # The exact same version is used in a LTS release which is out of standard support, the package is not
79 # supported by esm but an update already exists for this release (this case should never happen
80 # as focal should also be patched already)
81 TC("4.3-1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
82 pkg_list={'focal': ['4.3-1', '', ''], 'trusty': ['4.3-1ubuntu0.14.04.1', '', '']}),
83 # The exact same version is used only in other release which is the esm variant of the target one
84 TC("4.3-1", "4.3-1ubuntu0.1", details={'package': 'plib', 'release': 'focal'},
85 pkg_list={'focal': ['4.3-1', '', ''], 'esm-apps/focal': ['4.3-1ubuntu0.1~esm1', '', '']}),
86 # The exact some version is used in other release, both versions were backported
87 TC("4.3-1~20.04.1", "4.3-1~20.04.2", details={'package': 'plib', 'release': 'focal'},
88 pkg_list={'focal': ['4.3-1~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}),
89 # The exact some version is used in other release, the package was rebuild and then backported
90 TC("4.3-1build2~20.04.1", "4.3-1ubuntu0.20.04.1", details={'package': 'plib', 'release': 'focal'},
91 pkg_list={'focal': ['4.3-1build2~20.04.1', '', ''], 'jammy': ['4.3-1~22.04.1', '', '']}),
92 # Target release is an interim one, the exact same version is used in other active release
93 TC("4.3-1", "4.3-1ubuntu0.23.04.1", details={'package': 'plib', 'release': 'lunar'},
94 pkg_list={'focal': ['4.3-1', '', ''], 'lunar': ['4.3-1', '', '']}),
95 # Target release is the development one, the exact same version is used in other active release
96 TC("4.3-1", "4.3-1ubuntu1", devel=True, details={'package': 'plib', 'release': 'mantic'},
97 pkg_list={'focal': ['4.3-1', '', ''], 'mantic': ['4.3-1', '', '']}),
41 ]98 ]
42 for tc in test_cases:99 for tc in test_cases:
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):
44 self.assertEqual(101 self.assertEqual(
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),
46 tc.expected,103 tc.expected,
47 )104 )

Subscribers

People subscribed via source and target branches