This file is indexed.

/usr/lib/python3/dist-packages/provisioningserver/drivers/osystem/tests/test_ubuntu.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright 2014-2016 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Tests for the UbuntuOS module."""

__all__ = []

from itertools import product
import random

from distro_info import UbuntuDistroInfo
from maastesting.factory import factory
from maastesting.testcase import MAASTestCase
from provisioningserver.drivers.osystem import BOOT_IMAGE_PURPOSE
from provisioningserver.drivers.osystem.ubuntu import UbuntuOS


class TestUbuntuOS(MAASTestCase):

    def get_lts_release(self):
        # XXX ltrager 2016-04-06 - python3-distro-info won't set the latest lts
        # to Xenial until its been released. So we can start testing MAAS 2.0
        # with Xenial by default override it here. Once Xenial is released this
        # can be removed
        # return UbuntuDistroInfo().lts()
        return "xenial"

    def get_release_title(self, release):
        info = UbuntuDistroInfo()
        for row in info._avail(info._date):
            if row['series'] == release:
                return info._format("fullname", row)
        return None

    def test_get_boot_image_purposes(self):
        osystem = UbuntuOS()
        archs = [factory.make_name('arch') for _ in range(2)]
        subarchs = [factory.make_name('subarch') for _ in range(2)]
        releases = [factory.make_name('release') for _ in range(2)]
        labels = [factory.make_name('label') for _ in range(2)]
        for arch, subarch, release, label in product(
                archs, subarchs, releases, labels):
            expected = osystem.get_boot_image_purposes(
                arch, subarchs, release, label)
            self.assertIsInstance(expected, list)
            self.assertEqual(expected, [
                BOOT_IMAGE_PURPOSE.COMMISSIONING,
                BOOT_IMAGE_PURPOSE.INSTALL,
                BOOT_IMAGE_PURPOSE.XINSTALL,
                BOOT_IMAGE_PURPOSE.DISKLESS,
                ])

    def test_get_default_release(self):
        osystem = UbuntuOS()
        expected = osystem.get_default_release()
        self.assertEqual(expected, self.get_lts_release())

    def test_get_supported_commissioning_releases(self):
        self.patch_autospec(UbuntuDistroInfo, "is_lts").return_value = True
        self.patch_autospec(UbuntuDistroInfo, "supported").return_value = [
            'precise', 'trusty', 'vivid', 'wily', 'xenial'
        ]
        osystem = UbuntuOS()
        releases = osystem.get_supported_commissioning_releases()
        self.assertIsInstance(releases, list)
        self.assertSequenceEqual(
            ['trusty', 'vivid', 'wily', 'xenial'], releases)

    def test_get_supported_commissioning_releases_excludes_non_lts(self):
        supported = [
            'precise', 'trusty', 'vivid', 'wily', 'xenial'
        ]
        self.patch_autospec(
            UbuntuDistroInfo, "supported").return_value = supported
        osystem = UbuntuOS()
        releases = osystem.get_supported_commissioning_releases()
        self.assertIsInstance(releases, list)
        udi = UbuntuDistroInfo()
        non_lts_releases = [name for name in supported if not udi.is_lts(name)]
        for release in non_lts_releases:
            self.assertNotIn(release, releases)

    def test_get_supported_commissioning_releases_excludes_precise(self):
        """Make sure we remove 'precise' from the list."""
        self.patch_autospec(UbuntuDistroInfo, "supported").return_value = [
            'precise', 'trusty', 'vivid', 'wily', 'xenial'
        ]
        osystem = UbuntuOS()
        releases = osystem.get_supported_commissioning_releases()
        self.assertIsInstance(releases, list)
        self.assertNotIn('precise', releases)

    def test_get_supported_commissioning_releases_excludes_unsupported_lts(
            self):
        self.patch_autospec(UbuntuDistroInfo, "supported").return_value = [
            'precise', 'trusty', 'vivid', 'wily', 'xenial'
        ]
        unsupported = [
            'warty', 'hoary', 'breezy', 'dapper', 'edgy', 'feisty', 'gutsy',
            'hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', 'maverick',
            'natty', 'oneiric', 'quantal', 'raring', 'saucy', 'utopic'
        ]
        self.patch_autospec(
            UbuntuDistroInfo, "unsupported").return_value = unsupported
        osystem = UbuntuOS()
        releases = osystem.get_supported_commissioning_releases()
        self.assertIsInstance(releases, list)
        for release in unsupported:
            self.assertNotIn(release, releases)

    def test_default_commissioning_release(self):
        osystem = UbuntuOS()
        expected = osystem.get_default_commissioning_release()
        self.assertEqual(expected, self.get_lts_release())

    def test_get_release_title(self):
        osystem = UbuntuOS()
        info = UbuntuDistroInfo()
        release = random.choice(info.all)
        self.assertEqual(
            osystem.get_release_title(release),
            self.get_release_title(release))