Merge lp:~juliank/ubuntu-release-upgrader/double-check-source-release into lp:ubuntu-release-upgrader

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 3109
Proposed branch: lp:~juliank/ubuntu-release-upgrader/double-check-source-release
Merge into: lp:ubuntu-release-upgrader
Diff against target: 122 lines (+93/-0)
3 files modified
DistUpgrade/DistUpgradeController.py (+11/-0)
debian/changelog (+7/-0)
tests/test_sources_list.py (+75/-0)
To merge this branch: bzr merge lp:~juliank/ubuntu-release-upgrader/double-check-source-release
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+337258@code.launchpad.net

Description of the change

Check that a sources.list entry for the "from" distribution exists
before attempting to upgrade (LP: #1725359)

To post a comment you must log in.
3100. By Julian Andres Klode

Also check that e.type == "deb" when validating fromDist

3101. By Julian Andres Klode

Add test cases for double checking source release

3102. By Julian Andres Klode

Fixup test case to correctly mock get_distro

3103. By Julian Andres Klode

Actually fix up docstrings for the new tests

Revision history for this message
Brian Murray (brian-murray) wrote :

I've added a comment to the bug report regarding fixing this a different way.

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 2018-01-29 09:43:48 +0000
3+++ DistUpgrade/DistUpgradeController.py 2018-02-08 09:25:43 +0000
4@@ -771,6 +771,17 @@
5 def updateSourcesList(self):
6 logging.debug("updateSourcesList()")
7 self.sources = SourcesList(matcherPath=self.datadir)
8+
9+ if not any(e.type == "deb" and e.dist == self.fromDist for e in self.sources):
10+ res = self._view.askYesNoQuestion(_("No valid sources.list entry found"),
11+ _("While scanning your repository "
12+ "information no entry about %s could be "
13+ "found.\n\n"
14+ "An upgrade might not succeed.\n\n"
15+ "Do you want to continue anyway?") % self.fromDist)
16+ if not res:
17+ self.abort()
18+
19 # backup first!
20 self.sources.backup(self.sources_backup_ext)
21 if not self.rewriteSourcesList(mirror_check=True):
22
23=== modified file 'debian/changelog'
24--- debian/changelog 2018-02-05 11:26:33 +0000
25+++ debian/changelog 2018-02-08 09:25:43 +0000
26@@ -1,3 +1,10 @@
27+ubuntu-release-upgrader (1:18.04.9) UNRELEASED; urgency=medium
28+
29+ * Check that a sources.list entry for the "from" distribution exists
30+ before attempting to upgrade (LP: #1725359)
31+
32+ -- Julian Andres Klode <juliank@ubuntu.com> Wed, 07 Feb 2018 11:09:03 +0100
33+
34 ubuntu-release-upgrader (1:18.04.8) bionic; urgency=medium
35
36 * data/DistUpgrade.cfg: Add ubuntu-budgie-desktop support.
37
38=== modified file 'tests/test_sources_list.py'
39--- tests/test_sources_list.py 2018-01-29 10:59:52 +0000
40+++ tests/test_sources_list.py 2018-02-08 09:25:43 +0000
41@@ -126,6 +126,81 @@
42 apt_pkg.config.find_file("Dir::Etc::sourcelist") + ".in",
43 apt_pkg.config.find_file("Dir::Etc::sourcelist") + ".distUpgrade"
44 ]))
45+
46+ @mock.patch("DistUpgrade.DistUpgradeController.DistUpgradeController.abort")
47+ @mock.patch("DistUpgrade.DistUpgradeController.get_distro")
48+ def test_double_check_source_distribution_reject(self, mock_abort, mock_get_distro):
49+ """
50+ test that an upgrade from feisty with a sources.list containing
51+ hardy asks a question, and if rejected, aborts the upgrade.
52+ """
53+ shutil.copy(os.path.join(self.testdir, "sources.list.hardy"),
54+ os.path.join(self.testdir, "sources.list"))
55+ apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list")
56+ v = mock.Mock()
57+ v.askYesNoQuestion.return_value=False
58+ d = DistUpgradeController(v, datadir=self.testdir)
59+ d.config.set("Distro", "BaseMetaPkgs", "ubuntu-minimal")
60+ mock_get_distro.return_value = UbuntuDistribution("Ubuntu", "feisty",
61+ "Ubuntu Feisty Fawn",
62+ "7.04")
63+
64+ class AbortException(Exception):
65+ """Exception"""
66+
67+ mock_abort.side_effect = AbortException
68+ d.openCache(lock=False)
69+ with self.assertRaises(AbortException):
70+ d.updateSourcesList()
71+ self.assertTrue(mock_abort.called)
72+ self.assertTrue(mock_get_distro.called)
73+ self.assertTrue(v.askYesNoQuestion.called)
74+
75+ @mock.patch("DistUpgrade.DistUpgradeController.get_distro")
76+ def test_double_check_source_distribution_continue(self, mock_get_distro):
77+ """
78+ test that an upgrade from feisty with a sources.list containing
79+ hardy asks a question, and if continued, does something.
80+ """
81+ shutil.copy(os.path.join(self.testdir, "sources.list.hardy"),
82+ os.path.join(self.testdir, "sources.list"))
83+ apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list")
84+ v = mock.Mock()
85+ v.askYesNoQuestion.return_value=True
86+ d = DistUpgradeController(v, datadir=self.testdir)
87+ d.config.set("Distro", "BaseMetaPkgs", "ubuntu-minimal")
88+ mock_get_distro.return_value = UbuntuDistribution("Ubuntu", "feisty",
89+ "Ubuntu Feisty Fawn",
90+ "7.04")
91+ d.openCache(lock=False)
92+ res = d.updateSourcesList()
93+ self.assertTrue(mock_get_distro.called)
94+ self.assertTrue(res)
95+
96+ # now test the result
97+ #print(open(os.path.join(self.testdir,"sources.list")).read())
98+
99+ # The result here is not really all that helpful, hence we
100+ # added the question in the first place. But still better to
101+ # check what it does than to not check it.
102+ self._verifySources2Way("""
103+# main repo
104+# deb cdrom:[Ubuntu 8.10 _foo]/ hardy main
105+# deb ftp://uk.archive.ubuntu.com/ubuntu/ hardy main restricted multiverse universe
106+# deb http://de.archive.ubuntu.com/ubuntu/ hardy main restricted multiverse
107+deb-src http://uk.archive.ubuntu.com/ubuntu/ hardy main restricted multiverse
108+
109+# deb http://security.ubuntu.com/ubuntu/ hardy-security main restricted
110+# deb http://security.ubuntu.com/ubuntu/ hardy-security universe
111+
112+deb http://archive.ubuntu.com/ubuntu/ gutsy main
113+""")
114+ # check that the backup file was created correctly
115+ self.assertEqual(0, subprocess.call(
116+ ["cmp",
117+ apt_pkg.config.find_file("Dir::Etc::sourcelist") + ".hardy",
118+ apt_pkg.config.find_file("Dir::Etc::sourcelist") + ".distUpgrade"
119+ ]))
120
121 @mock.patch("DistUpgrade.DistUpgradeController.get_distro")
122 def test_sources_list_inactive_mirror(self, mock_get_distro):

Subscribers

People subscribed via source and target branches