Skip to content

Commit

Permalink
Support latest distro args in pxemenu
Browse files Browse the repository at this point in the history
For latest distros, the variables 'method' and 'repos'
are not supported in beaker pxemenu.  Replace with
'inst.repos' instead.  The latest distros are
RHEL9, CentOSStream9, FedoraRawhide, FedoraELN, and
Fedora34 and up.
  • Loading branch information
cbouchar committed Aug 23, 2022
1 parent 3c4a768 commit 99f8415
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 5 deletions.
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 tests 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 @@ -32,6 +32,43 @@ def _get_url(available):
[url for lc, url in available])


def _is_newer_distro(osmajor):
if ((osmajor == 'FedoraELN') or (osmajor == 'Fedorarawhide') or
(osmajor == 'FedoraRawhide')):
return True
split_str = re.split("(RedHatEnterpriseLinux|Fedora|CentOSStream)(\d+)", osmajor) # noqa: W605
if (len(split_str) == 4):
if (((split_str[1] == 'RedHatEnterpriseLinux') and
(int(split_str[2]) > 8)) or
((split_str[1] == 'Fedora') and
(int(split_str[2]) > 33)) or
((split_str[1] == 'CentOSStream') and
(int(split_str[2]) > 8))):
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 @@ -78,6 +115,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

0 comments on commit 99f8415

Please sign in to comment.