def test_list_release_choices_includes_requires_key_asterisk(self): factory.make_BootResource(name='windows/win2016') releases = list_all_usable_releases()['windows'] choices = [ self.make_release_choice('windows', release, include_asterisk=True) for release in releases ] self.assertItemsEqual( choices, list_release_choices( list_all_usable_releases(), include_default=False))
def test_list_release_choices(self): for _ in range(3): factory.make_BootResource(name='custom/%s' % factory.make_name()) choices = [ self.make_release_choice('custom', release) for release in list_all_usable_releases()['custom'] ] self.assertItemsEqual( choices, list_release_choices( list_all_usable_releases(), include_default=False))
def test_list_release_choices_sorts(self): for _ in range(3): factory.make_BootResource(name='custom/%s' % factory.make_name()) releases = list_all_usable_releases()['custom'] choices = [ self.make_release_choice('custom', release) for release in sorted(releases, key=itemgetter('title')) ] self.assertEqual( choices, list_release_choices( list_all_usable_releases(), include_default=False))
def test_list_release_choices_fallsback_to_name(self): for _ in range(3): factory.make_BootResource(name="custom/%s" % factory.make_name()) releases = list_all_usable_releases()["custom"] for release in releases: release["title"] = "" choices = [ self.make_release_choice("custom", release) for release in releases ] self.assertItemsEqual( choices, list_release_choices(list_all_usable_releases(), include_default=False), )
def test_list_all_usable_releases(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.assertDictEqual( { "custom": [ { "name": custom_os.name, "title": custom_os.extra["title"], "can_commission": False, "requires_license_key": False, } ], "ubuntu": [ { "name": "bionic", "title": 'Ubuntu 18.04 LTS "Bionic Beaver"', "can_commission": True, "requires_license_key": False, } ], }, dict(list_all_usable_releases()), )
def test_list_release_choices(self): releases = [make_rpc_release() for _ in range(3)] osystem = make_rpc_osystem(releases=releases) choices = [ self.make_release_choice(osystem, release) for release in releases ] self.assertItemsEqual( choices, list_release_choices(list_all_usable_releases([osystem]), include_default=False))
def test_list_release_choices_sorts(self): releases = [make_rpc_release() for _ in range(3)] osystem = make_rpc_osystem(releases=releases) choices = [ self.make_release_choice(osystem, release) for release in sorted(releases, key=itemgetter('title')) ] self.assertEqual( choices, list_release_choices(list_all_usable_releases([osystem]), include_default=False))
def test_list_all_usable_releases_finds_title_for_custom(self): # Regression test for LP:1683440 release = make_rpc_release() osystem = make_rpc_osystem(name='custom', releases=[release]) title = factory.make_name('title') factory.make_BootResource(rtype=BOOT_RESOURCE_TYPE.UPLOADED, name=release['name'], extra={'title': title}) self.assertEquals( title, list_all_usable_releases([osystem])[osystem['name']][0]['title'])
def test_list_all_usable_releases_finds_title_in_boot_resource_table(self): release = make_rpc_release() osystem = make_rpc_osystem(releases=[release]) title = factory.make_name('title') factory.make_BootResource(rtype=BOOT_RESOURCE_TYPE.GENERATED, name='%s/%s' % (osystem['name'], release['name']), extra={'title': title}) self.assertEquals( title, list_all_usable_releases([osystem])[osystem['name']][0]['title'])
def test_list_release_choices_includes_requires_key_asterisk(self): releases = [ make_rpc_release(requires_license_key=True) for _ in range(3) ] osystem = make_rpc_osystem(releases=releases) choices = [ self.make_release_choice(osystem, release, include_asterisk=True) for release in releases ] self.assertItemsEqual( choices, list_release_choices(list_all_usable_releases([osystem]), include_default=False))
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"), }
def test_list_all_usable_releases_finds_uploaded_with_osystem(self): release = make_rpc_release() osystem = make_rpc_osystem(releases=[release]) title = factory.make_name('title') self.patch(osystems, 'gen_all_known_operating_systems').return_value = [{ 'name': osystem['name'] }] factory.make_BootResource(rtype=BOOT_RESOURCE_TYPE.UPLOADED, name='%s/%s' % (osystem['name'], release['name']), extra={'title': title}) self.assertEquals( title, list_all_usable_releases([osystem])[osystem['name']][0]['title'])
def test_list_release_with_missing_title(self): releases = [make_rpc_release(name="xenial"), make_rpc_release()] # Simulate missing title releases[-1]["title"] = None bogus_release_name = releases[-1]["name"] for release in releases: factory.make_BootResource( name="ubuntu/" + release["name"], rtype=BOOT_RESOURCE_TYPE.SYNCED, ) self.assertEqual( [ ("ubuntu/xenial", 'Ubuntu 16.04 LTS "Xenial Xerus"'), ("ubuntu/" + bogus_release_name, bogus_release_name), ], list_release_choices(list_all_usable_releases(), include_default=False), )
def make_default_distro_series_field(*args, **kwargs): """Build and return the default_distro_series field.""" default_osystem = Config.objects.get_config('default_osystem') default_usable_os = get_default_usable_osystem(default_osystem) release_choices = [('---', '--- No Usable Release ---')] if default_usable_os is not None: releases = list_all_usable_releases([default_usable_os ])[default_osystem] valid_release_choices = list_choices_for_releases(releases) if len(valid_release_choices) > 0: release_choices = valid_release_choices field = forms.ChoiceField( initial=Config.objects.get_config('default_distro_series'), choices=release_choices, validators=[validate_missing_boot_images], error_messages={ 'invalid_choice': compose_invalid_choice_text('release', release_choices) }, **kwargs) return field
def test_list_all_usable_releases(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.assertDictEqual({ 'custom': [{ 'name': custom_os.name, 'title': custom_os.extra['title'], 'can_commission': False, 'requires_license_key': False, }], 'ubuntu': [{ 'name': 'bionic', 'title': 'Ubuntu 18.04 LTS "Bionic Beaver"', 'can_commission': True, 'requires_license_key': False, }], }, dict(list_all_usable_releases()))
def test_list_all_usable_releases(self): releases = [make_rpc_release() for _ in range(3)] osystem = make_rpc_osystem(releases=releases) self.assertItemsEqual( releases, list_all_usable_releases([osystem])[osystem['name']])
def test_list_all_usable_releases_sorts(self): releases = [make_rpc_release() for _ in range(3)] osystem = make_rpc_osystem(releases=releases) releases = sorted(releases, key=itemgetter('title')) self.assertEqual(releases, list_all_usable_releases([osystem])[osystem['name']])