def check_supported_distribution(changes, profile, interface): """ The ``supported-distribution`` checker is a stock dput checker that checks packages intended for upload for a valid upload distribution. Profile key: supported-distribution """ suite = changes['Distribution'] if profile.get('codenames'): if '-' in suite: release, pocket = suite.split('-', 1) else: release, pocket = suite, 'release' codenames = profile['codenames'] if codenames == 'ubuntu': distro_info = UbuntuDistroInfo() pockets = profile['supported-distribution'] logger.critical(pockets) if pocket not in pockets['known']: raise UnknownDistribution("Unkown pocket: %s" % pocket) if pocket not in pockets['allowed']: raise UnknownDistribution( "Uploads aren't permitted to pocket: %s" % pocket) elif codenames == 'debian': distro_info = DebianDistroInfo() else: raise UnknownDistribution("distro-info doesn't know about %s" % codenames) try: codename = distro_info.codename(release, default=release) if codename not in distro_info.all: raise UnsupportedDistribution('Unknown release %s' % release) if codename not in distro_info.supported(): raise UnsupportedDistribution('Unsupported release %s' % release) except DistroDataOutdated: logger.warn('distro-info is outdated, ' 'unable to check supported releases')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os, re from flask import Flask, Response, Markup, request, render_template, make_response from distro_info import DebianDistroInfo, UbuntuDistroInfo debian = DebianDistroInfo() ubuntu = UbuntuDistroInfo() supported = list(reversed(debian.supported())) + list( reversed(ubuntu.supported())) app = Flask(__name__) _pattern = re.compile("^([0-9a-f]{8})$") def get_file_path(remote_addr, file_name, series=None, code=None): if code and code == "default": return os.path.join(app.root_path, file_name) ip_addr = '' if code and _pattern.match(code): for i in (0, 2, 4, 6): ip_addr = ip_addr + str(int("0x" + code[i:i + 2], 16)) + '.' else: ip_addr = ip_addr[:-1] if series and series in supported: if ip_addr:
class UbuntuOS(OperatingSystem): """Ubuntu operating system.""" name = "ubuntu" title = "Ubuntu" def __init__(self): self.ubuntu_distro_info = UbuntuDistroInfo() def get_boot_image_purposes(self, arch, subarch, release, label): """Gets the purpose of each boot image.""" return [ BOOT_IMAGE_PURPOSE.COMMISSIONING, BOOT_IMAGE_PURPOSE.INSTALL, BOOT_IMAGE_PURPOSE.XINSTALL, BOOT_IMAGE_PURPOSE.DISKLESS, ] def is_release_supported(self, release): """Return True when the release is supported, False otherwise.""" row = self.get_distro_series_info_row(release) return row is not None def get_lts_release(self): """Return the latest Ubuntu LTS release.""" return self.ubuntu_distro_info.lts() def get_default_release(self): """Gets the default release to use when a release is not explicit.""" return self.get_lts_release() def get_supported_commissioning_releases(self): """Gets the supported commissioning releases for Ubuntu. This only exists on Ubuntu, because that is the only operating system that supports commissioning. """ unsupported_releases = ['precise'] return [ name for name in self.ubuntu_distro_info.supported() if name not in unsupported_releases if self.ubuntu_distro_info.is_lts(name) ] def get_default_commissioning_release(self): """Gets the default commissioning release for Ubuntu. This only exists on Ubuntu, because that is the only operating system that supports commissioning. """ return self.get_lts_release() def get_distro_series_info_row(self, release): """Returns the distro series row information from python-distro-info. """ info = self.ubuntu_distro_info for row in info._avail(info._date): if row['series'] == release: return row return None def get_release_title(self, release): """Return the title for the given release.""" row = self.get_distro_series_info_row(release) if row is None: return None return self.ubuntu_distro_info._format("fullname", row) def get_xinstall_parameters(self, arch, subarch, release, label): """Return the xinstall image name and type for this operating system. :param arch: Architecture of boot image. :param subarch: Sub-architecture of boot image. :param release: Release of boot image. :param label: Label of boot image. :return: tuple with name of root image and image type """ with ClusterConfiguration.open() as config: squashfs_path = os.path.join(config.tftp_root, 'ubuntu', arch, subarch, release, label, 'squashfs') if os.path.exists(squashfs_path): return ('squashfs', 'squashfs') else: return ('root-tgz', 'tgz')
class UbuntuDistroInfoTestCase(unittest.TestCase): """TestCase object for distro_info.UbuntuDistroInfo""" #pylint: disable=C0103 def setUp(self): self._distro_info = UbuntuDistroInfo() self._date = datetime.date(2011, 1, 10) #pylint: enable=C0103 def test_all(self): """Test: List all known Ubuntu distributions.""" all_distros = set(["warty", "hoary", "breezy", "dapper", "edgy", "feisty", "gutsy", "hardy", "intrepid", "jaunty", "karmic", "lucid", "maverick", "natty"]) self.assertEqual(all_distros - set(self._distro_info.all), set()) def test_devel(self): """Test: Get latest development Ubuntu distribution.""" self.assertEqual(self._distro_info.devel(self._date), "natty") def test_lts(self): """Test: Get latest long term support (LTS) Ubuntu distribution.""" self.assertEqual(self._distro_info.lts(self._date), "lucid") def test_stable(self): """Test: Get latest stable Ubuntu distribution.""" self.assertEqual(self._distro_info.stable(self._date), "maverick") def test_supported(self): """Test: List all supported Ubuntu distribution.""" supported = ["dapper", "hardy", "karmic", "lucid", "maverick", "natty"] self.assertEqual(self._distro_info.supported(self._date), supported) def test_unsupported(self): """Test: List all unsupported Ubuntu distributions.""" unsupported = ["warty", "hoary", "breezy", "edgy", "feisty", "gutsy", "intrepid", "jaunty"] self.assertEqual(self._distro_info.unsupported(self._date), unsupported) def test_current_unsupported(self): """Test: List all unsupported Ubuntu distributions today.""" unsupported = set(["warty", "hoary", "breezy", "edgy", "feisty", "gutsy", "intrepid", "jaunty"]) self.assertEqual(unsupported - set(self._distro_info.unsupported()), set()) def test_valid(self): """Test: Check for valid Ubuntu distribution.""" self.assertTrue(self._distro_info.valid("lucid")) self.assertFalse(self._distro_info.valid("42")) def test_is_lts(self): """Test: Check if Ubuntu distribution is an LTS.""" self.assertTrue(self._distro_info.is_lts("lucid")) self.assertFalse(self._distro_info.is_lts("42")) self.assertFalse(self._distro_info.is_lts("warty")) def test_codename(self): """Test: Check result set to codename.""" self.assertEqual(self._distro_info.lts(self._date, "codename"), "lucid") self.assertEqual(self._distro_info.devel(self._date, result="codename"), "natty") def test_fullname(self): """Test: Check result set to fullname.""" self.assertEqual(self._distro_info.stable(self._date, "fullname"), 'Ubuntu 10.10 "Maverick Meerkat"') self.assertEqual(self._distro_info.lts(self._date, result="fullname"), 'Ubuntu 10.04 LTS "Lucid Lynx"') def test_release(self): """Test: Check result set to release.""" self.assertEqual(self._distro_info.devel(self._date, "release"), "11.04") self.assertEqual(self._distro_info.lts(self._date, result="release"), "10.04 LTS")
class UbuntuOS(OperatingSystem): """Ubuntu operating system.""" name = "ubuntu" title = "Ubuntu" def __init__(self): self.ubuntu_distro_info = UbuntuDistroInfo() def get_boot_image_purposes(self, arch, subarch, release, label): """Gets the purpose of each boot image.""" return [ BOOT_IMAGE_PURPOSE.COMMISSIONING, BOOT_IMAGE_PURPOSE.INSTALL, BOOT_IMAGE_PURPOSE.XINSTALL, BOOT_IMAGE_PURPOSE.DISKLESS, ] def is_release_supported(self, release): """Return True when the release is supported, False otherwise.""" row = self.get_distro_series_info_row(release) return row is not None def get_lts_release(self): """Return the latest Ubuntu LTS release.""" # XXX ltrager 2018-01-08 - Force the default to be bionic before # bionic release for testing with MAAS 2.4.0. return 'bionic' def get_default_release(self): """Gets the default release to use when a release is not explicit.""" return self.get_lts_release() def get_supported_commissioning_releases(self): """Gets the supported commissioning releases for Ubuntu. This only exists on Ubuntu, because that is the only operating system that supports commissioning. """ unsupported_releases = ['precise', 'trusty'] return [ name for name in self.ubuntu_distro_info.supported() if name not in unsupported_releases if self.ubuntu_distro_info.is_lts(name) ] def get_default_commissioning_release(self): """Gets the default commissioning release for Ubuntu. This only exists on Ubuntu, because that is the only operating system that supports commissioning. """ return self.get_lts_release() def get_distro_series_info_row(self, release): """Returns the distro series row information from python-distro-info. """ info = self.ubuntu_distro_info for row in info._avail(info._date): # LP: #1711191 - distro-info 0.16+ no longer returns dictionaries # or lists, and it now returns objects instead. In this case, we # return either the object or the dictionary so get_release_title # handles the formating correctly. row_dict = row if not isinstance(row, dict): row_dict = row.__dict__ if row_dict['series'] == release: return row return None def get_release_title(self, release): """Return the title for the given release.""" row = self.get_distro_series_info_row(release) if row is None: return None return self.ubuntu_distro_info._format("fullname", row) def get_xinstall_parameters(self, arch, subarch, release, label): """Return the xinstall image name and type for this operating system. :param arch: Architecture of boot image. :param subarch: Sub-architecture of boot image. :param release: Release of boot image. :param label: Label of boot image. :return: tuple with name of root image and image type """ return self._find_image(arch, subarch, release, label, tgz=True, squashfs=True)