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")
Example #2
0
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')