[neon/forks/ubuntu-release-upgrader/Neon/unstable_focal] tests: tests/test_sources_list.py: use distro_info to set releases when performing some upgrade tests.

Brian Murray null at kde.org
Wed Jul 28 09:25:04 BST 2021


Git commit 2fbed69cc82d0a83a344f1220a773902d73899de by Brian Murray.
Committed on 01/07/2021 at 00:24.
Pushed by jriddell into branch 'Neon/unstable_focal'.

tests/test_sources_list.py: use distro_info to set releases when performing some upgrade tests.

D  +0    -6    tests/data-sources-list-test/sources.list.EOL2Supported
M  +53   -20   tests/test_sources_list.py

https://invent.kde.org/neon/forks/ubuntu-release-upgrader/commit/2fbed69cc82d0a83a344f1220a773902d73899de

diff --git a/tests/data-sources-list-test/sources.list.EOL2Supported b/tests/data-sources-list-test/sources.list.EOL2Supported
deleted file mode 100644
index 51d30d63..00000000
--- a/tests/data-sources-list-test/sources.list.EOL2Supported
+++ /dev/null
@@ -1,6 +0,0 @@
-
-# main repo
-deb http://old-releases.ubuntu.com/ubuntu oneiric main restricted multiverse universe
-deb-src http://old-releases.ubuntu.com/ubuntu oneiric main restricted multiverse
-
-deb http://old-releases.ubuntu.com/ubuntu oneiric-security main restricted
diff --git a/tests/test_sources_list.py b/tests/test_sources_list.py
index c3866b9b..5a69fae5 100644
--- a/tests/test_sources_list.py
+++ b/tests/test_sources_list.py
@@ -3,11 +3,11 @@
 
 from __future__ import print_function
 
+import apt_pkg
+import distro_info
 import os
-
 import shutil
 import subprocess
-import apt_pkg
 import unittest
 from DistUpgrade.DistUpgradeController import (
     DistUpgradeController,
@@ -28,6 +28,12 @@ import mock
 DistUpgradeConfigParser.CONFIG_OVERRIDE_DIR = None
 
 CURDIR = os.path.dirname(os.path.abspath(__file__))
+dpkg = subprocess.Popen(['dpkg', '--print-architecture'],
+                        stdout=subprocess.PIPE)
+ARCH = dpkg.communicate()[0].decode().strip()
+di = distro_info.UbuntuDistroInfo()
+LTSES = [supported for supported in di.supported()
+         if di.is_lts(supported)]
 
 
 class TestComponentOrdering(unittest.TestCase):
@@ -448,8 +454,10 @@ deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted univers
         from aptsources.sourceslist import SourceEntry
         v = DistUpgradeViewNonInteractive()
         d = DistUpgradeController(v, datadir=self.testdir)
+        to_dist = LTSES[-2]
         for scheme in ["http"]:
-            entry = "deb %s://archive.ubuntu.com/ubuntu/ precise main universe restricted multiverse" % scheme
+            entry = "deb %s://archive.ubuntu.com/ubuntu/ %s main universe restricted multiverse" % \
+                    (scheme, to_dist)
             self.assertTrue(d._sourcesListEntryDownloadable(SourceEntry(entry)),
                             "entry '%s' not downloadable" % entry)
             entry = "deb %s://archive.ubuntu.com/ubuntu/ warty main universe restricted multiverse" % scheme
@@ -488,25 +496,33 @@ deb http://old-releases.ubuntu.com/ubuntu hoary-security main restricted univers
         # Use us.archive.ubuntu.com, because it is available in Canonical's
         # data center, unlike most mirrors.  This lets this test pass when
         # when run in their Jenkins test environment.
+        to_dist = LTSES[-2]
+        from_dist = di.all[di.all.index(to_dist) - 1]
         os.environ["LANG"] = "en_US.UTF-8"
-        shutil.copy(os.path.join(self.testdir, "sources.list.EOL2Supported"),
-                    os.path.join(self.testdir, "sources.list"))
+        with open(os.path.join(self.testdir, "sources.list"), "w") as f:
+            f.write("""
+# main repo
+deb http://old-releases.ubuntu.com/ubuntu %s main restricted multiverse universe
+deb-src http://old-releases.ubuntu.com/ubuntu %s main restricted multiverse
+
+deb http://old-releases.ubuntu.com/ubuntu %s-security main restricted
+""" % (from_dist, from_dist, from_dist))
         apt_pkg.config.set("Dir::Etc::sourceparts",
                            os.path.join(self.testdir, "sources.list.d"))
         v = DistUpgradeViewNonInteractive()
         d = DistUpgradeController(v, datadir=self.testdir)
-        d.fromDist = "oneiric"
-        d.toDist = "precise"
+        d.fromDist = from_dist
+        d.toDist = to_dist
         d.openCache(lock=False)
         res = d.updateSourcesList()
         self.assertTrue(res)
         self._verifySources("""
 # main repo
-deb http://us.archive.ubuntu.com/ubuntu precise main restricted multiverse universe
-deb-src http://us.archive.ubuntu.com/ubuntu precise main restricted multiverse
+deb http://us.archive.ubuntu.com/ubuntu %s main restricted multiverse universe
+deb-src http://us.archive.ubuntu.com/ubuntu %s main restricted multiverse
 
-deb http://us.archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse
-""")
+deb http://us.archive.ubuntu.com/ubuntu %s-security main restricted universe multiverse
+""" % (to_dist, to_dist, to_dist))
 
     @unittest.skipUnless(url_downloadable(
         "https://mirrors.kernel.org/ubuntu", logging.debug),
@@ -537,27 +553,44 @@ deb https://mirrors.kernel.org/ubuntu bionic-security main restricted universe m
 
     def testEOL2SupportedUpgrade(self):
         " test upgrade from a EOL release to a supported release "
+        to_dist = LTSES[-2]
+        from_dist = di.all[di.all.index(to_dist) - 1]
         os.environ["LANG"] = "C"
         v = DistUpgradeViewNonInteractive()
         d = DistUpgradeController(v, datadir=self.testdir)
-        shutil.copy(os.path.join(self.testdir, "sources.list.EOL2Supported"),
-                    os.path.join(self.testdir, "sources.list"))
+        with open(os.path.join(self.testdir, "sources.list"), "w") as f:
+            f.write("""
+# main repo
+deb http://old-releases.ubuntu.com/ubuntu %s main restricted multiverse universe
+deb-src http://old-releases.ubuntu.com/ubuntu %s main restricted multiverse
+
+deb http://old-releases.ubuntu.com/ubuntu %s-security main restricted
+""" % (from_dist, from_dist, from_dist))
         apt_pkg.config.set("Dir::Etc::sourceparts",
                            os.path.join(self.testdir, "sources.list.d"))
         v = DistUpgradeViewNonInteractive()
         d = DistUpgradeController(v, datadir=self.testdir)
-        d.fromDist = "oneiric"
-        d.toDist = "precise"
+        d.fromDist = from_dist
+        d.toDist = to_dist
         d.openCache(lock=False)
         res = d.updateSourcesList()
         self.assertTrue(res)
-        self._verifySources("""
+        if ARCH in ('amd64', 'i386'):
+            self._verifySources("""
 # main repo
-deb http://archive.ubuntu.com/ubuntu precise main restricted multiverse universe
-deb-src http://archive.ubuntu.com/ubuntu precise main restricted multiverse
+deb http://archive.ubuntu.com/ubuntu %s main restricted multiverse universe
+deb-src http://archive.ubuntu.com/ubuntu %s main restricted multiverse
 
-deb http://archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse
-""")
+deb http://archive.ubuntu.com/ubuntu %s-security main restricted universe multiverse
+""" % (to_dist, to_dist, to_dist))
+        else:
+            self._verifySources("""
+# main repo
+deb http://ports.ubuntu.com/ubuntu-ports/ %s main restricted multiverse universe
+deb-src http://archive.ubuntu.com/ubuntu %s main restricted multiverse
+
+deb http://ports.ubuntu.com/ubuntu-ports/ %s-security main restricted universe multiverse
+""" % (to_dist, to_dist, to_dist))
 
     @mock.patch("DistUpgrade.DistUpgradeController.DistUpgradeController._sourcesListEntryDownloadable")
     def test_partner_update(self, mock_sourcesListEntryDownloadable):



More information about the Neon-commits mailing list