Merge lp:~brian-murray/ubuntu-release-upgrader/better-uri-testing into lp:ubuntu-release-upgrader

Proposed by Brian Murray
Status: Merged
Merged at revision: 3227
Proposed branch: lp:~brian-murray/ubuntu-release-upgrader/better-uri-testing
Merge into: lp:ubuntu-release-upgrader
Diff against target: 144 lines (+62/-10)
3 files modified
DistUpgrade/DistUpgradeController.py (+15/-5)
debian/changelog (+9/-0)
tests/test_sources_list.py (+38/-5)
To merge this branch: bzr merge lp:~brian-murray/ubuntu-release-upgrader/better-uri-testing
Reviewer Review Type Date Requested Status
Steve Langasek Needs Fixing
Review via email: mp+365494@code.launchpad.net

Description of the change

As a part of improving the release upgrade process for people with PPAs enabled a check was added to see if the release to which we are upgrading is provided by the archive (LP: #1807043). However, this check is done for every entry and its uri in a sources.list file which could result in a situation, if a network was flakey, where main was enabled and universe was not (LP: #1822886).

If we instead have a dictionary of the entry.uris and whether or not they were accessible all the sources.list entries with that uri will be disabled. In the case of the Ubuntu archive this will result in 'ubuntu-minimal' not being downloadable and the upgrade process will abort. This is better than the upgrade proceeding and some components for an archive being disabled. Additionally, the multiple calls to _sourcesListEntryDownloadable were unnecessary.

To post a comment you must log in.
3227. By Brian Murray

add in a test where getting the Release file fails, if entry.uri is rewritten add new entry.uri to entry_uri_test_results

Revision history for this message
Steve Langasek (vorlon) :
review: Needs Fixing
3228. By Brian Murray

merge Steve's code refactor to reduce code duplication

3229. By Brian Murray

remove sources.list file on tear down e.g. when a test fails

3230. By Brian Murray

give new test a unique name

3231. By Brian Murray

add in a changelog entry

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'DistUpgrade/DistUpgradeController.py'
2--- DistUpgrade/DistUpgradeController.py 2019-03-08 22:41:57 +0000
3+++ DistUpgrade/DistUpgradeController.py 2019-04-05 00:10:53 +0000
4@@ -590,7 +590,10 @@
5 # collect information on what components (main,universe) are enabled for what distro (sub)version
6 # e.g. found_components = { 'hardy':set("main","restricted"), 'hardy-updates':set("main") }
7 self.found_components = {}
8+ entry_uri_test_results = {}
9 for entry in self.sources.list[:]:
10+ if entry.uri not in entry_uri_test_results:
11+ entry_uri_test_results[entry.uri] = 'unknown'
12
13 # ignore invalid records or disabled ones
14 if entry.invalid or entry.disabled:
15@@ -661,6 +664,8 @@
16 if self._sourcesListEntryDownloadable(test_entry):
17 logging.info("transition from old-release.u.c to %s" % uri)
18 entry.uri = uri
19+ if entry.uri not in entry_uri_test_results:
20+ entry_uri_test_results[entry.uri] = 'unknown'
21 break
22
23 logging.debug("examining: '%s'" % get_string_with_no_auth_from_source_entry(entry))
24@@ -686,11 +691,16 @@
25 logging.debug("entry '%s' is already set to new dist" % get_string_with_no_auth_from_source_entry(entry))
26 foundToDist |= validTo
27 elif entry.dist in fromDists:
28- foundToDist |= validTo
29- # check to see whether the archive provides the new dist
30- test_entry = copy.copy(entry)
31- test_entry.dist = self.toDist
32- if not self._sourcesListEntryDownloadable(test_entry):
33+ if entry_uri_test_results[entry.uri] == 'unknown':
34+ foundToDist |= validTo
35+ # check to see whether the archive provides the new dist
36+ test_entry = copy.copy(entry)
37+ test_entry.dist = self.toDist
38+ if not self._sourcesListEntryDownloadable(test_entry):
39+ entry_uri_test_results[entry.uri] = 'failed'
40+ else:
41+ entry_uri_test_results[entry.uri] = 'passed'
42+ if entry_uri_test_results[entry.uri] == 'failed':
43 entry.disabled = True
44 self.sources_disabled = True
45 logging.debug("entry '%s' was disabled (no Release file)" % get_string_with_no_auth_from_source_entry(entry))
46
47=== modified file 'debian/changelog'
48--- debian/changelog 2019-03-14 18:02:37 +0000
49+++ debian/changelog 2019-04-05 00:10:53 +0000
50@@ -1,3 +1,12 @@
51+ubuntu-release-upgrader (1:19.04.14) UNRELEASED; urgency=medium
52+
53+ * DistUpgradeController.py: Instead of checking every sources.list entry to
54+ see if they are accessible keep track of the uris and only test once per
55+ uri thereby preventing situations where entries for the same server are
56+ enabled and disabled. (LP: #1822886)
57+
58+ -- Brian Murray <brian@ubuntu.com> Thu, 04 Apr 2019 17:06:26 -0700
59+
60 ubuntu-release-upgrader (1:19.04.13) disco; urgency=medium
61
62 [ Brian Murray ]
63
64=== modified file 'tests/test_sources_list.py'
65--- tests/test_sources_list.py 2018-12-11 00:28:15 +0000
66+++ tests/test_sources_list.py 2019-04-05 00:10:53 +0000
67@@ -72,6 +72,10 @@
68 os.unlink(os.path.join(self.testdir, "sources.list"))
69 apt_pkg.config.set("APT::Default-Release", "")
70
71+ def tearDown(self):
72+ if os.path.exists(os.path.join(self.testdir, "sources.list")):
73+ os.unlink(os.path.join(self.testdir, "sources.list"))
74+
75 def test_sources_list_with_nothing(self):
76 """
77 test sources.list rewrite with nothing in it
78@@ -131,6 +135,39 @@
79 apt_pkg.config.find_file("Dir::Etc::sourcelist") + ".distUpgrade"
80 ]))
81
82+ @mock.patch("DistUpgrade.DistUpgradeController.DistUpgradeController._sourcesListEntryDownloadable")
83+ @mock.patch("DistUpgrade.DistUpgradeController.get_distro")
84+ def test_sources_list_rewrite_no_network(self, mock_get_distro, mock_sourcesListEntryDownloadable):
85+ """
86+ test sources.list rewrite no network
87+ """
88+ shutil.copy(os.path.join(self.testdir, "sources.list.in"),
89+ os.path.join(self.testdir, "sources.list"))
90+ apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list")
91+ v = DistUpgradeViewNonInteractive()
92+ d = DistUpgradeController(v, datadir=self.testdir)
93+ d.config.set("Distro", "BaseMetaPkgs", "ubuntu-minimal")
94+ mock_get_distro.return_value = UbuntuDistribution("Ubuntu", "feisty",
95+ "Ubuntu Feisty Fawn",
96+ "7.04")
97+ d.openCache(lock=False)
98+ mock_sourcesListEntryDownloadable.return_value = False
99+ res = d.updateSourcesList()
100+ self.assertTrue(mock_get_distro.called)
101+ self.assertTrue(mock_sourcesListEntryDownloadable.called)
102+ self.assertTrue(res)
103+
104+ # now test the result
105+ #print(open(os.path.join(self.testdir,"sources.list")).read())
106+ self._verifySources("""
107+# main repo
108+# deb http://archive.ubuntu.com/ubuntu/ feisty main restricted multiverse universe
109+# deb http://de.archive.ubuntu.com/ubuntu/ feisty main restricted multiverse
110+# deb-src http://archive.ubuntu.com/ubuntu/ feisty main restricted multiverse
111+# deb http://security.ubuntu.com/ubuntu/ feisty-security main restricted
112+# deb http://security.ubuntu.com/ubuntu/ feisty-security universe
113+""")
114+
115 @mock.patch("DistUpgrade.DistUpgradeController.DistUpgradeController.abort")
116 @mock.patch("DistUpgrade.DistUpgradeController.get_distro")
117 def test_double_check_source_distribution_reject(self, mock_abort, mock_get_distro):
118@@ -424,8 +461,6 @@
119
120 def testEOL2EOLUpgrades(self):
121 " test upgrade from EOL release to EOL release "
122- v = DistUpgradeViewNonInteractive()
123- d = DistUpgradeController(v, datadir=self.testdir)
124 shutil.copy(os.path.join(self.testdir, "sources.list.EOL"),
125 os.path.join(self.testdir, "sources.list"))
126 apt_pkg.config.set("Dir::Etc::sourceparts",
127@@ -454,8 +489,6 @@
128 # data center, unlike most mirrors. This lets this test pass when
129 # when run in their Jenkins test environment.
130 os.environ["LANG"] = "en_US.UTF-8"
131- v = DistUpgradeViewNonInteractive()
132- d = DistUpgradeController(v, datadir=self.testdir)
133 shutil.copy(os.path.join(self.testdir, "sources.list.EOL2Supported"),
134 os.path.join(self.testdir, "sources.list"))
135 apt_pkg.config.set("Dir::Etc::sourceparts",
136@@ -624,7 +657,7 @@
137 @mock.patch("DistUpgrade.DistUpgradeController.DistUpgradeController._sourcesListEntryDownloadable")
138 def test_local_mirror(self, mock_sourcesListEntryDownloadable):
139 """
140- test that a local mirror with official -backports works (LP:# 1067393)
141+ test that a local mirror with official -backports works (LP: #1067393)
142 """
143 shutil.copy(os.path.join(self.testdir, "sources.list.local"),
144 os.path.join(self.testdir, "sources.list"))

Subscribers

People subscribed via source and target branches