Example #1
0
def get_default_usable_osystem(default_osystem):
    """Return the osystem from the clusters that matches the default_osystem."""
    usable_oses = list_all_usable_osystems()
    for usable_os in usable_oses:
        if usable_os["name"] == default_osystem:
            return usable_os
    return None
Example #2
0
    def test_list_all_usable_osystems(self):
        custom_os = factory.make_BootResource(
            rtype=BOOT_RESOURCE_TYPE.UPLOADED,
            extra={'title': factory.make_name('title')})
        factory.make_default_ubuntu_release_bootable()
        # Bootloader to be ignored.
        factory.make_BootResource(
            rtype=BOOT_RESOURCE_TYPE.SYNCED, bootloader_type='uefi')

        self.assertItemsEqual([
            {
                'name': 'custom',
                'title': 'Custom',
                'default_commissioning_release': None,
                'default_release': '',
                'releases': [{
                    'name': custom_os.name,
                    'title': custom_os.extra['title'],
                    'can_commission': False,
                    'requires_license_key': False,
                    }],
            },
            {
                'name': 'ubuntu',
                'title': 'Ubuntu',
                'default_commissioning_release': 'bionic',
                'default_release': 'bionic',
                'releases': [{
                    'name': 'bionic',
                    'title': 'Ubuntu 18.04 LTS "Bionic Beaver"',
                    'can_commission': True,
                    'requires_license_key': False,
                }],
            }], list_all_usable_osystems())
Example #3
0
 def osinfo(self, params):
     """Return all available operating systems and releases information."""
     releases = list_all_usable_releases()
     osystems = list_all_usable_osystems(releases)
     kernels = list_all_usable_hwe_kernels(releases)
     return {
         "osystems": list_osystem_choices(osystems, include_default=False),
         "releases": list_release_choices(releases, include_default=False),
         "kernels": kernels,
         "default_osystem": Config.objects.get_config("default_osystem"),
         "default_release":
         Config.objects.get_config("default_distro_series"),
     }
Example #4
0
def make_default_osystem_field(*args, **kwargs):
    """Build and return the default_osystem field."""
    usable_oses = list_all_usable_osystems()
    os_choices = list_osystem_choices(usable_oses, include_default=False)
    if len(os_choices) == 0:
        os_choices = [("---", "--- No Usable Operating System ---")]
    field = forms.ChoiceField(
        initial=Config.objects.get_config("default_osystem"),
        choices=os_choices,
        validators=[validate_missing_boot_images],
        error_messages={
            "invalid_choice":
            compose_invalid_choice_text("osystem", os_choices)
        },
        **kwargs)
    return field
Example #5
0
def make_commissioning_distro_series_field(*args, **kwargs):
    """Build and return the commissioning_distro_series field."""
    usable_oses = list_all_usable_osystems()
    commissioning_choices = list_commissioning_choices(usable_oses)
    if len(commissioning_choices) == 0:
        commissioning_choices = [('---', '--- No Usable Release ---')]
    field = forms.ChoiceField(
        initial=Config.objects.get_config('commissioning_distro_series'),
        choices=commissioning_choices,
        validators=[validate_missing_boot_images],
        error_messages={
            'invalid_choice': compose_invalid_choice_text(
                'commissioning_distro_series', commissioning_choices)
        },
        **kwargs)
    return field
Example #6
0
    def test_list_all_usable_osystems(self):
        custom_os = factory.make_BootResource(
            rtype=BOOT_RESOURCE_TYPE.UPLOADED,
            extra={"title": factory.make_name("title")},
        )
        factory.make_default_ubuntu_release_bootable()
        # Bootloader to be ignored.
        factory.make_BootResource(rtype=BOOT_RESOURCE_TYPE.SYNCED,
                                  bootloader_type="uefi")

        self.assertItemsEqual(
            [
                {
                    "name":
                    "custom",
                    "title":
                    "Custom",
                    "default_commissioning_release":
                    None,
                    "default_release":
                    "",
                    "releases": [{
                        "name": custom_os.name,
                        "title": custom_os.extra["title"],
                        "can_commission": False,
                        "requires_license_key": False,
                    }],
                },
                {
                    "name":
                    "ubuntu",
                    "title":
                    "Ubuntu",
                    "default_commissioning_release":
                    "bionic",
                    "default_release":
                    "bionic",
                    "releases": [{
                        "name": "bionic",
                        "title": 'Ubuntu 18.04 LTS "Bionic Beaver"',
                        "can_commission": True,
                        "requires_license_key": False,
                    }],
                },
            ],
            list_all_usable_osystems(),
        )
Example #7
0
def show_license_keys():
    """Return True when license keys should be shown."""
    osystems = list_all_usable_osystems()
    return has_osystems_supporting_license_keys(osystems)
Example #8
0
 def test_list_all_usable_osystems_removes_bootloaders(self):
     osystems = [make_rpc_osystem() for _ in range(3)]
     bootloaders = [make_rpc_osystem(name='bootloader') for _ in range(3)]
     self.patch_gen_all_known_operating_systems(osystems + bootloaders)
     self.assertItemsEqual(osystems, list_all_usable_osystems())
Example #9
0
 def test_list_all_usable_osystems_removes_os_without_releases(self):
     osystems = [make_rpc_osystem() for _ in range(3)]
     without_releases = make_rpc_osystem(releases=[])
     self.patch_gen_all_known_operating_systems(osystems +
                                                [without_releases])
     self.assertItemsEqual(osystems, list_all_usable_osystems())
Example #10
0
 def test_list_all_usable_osystems_sorts_title(self):
     osystems = [make_rpc_osystem() for _ in range(3)]
     self.patch_gen_all_known_operating_systems(osystems)
     self.assertEqual(sorted(osystems, key=itemgetter('title')),
                      list_all_usable_osystems())
Example #11
0
 def test_list_all_usable_osystems(self):
     osystems = [make_rpc_osystem() for _ in range(3)]
     self.patch_gen_all_known_operating_systems(osystems)
     self.assertItemsEqual(osystems, list_all_usable_osystems())