Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support latest distro args in pxemenu #241

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions IntegrationTests/src/bkr/inttest/labcontroller/test_pxemenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,211 @@ def test_grub2_menu_for_efi(self):

}
''' % (distro_tree.id, distro_tree.id))

# Below test changes for latest distros

def test_x86_menus_for_latest_distros(self):
with session.begin():
lc = self.get_lc()
tag = u'test_grub2_menu_for_efi_and_latest_distros'
distro_tree = data_setup.create_distro_tree(
osmajor=u'RedHatEnterpriseLinux9', osminor=u'0',
distro_name=u'RHEL-9.0.0-20211201.1', distro_tags=[tag],
arch=u'x86_64', lab_controllers=[lc],
urls=[u'http://localhost:19998/'])
write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
# Menu 1 of 3
menu = open(os.path.join(self.tftp_dir, 'boot', 'grub2',
'beaker_menu_x86.cfg')).read()
self.assertEquals(menu, '''\
set default="Exit PXE"
set timeout=60
menuentry "Exit PXE" {
exit
}

submenu "RedHatEnterpriseLinux9" {

submenu "RedHatEnterpriseLinux9.0" {

menuentry "RHEL-9.0.0-20211201.1 Server x86_64" {
linux /distrotrees/%s/kernel inst.repo=http://localhost:19998/
initrd /distrotrees/%s/initrd
}

}

}
''' % (distro_tree.id, distro_tree.id))

# Menu 2 of 3
menu = open(os.path.join(self.tftp_dir, 'ipxe',
'beaker_menu')).read()
self.assertEquals(menu, '''\
#!ipxe

chain /ipxe/${ip:hexraw} ||

:main_menu
menu Beaker
item local (local)
item RedHatEnterpriseLinux9 RedHatEnterpriseLinux9 ->
choose --default local --timeout 600000 target && goto ${target} || goto local

:local
echo Booting local disk...
iseq ${builtin/platform} pcbios && sanboot --no-describe --drive 0x80 ||
# exit 1 generates an error message but req'd for some systems to fall through
exit 1 || goto main_menu

:RedHatEnterpriseLinux9
menu RedHatEnterpriseLinux9
item RedHatEnterpriseLinux9.0 RedHatEnterpriseLinux9.0 ->
item main_menu back <-
choose target && goto ${target} || goto main_menu

:RedHatEnterpriseLinux9.0
menu RedHatEnterpriseLinux9.0
item RHEL-9.0.0-20211201.1-Server-x86_64 RHEL-9.0.0-20211201.1 Server x86_64
item RedHatEnterpriseLinux9 back <-
choose target && goto ${target} || goto RedHatEnterpriseLinux9

:RHEL-9.0.0-20211201.1-Server-x86_64
set options kernel initrd=initrd inst.repo=http://localhost:19998/
echo Kernel command line: ${options}
prompt --timeout 5000 Press any key for additional options... && set opts 1 || clear opts
isset ${opts} && echo -n Additional options: ${} ||
isset ${opts} && read useropts ||
kernel /distrotrees/%s/kernel || goto RedHatEnterpriseLinux9.0
initrd /distrotrees/%s/initrd || goto RedHatEnterpriseLinux9.0
imgargs ${options} ${useropts}
boot || goto RedHatEnterpriseLinux9.0

''' % (distro_tree.id, distro_tree.id)) # noqa: W291

# Menu 3 of 3
menu = open(os.path.join(self.tftp_dir, 'pxelinux.cfg', 'beaker_menu')).read()
self.assertEquals(menu, '''\
default menu
prompt 0
timeout 6000
ontimeout local
menu title Beaker
label local
menu label (local)
menu default
localboot 0

menu begin
menu title RedHatEnterpriseLinux9

menu begin
menu title RedHatEnterpriseLinux9.0

label RHEL-9.0.0-20211201.1-Server-x86_64
menu title RHEL-9.0.0-20211201.1 Server x86_64
kernel /distrotrees/{0}/kernel
append initrd=/distrotrees/{0}/initrd inst.repo=http://localhost:19998/

menu end

menu end
'''.format(distro_tree.id)) # noqa: W291

def test_aarch64_menu_and_latest_distros(self):
with session.begin():
lc = self.get_lc()
tag = u'test_aarch64_menu_and_latest_distros'
distro_tree = data_setup.create_distro_tree(
osmajor=u'RedHatEnterpriseLinux9', osminor=u'0',
distro_name=u'RHEL-9.0.0-20211201.1-Server-aarch64', distro_tags=[tag],
arch=u'aarch64', lab_controllers=[lc],
urls=[u'http://localhost:19998/'])
write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
menu = open(os.path.join(self.tftp_dir, 'aarch64', 'beaker_menu.cfg')).read()
self.assertEquals(menu, '''\
set default="Exit PXE"
set timeout=60
menuentry "Exit PXE" {
exit
}

submenu "RedHatEnterpriseLinux9" {

submenu "RedHatEnterpriseLinux9.0" {

menuentry "RHEL-9.0.0-20211201.1-Server-aarch64 Server aarch64" {
linux /distrotrees/%s/kernel inst.repo=http://localhost:19998/
initrd /distrotrees/%s/initrd
}

}

}
''' % (distro_tree.id, distro_tree.id))

def test_ppc64le_menu_and_latest_distros(self):
with session.begin():
lc = self.get_lc()
tag = u'test_ppc64le_menu_and_latest_distros'
distro_tree = data_setup.create_distro_tree(
osmajor=u'RedHatEnterpriseLinux9', osminor=u'0',
distro_name=u'RHEL-9.0.0-20211201.1-Server-ppc64le', distro_tags=[tag],
arch=u'ppc64le', lab_controllers=[lc],
urls=[u'http://localhost:19998/'])
write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
menu = open(os.path.join(self.tftp_dir, 'boot', 'grub2',
'beaker_menu_ppc64le.cfg')).read()
self.assertEquals(menu, '''\
set default="Exit PXE"
set timeout=60
menuentry "Exit PXE" {
exit
}

submenu "RedHatEnterpriseLinux9" {

submenu "RedHatEnterpriseLinux9.0" {

menuentry "RHEL-9.0.0-20211201.1-Server-ppc64le Server ppc64le" {
linux /distrotrees/%s/kernel inst.repo=http://localhost:19998/
initrd /distrotrees/%s/initrd
}

}

}
''' % (distro_tree.id, distro_tree.id))

def test_ppc64_menu_and_latest_distros(self):
with session.begin():
lc = self.get_lc()
tag = u'test_ppc64_menu_and_latest_distros'
distro_tree = data_setup.create_distro_tree(
osmajor=u'RedHatEnterpriseLinux9', osminor=u'0',
distro_name=u'RHEL-9.0.0-20211201.1-Server-ppc64', distro_tags=[tag],
arch=u'ppc64', lab_controllers=[lc],
urls=[u'http://localhost:19998/'])
write_menus(self.tftp_dir, tags=[tag], xml_filter=None)
menu = open(os.path.join(self.tftp_dir, 'boot', 'grub2',
'beaker_menu_ppc64.cfg')).read()
self.assertEquals(menu, '''\
set default="Exit PXE"
set timeout=60
menuentry "Exit PXE" {
exit
}

submenu "RedHatEnterpriseLinux9" {

submenu "RedHatEnterpriseLinux9.0" {

menuentry "RHEL-9.0.0-20211201.1-Server-ppc64 Server ppc64" {
linux /distrotrees/%s/kernel inst.repo=http://localhost:19998/
initrd /distrotrees/%s/initrd
}

}

}
''' % (distro_tree.id, distro_tree.id))
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

title {{ distro_tree.distro_name }} {{ distro_tree.variant }} {{ distro_tree.arch }}
root (nd)
kernel /distrotrees/{{ distro_tree.distro_tree_id }}/kernel method={{ distro_tree.available|get_url }} repo={{ distro_tree.available|get_url }}
kernel /distrotrees/{{ distro_tree.distro_tree_id }}/kernel {{ osmajor|get_method(distro_tree.available) }} {{ osmajor|get_repo_prefix }}repo={{ distro_tree.available|get_url }}
initrd /distrotrees/{{ distro_tree.distro_tree_id }}/initrd
{% endfor %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ submenu "{{ osversion }}" {

{% for distro_tree in distro_trees %}
menuentry "{{ distro_tree.distro_name }} {{ distro_tree.variant }} {{ distro_tree.arch }}" {
linux /distrotrees/{{ distro_tree.distro_tree_id }}/kernel method={{ distro_tree.available|get_url }} repo={{
linux /distrotrees/{{ distro_tree.distro_tree_id }}/kernel {{ osmajor|get_method(distro_tree.available) }} {{ osmajor|get_repo_prefix }}repo={{
distro_tree.available| get_url }}
initrd /distrotrees/{{ distro_tree.distro_tree_id }}/initrd
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ choose target && goto ${target} || goto {{ osmajor }}

{% for distro_tree in distro_trees %}
:{{ distro_tree.distro_name.replace(" ", "") }}-{{ distro_tree.variant.replace(" ", "") }}-{{ distro_tree.arch.replace(" ", "") }}
set options kernel initrd=initrd method={{ distro_tree.available|get_url }} repo={{ distro_tree.available|get_url }} {{ distro_tree.kernel_options }}
set options kernel initrd=initrd {{ osmajor|get_method(distro_tree.available) }} {{ osmajor|get_repo_prefix }}repo={{ distro_tree.available|get_url }} {{ distro_tree.kernel_options }}
echo Kernel command line: ${options}
prompt --timeout 5000 Press any key for additional options... && set opts 1 || clear opts
isset ${opts} && echo -n Additional options: ${} ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ menu title {{ osversion }}
label {{ distro_tree.distro_name }}-{{ distro_tree.variant }}-{{ distro_tree.arch }}
menu title {{ distro_tree.distro_name }} {{ distro_tree.variant }} {{ distro_tree.arch }}
kernel /distrotrees/{{ distro_tree.distro_tree_id }}/kernel
append initrd=/distrotrees/{{ distro_tree.distro_tree_id }}/initrd method={{ distro_tree.available|get_url }} repo={{ distro_tree.available|get_url }} {{ distro_tree.kernel_options }}

append initrd=/distrotrees/{{ distro_tree.distro_tree_id }}/initrd {{ osmajor|get_method(distro_tree.available) }} {{ osmajor|get_repo_prefix }}repo={{ distro_tree.available|get_url }} {{ distro_tree.kernel_options }}
{% endfor %}

menu end

{% endfor %}
Expand Down
39 changes: 39 additions & 0 deletions LabController/src/bkr/labcontroller/pxemenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@ def _get_url(available):
[url for lc, url in available])


def _is_newer_distro(osmajor):
if (osmajor.lower() in ('fedoraeln', 'fedorarawhide')):
return True

result = re.search(r"([a-zA-Z]+)(\d+)", osmajor)
if result is None:
return False
distro = result.groups()[0]
version = int(result.groups()[1])
if distro in ('RedHatEnterpriseLinux', 'CentOSStream') and version > 8:
return True
if distro == 'Fedora' and version > 33:
return True
return False


def _get_repo_prefix(osmajor):
"""
Newer distros require prefix of 'inst.' to repo kernel variable
which ultimately results in inst.repo.
"""
if (_is_newer_distro(osmajor)):
return 'inst.'
return ''


def _get_method(osmajor, available):
"""
Older distros use 'method' kernel variable which has been deprecated by
inst.repo in newer distros.
"""
if (_is_newer_distro(osmajor)):
return ''
url = _get_url(available)
return 'method='+url


def _group_distro_trees(distro_trees):
grouped = {}
for dt in distro_trees:
Expand Down Expand Up @@ -77,6 +114,8 @@ def _get_all_images(tftp_root, distro_trees):
template_env = Environment(loader=PackageLoader('bkr.labcontroller', 'pxemenu-templates'),
trim_blocks=True)
template_env.filters['get_url'] = _get_url
template_env.filters['get_repo_prefix'] = _get_repo_prefix
template_env.filters['get_method'] = _get_method


def write_menu(menu, template_name, distro_trees):
Expand Down
Loading