예제 #1
0
def inner_start_up(master=False):
    """Startup jobs that must run serialized w.r.t. other starting servers."""
    # Register our MAC data type with psycopg.
    register_mac_type(connection.cursor())

    # All commissioning and testing scripts are stored in the database. For
    # a commissioning ScriptSet to be created Scripts must exist first. Call
    # this early, only on the master process, to ensure they exist and are
    # only created once. If get_or_create_running_controller() is called before
    # this it will fail on first run.
    if master:
        load_builtin_scripts()

    # Ensure the this region is represented in the database. The first regiond
    # to pass through inner_start_up on this host can do this; it should NOT
    # be restricted to masters only. This also ensures that the MAAS ID is set
    # on the filesystem; it will be done in a post-commit hook and will thus
    # happen before `locks.startup` is released.
    region = RegionController.objects.get_or_create_running_controller()
    # Ensure that uuid is created after creating
    RegionController.objects.get_or_create_uuid()

    # Only perform the following if the master process for the
    # region controller.
    if master:
        # Freshen the kms SRV records.
        dns_kms_setting_changed()

        # Make sure the commissioning distro series is still a supported LTS.
        commissioning_distro_series = Config.objects.get_config(
            name="commissioning_distro_series")
        ubuntu = UbuntuOS()
        if commissioning_distro_series not in (
                ubuntu.get_supported_commissioning_releases()):
            Config.objects.set_config(
                "commissioning_distro_series",
                ubuntu.get_default_commissioning_release(),
            )
            Notification.objects.create_info_for_admins(
                "Ubuntu %s is no longer a supported commissioning "
                "series. Ubuntu %s has been automatically selected." % (
                    commissioning_distro_series,
                    ubuntu.get_default_commissioning_release(),
                ),
                ident="commissioning_release_deprecated",
            )

        # Update deprecation notifications if needed
        sync_deprecation_notifications()

        # Refresh soon after this transaction is in.
        post_commit_do(reactor.callLater, 0, refreshRegion, region)

        # Create a certificate for the region.
        post_commit_do(reactor.callLater, 0, generate_certificate_if_needed)
예제 #2
0
 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)
예제 #3
0
 def test__resets_deprecated_commissioning_release_if_master(self):
     Config.objects.set_config('commissioning_distro_series',
                               random.choice(['precise', 'trusty']))
     with post_commit_hooks:
         start_up.inner_start_up(master=True)
     ubuntu = UbuntuOS()
     self.assertEquals(
         Config.objects.get_config('commissioning_distro_series'),
         ubuntu.get_default_commissioning_release())
     self.assertTrue(
         Notification.objects.filter(
             ident="commissioning_release_deprecated").exists())
예제 #4
0
 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(["vivid", "wily", "xenial"], releases)
예제 #5
0
 def test_get_supported_commissioning_releases_excludes_deprecated(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)
     self.assertNotIn("trusty", releases)
예제 #6
0
파일: bootsources.py 프로젝트: uraniid/maas
def ensure_boot_source_definition():
    """Set default boot source if none is currently defined."""
    if not BootSource.objects.exists():
        source = BootSource.objects.create(
            url=DEFAULT_IMAGES_URL, keyring_filename=DEFAULT_KEYRINGS_PATH)
        # Default is to import newest Ubuntu LTS releases, for only amd64
        # release versions only.
        ubuntu = UbuntuOS()
        BootSourceSelection.objects.create(
            boot_source=source, os=ubuntu.name,
            release=ubuntu.get_default_commissioning_release(),
            arches=['amd64'], subarches=['*'], labels=['*'])
        return True
    else:
        return False
예제 #7
0
 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,
         ])
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
def ensure_boot_source_definition():
    """Set default boot source if none is currently defined."""
    if not BootSource.objects.exists():
        source = BootSource.objects.create(
            url=DEFAULT_IMAGES_URL, keyring_filename=DEFAULT_KEYRINGS_PATH
        )
        # Default is to import newest Ubuntu LTS release, for the current
        # architecture.
        arch = get_architecture().split("/")[0]
        # amd64 is the primary architecture for MAAS uses. Make sure its always
        # selected. If MAAS is running on another architecture select that as
        # well.
        if arch in ("", "amd64"):
            arches = ["amd64"]
        else:
            arches = [arch, "amd64"]
        ubuntu = UbuntuOS()
        BootSourceSelection.objects.create(
            boot_source=source,
            os=ubuntu.name,
            release=ubuntu.get_default_commissioning_release(),
            arches=arches,
            subarches=["*"],
            labels=["*"],
        )
        return True
    else:
        # XXX ensure the default keyrings path in the database points to the
        # right file when running in a snap. (see lp:1890468) The
        # DEFAULT_KEYRINGS_PATH points to the right file whether running from
        # deb or snap, but the path stored in the DB might be wrong if a
        # snap-to-deb transition happened with a script without the fix.
        if os.environ.get("SNAP"):
            BootSource.objects.filter(url=DEFAULT_IMAGES_URL).update(
                keyring_filename=DEFAULT_KEYRINGS_PATH
            )
        return False
예제 #11
0
            osystem=config["commissioning_osystem"],
            release=config["commissioning_distro_series"],
        )
    else:
        return render_preseed(
            request,
            node,
            get_preseed_type_for(node),
            osystem=node.get_osystem(config["commissioning_osystem"]),
            release=node.get_distro_series(
                config["commissioning_distro_series"]
            ),
        )


UBUNTU_NAME = UbuntuOS().name


def get_preseed_filenames(
    node, prefix="", osystem="", release="", default=False
):
    """List possible preseed template filenames for the given node.

    :param node: The node to return template preseed filenames for.
    :type node: :class:`maasserver.models.Node`
    :param prefix: At the top level, this is the preseed type (will be used as
        a prefix in the template filenames).  Usually one of {'', 'enlist',
        'commissioning'}.
    :type prefix: unicode
    :param osystem: The operating system to be used.
    :type osystem: unicode
예제 #12
0
 def test_get_default_release(self):
     osystem = UbuntuOS()
     expected = osystem.get_default_release()
     self.assertEqual(expected, self.get_lts_release())
예제 #13
0
 def test_get_lts_release(self):
     # Canary so we know when the lts changes
     osystem = UbuntuOS()
     self.assertEquals('bionic', osystem.get_lts_release())
예제 #14
0
 def test_is_release_supported(self):
     osystem = UbuntuOS()
     info = UbuntuDistroInfo()
     self.assertTrue(osystem.is_release_supported(random.choice(info.all)))
예제 #15
0
from datetime import timedelta
from socket import gethostname

from django.db.models import (
    CharField,
    Manager,
    Model,
)
from django.db.models.signals import post_save
from maasserver import DefaultMeta
from maasserver.fields import JSONObjectField
from provisioningserver.drivers.osystem.ubuntu import UbuntuOS
from provisioningserver.events import EVENT_TYPES


DEFAULT_OS = UbuntuOS()

DNSSEC_VALIDATION_CHOICES = [
    ("auto", "Automatic (use default root key)"),
    ("yes", "Yes (manually configured root key)"),
    ("no", "No (Disable DNSSEC; useful when upstream DNS is misconfigured)")
]

NETWORK_DISCOVERY_CHOICES = [
    ("enabled", "Enabled"),
    ("disabled", "Disabled")
]

ACTIVE_DISCOVERY_INTERVAL_CHOICES = [
    (0, "Never (disabled)"),
    (int(timedelta(days=7).total_seconds()), "Every week"),
예제 #16
0
        return "root-tgz", "tgz"


class OperatingSystemRegistry(Registry):
    """Registry for operating system classes."""


from provisioningserver.drivers.osystem.ubuntu import UbuntuOS
from provisioningserver.drivers.osystem.ubuntucore import UbuntuCoreOS
from provisioningserver.drivers.osystem.bootloader import BootLoaderOS
from provisioningserver.drivers.osystem.centos import CentOS
from provisioningserver.drivers.osystem.rhel import RHELOS
from provisioningserver.drivers.osystem.custom import CustomOS
from provisioningserver.drivers.osystem.windows import WindowsOS
from provisioningserver.drivers.osystem.suse import SUSEOS
from provisioningserver.drivers.osystem.caringo import CaringoOS

builtin_osystems = [
    UbuntuOS(),
    UbuntuCoreOS(),
    BootLoaderOS(),
    CentOS(),
    RHELOS(),
    CustomOS(),
    WindowsOS(),
    SUSEOS(),
    CaringoOS(),
]
for osystem in builtin_osystems:
    OperatingSystemRegistry.register_item(osystem.name, osystem)
예제 #17
0
 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))