From 6b251e401b7ccc22a53ce14abe7687606ac03c8e Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Wed, 29 Jun 2016 18:12:43 +0200 Subject: [PATCH] Update lsb_release.py to cope with the new Debian Ports' release label Closes: #827137 Changed-by: Didier Raboud to have tests for both the old and the new versions --- lsb_release.py | 6 +++--- test/apt-cache | 7 ++++++- test/test_lsb_release.py | 26 ++++++++++++++------------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lsb_release.py b/lsb_release.py index ce5c93d..0c4b078 100644 --- a/lsb_release.py +++ b/lsb_release.py @@ -184,7 +184,7 @@ def parse_apt_policy(): def guess_release_from_apt(origin='Debian', component='main', ignoresuites=('experimental'), label='Debian', - alternate_olabels={'Debian Ports':'ftp.debian-ports.org'}): + alternate_olabels={'Debian Ports': ('ftp.ports.debian.org', 'ftp.debian-ports.org')}): releases = parse_apt_policy() if not releases: @@ -197,7 +197,7 @@ def guess_release_from_apt(origin='Debian', component='main', x[1].get('component', '') == component and x[1].get('label', '') == label) or ( x[1].get('origin', '') in alternate_olabels and - x[1].get('label', '') == alternate_olabels.get(x[1].get('origin', '')))] + x[1].get('label', '') in alternate_olabels.get(x[1].get('origin', '')))] # Check again to make sure we didn't wipe out all of the releases if not releases: @@ -285,7 +285,7 @@ def guess_debian_release(): release = rinfo.get('version') # Special case Debian-Ports as their Release file has 'version': '1.0' - if release == '1.0' and rinfo.get('origin') == 'Debian Ports' and rinfo.get('label') == 'ftp.debian-ports.org': + if release == '1.0' and rinfo.get('origin') == 'Debian Ports' and rinfo.get('label') in ('ftp.ports.debian.org', 'ftp.debian-ports.org'): release = None rinfo.update({'suite': 'unstable'}) diff --git a/test/apt-cache b/test/apt-cache index 7492dc0..eb503a5 100755 --- a/test/apt-cache +++ b/test/apt-cache @@ -46,9 +46,14 @@ if os.environ.get('TEST_APT_CACHE_UNSTABLE') == '500': print(' release o=Debian,a=unstable,n=sid,l=Debian,c=main') print(' origin MirRor-is-not-read') -if os.environ.get('TEST_APT_CACHE_UNSTABLE_PORTS') == '500': +if os.environ.get('TEST_APT_CACHE_UNSTABLE_PORTS_OLD') == '500': print(' 500 http://MirRor_is_not_read/folder-either-debian-ports/ sid/main arch Packages') print(' release o=Debian Ports,a=unstable,n=sid,l=ftp.debian-ports.org,c=main,v=1.0') print(' origin MirRor-is-not-read') +if os.environ.get('TEST_APT_CACHE_UNSTABLE_PORTS') == '500': + print(' 500 http://MirRor_is_not_read/folder-either-debian-ports/ sid/main arch Packages') + print(' release o=Debian Ports,a=unstable,n=sid,l=ftp.ports.debian.org,c=main,v=1.0') + print(' origin MirRor-is-not-read') + print('Pinned packages:') diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py index 10b969a..936af90 100644 --- a/test/test_lsb_release.py +++ b/test/test_lsb_release.py @@ -163,7 +163,7 @@ class TestLSBRelease(unittest.TestCase): label='l8bel', component='c0mp0nent', ignoresuites=('c0mp0nentIgn'), - alternate_olabels={'P-or1g1n':'P-l8bel'}), + alternate_olabels={'P-or1g1n': ('P-l8bel', 'P-l9bel')}), supposed_output) os.environ.pop('TEST_APT_CACHE1') os.environ.pop('TEST_APT_CACHE2') @@ -255,21 +255,23 @@ class TestLSBRelease(unittest.TestCase): os.remove(fn) os.environ.pop('LSB_ETC_DEBIAN_VERSION') - # Test "unstable releases with Debian Ports" that end in /sid, go read valid apt-cache policy - os.environ['TEST_APT_CACHE_UNSTABLE_PORTS'] = '500' distinfo['CODENAME'] = 'sid' distinfo['RELEASE'] = 'unstable' distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo - for rno in lr.RELEASE_CODENAME_LOOKUP: - fn = 'test/debian_version_' + rnd_string(5,12) - f = open(fn,'w') - f.write(lr.RELEASE_CODENAME_LOOKUP[rno] + '/sid') - f.close() - os.environ['LSB_ETC_DEBIAN_VERSION'] = fn - self.assertEqual(lr.guess_debian_release(),distinfo) - os.remove(fn) + + for CODE in ('PORTS', 'PORTS_OLD'): + # Test "unstable releases with Debian Ports" that end in /sid, go read valid apt-cache policy + os.environ['TEST_APT_CACHE_UNSTABLE_' + CODE] = '500' + for rno in lr.RELEASE_CODENAME_LOOKUP: + fn = 'test/debian_version_' + rnd_string(5,12) + f = open(fn,'w') + f.write(lr.RELEASE_CODENAME_LOOKUP[rno] + '/sid') + f.close() + os.environ['LSB_ETC_DEBIAN_VERSION'] = fn + self.assertEqual(lr.guess_debian_release(),distinfo) + os.remove(fn) + os.environ.pop('TEST_APT_CACHE_UNSTABLE_' + CODE) os.environ.pop('LSB_ETC_DEBIAN_VERSION') - os.environ.pop('TEST_APT_CACHE_UNSTABLE_PORTS') os.environ.pop('TEST_APT_CACHE_UNSTABLE') def test_get_lsb_information(self): -- 2.30.2