Skip to content

Another approach to write netboot-lib #639

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

Open
wants to merge 14 commits into
base: ubuntu-automatic-installation
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Library Collections
Library OperatingSystem
Resource pikvm-rest-api/pikvm_comm.robot
Resource lib/secure-boot-lib.robot
Resource lib/netbootxyz-lib.robot
Resource lib/usb-hid-msc-lib.robot
Resource lib/dts-lib.robot
Resource lib/terminal.robot
Expand Down
7 changes: 6 additions & 1 deletion lib/bios/common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Boot System Or From Connected Disk # robocop: disable=too-long-keyword
ELSE
${system_index}= Get Index Of Matching Option In Menu ${menu_construction} ${system_name}
END
Select Boot Menu Option ${system_index} ${ARROW_DOWN}
Select Option ${system_index} ${ARROW_DOWN}

Make Sure That Network Boot Is Enabled
[Documentation] This keywords checks that "Enable network boot" in
Expand Down Expand Up @@ -224,3 +224,8 @@ Press Enter
ELSE
Press Key N Times 1 ${ENTER}
END

Select Option
[Documentation] Select the option by hitting index-times given key.
[Arguments] ${index} ${key}
Press Key N Times ${index} ${key}
5 changes: 0 additions & 5 deletions lib/bios/edk2.robot
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,3 @@ Get Firmware Version From Tianocore Setup Menu
${firmware_line}= Get Lines Containing String ${output} Dasharo (coreboot+UEFI)
${firmware_version}= Get Regexp Matches ${firmware_line} v\\d{1,}\.\\d{1,}\.\\d{1,}
RETURN ${firmware_version}

Select Boot Menu Option
[Documentation] Select the boot menu option using the given index.
[Arguments] ${index} ${key}
Press Key N Times ${index} ${key}
16 changes: 4 additions & 12 deletions lib/bios/seabios.robot
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ Set Option State
[Arguments] ${menu} ${option} ${target_state}
${current_state}= Get Option State ${menu} ${option}
IF '${current_state}' != '${target_state}'
${menu}= Enter Submenu From Snapshot ${menu} ${option}
Enter Submenu From Snapshot ${menu} ${option}
${menu}= Get Menu Construction Save configuration and exit 7 0
${current_state}= Get Option State ${menu} ${option}
Should Match ${current_state} Enabled
RETURN ${TRUE}
ELSE
RETURN ${FALSE}
Expand Down Expand Up @@ -118,14 +121,3 @@ Enter IPXE
${menu}= Get Boot Menu Construction
Enter Submenu From Snapshot ${menu} iPXE

# robocop: disable=unused-argument

Select Boot Menu Option
[Documentation] Select the boot menu option using the given index.
... Accounts for indices counting from zero, and SeaBIOS options counting
... from '1.'. Has to take a dummy parameter for compatibility with the
... EDK2 version of this keyword.
[Arguments] ${index} ${dummy}
${option}= Evaluate ${index} + 1
Write Bare Into Terminal '${option}'
# robocop: disable=unused-argument
183 changes: 180 additions & 3 deletions lib/netbootxyz-lib.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,51 @@ Documentation Collection of keywords related to netboot.xyz
Library Collections
Library String

# Nomenclature:
# - Netboot.Xyz Menu - netboot.xyz main menu
# - Netboot.Xyz Linux Install Menu - submenu of Netboot.Xyz Menu behind Linux
# Network Installs (64-bit) (aka Linux Installers - Current Arch [ x86_64 ])
# - Netboot.Xyz Linux Distro Install Menu - submenu of Netboot.Xyz Linux Install
# Menu of each distribtuion, those may vary depending on distro contain various
# releases and submenus

*** Keywords ***
Boot To Netboot.Xyz
Get Netboot.Xyz Menu Construction
[Documentation] Return only selectable entries of netboot.xyz menu.
... If some menu option is not selectable it will not be in the menu
... construction list.
[Arguments] ${checkpoint}=[ enabled: true ] ${lines_top}=1 ${lines_bot}=0
${out}= Read From Terminal Until ${checkpoint}
# At first, parse the menu as usual
${menu}= Parse Netboot.Xyz Menu Snapshot Into Construction ${out}
# Remove Values From List
# ... ${menu}
# ... To enable Secure Boot, set Secure Boot Mode to
# ... Custom and enroll the keys/PK first.
# ... Enable Secure Boot [ ]
# ... Enable Secure Boot [X]
RETURN ${menu}

Parse Netboot.Xyz Menu Snapshot Into Construction
[Documentation] Breaks grabbed netboot.xyz data into selectable lines.
[Arguments] ${menu}
${menu}= Remove String ${menu} \r
@{menu_lines}= Split To Lines ${menu}
@{construction}= Create List
FOR ${line} IN @{menu_lines}
# It seems that selectable entries start with 6 spaces, followed by
# non-whitespace character
${match}= Run Keyword And Return Status Should Match Regexp ${line} ^ {6}\\S+.*$
IF ${match}
${line}= Strip String ${line}
Append To List ${construction} ${line}
END
END
RETURN ${construction}

Enter Netboot.Xyz Menu
[Documentation] This keyword enters netboot.xyz menu after the platform was
... powered on.
Power On
${boot_menu}= Enter Boot Menu And Return Construction
Enter Submenu From Snapshot ${boot_menu} ${IPXE_BOOT_ENTRY}
${ipxe_menu}= Get IPXE Boot Menu Construction
Expand All @@ -27,4 +66,142 @@ Boot To Netboot.Xyz
ELSE
Enter Submenu From Snapshot ${ipxe_menu} OS installation
END
Read From Terminal Until netboot.xyz [ enabled: true ]

Enter Netboot.Xyz Menu And Return Construction
[Documentation] This keyword enters netboot.xyz menu after the platform
... was powered on. Returns netboot.xyz menu construction.
Enter Netboot.Xyz Menu
${nb_menu}= Get Netboot.Xyz Menu Construction
RETURN ${nb_menu}

Enter Netboot.Xyz Linux Install Menu And Return Construction
[Documentation] Return only selectable entries of netboot.xyz Linux
... Install submenu. If some menu option is not selectable it will not
... be in the menu construction list.
Enter Netboot.Xyz Menu
${nb_menu}= Get Netboot.Xyz Menu Construction
${index}= Get Index Of Matching Option In Menu ${nb_menu} Linux Network Installs (64-bit)
Select Option ${index} ${ARROW_DOWN}
Press Enter
${out}= Read From Terminal
${menu}= Parse Netboot.Xyz Linux Install Menu Snapshot Into Construction ${out}
RETURN ${menu}

Enter Netboot.Xyz Utilities Menu And Return Construction
[Documentation] Return only selectable entries of netboot.xyz Utilities
... submenu. If some menu option is not selectable it will not
... be in the menu construction list.
Enter Netboot.Xyz Menu
${nb_menu}= Get Netboot.Xyz Menu Construction
${index}= Get Index Of Matching Option In Menu ${nb_menu} Utilities (64-bit)
Select Option ${index} ${ARROW_DOWN}
Press Enter
${out}= Read From Terminal
${menu}= Parse Netboot.Xyz Linux Distro Install Menu Snapshot Into Construction ${out}
RETURN ${menu}

Enter Netboot.Xyz Linux Distro Install Menu And Return Construction
[Documentation] Return only selectable entries of netboot.xyz Linux
... Install submenu for provided Linux distribution. If some menu option
... is not selectable it will not be in the menu construction list.
[Arguments] ${distro}
Enter Netboot.Xyz Menu
${nb_menu}= Get Netboot.Xyz Menu Construction
${index}= Get Index Of Matching Option In Menu ${nb_menu} Linux Network Installs (64-bit)
Select Option ${index} ${ARROW_DOWN}
Press Enter
Select Option 1 ${ARROW_DOWN}
${out}= Read From Terminal
${menu}= Parse Netboot.Xyz Linux Install Menu Snapshot Into Construction ${out}

${index}= Get Index Of Matching Option In Menu ${menu} ${distro} ${TRUE}
Should Not Be Equal '${index}' -1 The option was not found in menu
${index}= Evaluate ${index}-1
Press Key N Times And Enter ${index} ${ARROW_DOWN}
${out}= Read From Terminal
${menu}= Parse Netboot.Xyz Linux Distro Install Menu Snapshot Into Construction ${out}
RETURN ${menu}

Parse Netboot.Xyz Linux Distro Install Menu Snapshot Into Construction
[Documentation] Breaks grabbed netboot.xyz Linux distro install menu data
... into selectable lines.
[Arguments] ${menu}
${menu}= Remove String ${menu} \r
@{menu_lines}= Split To Lines ${menu}
@{construction}= Create List
${nextpage}= Set Variable ${FALSE}
FOR ${line} IN @{menu_lines}
${match}= Run Keyword And Return Status Should Match Regexp ${line} ^ {6}\\S+(?: \\S+)*$
IF ${match}
${line}= Strip String ${line}
# If the resulting line is not empty, add it as a menu entry
${length}= Get Length ${line}
IF ${length} > 0 Append To List ${construction} ${line}
END
END
Remove Values From List
... ${construction}
... Latest Release
... Older Releases
... Testing Releases
... .* - amd64
... netboot.xyz tools:
... Utilities:
${nextpage}= Strip String ${menu_lines[-1]}
IF "${nextpage}" == "..."
${keypress}= Get Length ${construction}
Press Key N Times ${keypress} ${ARROW_DOWN}
${out}= Read From Terminal
${out}= Fetch From Right ${out} ...
${menu}= Parse Netboot.Xyz Linux Distro Install Menu Snapshot Into Construction ${out}
${construction}= Combine Lists ${construction} ${menu}
# We have to get back to top of the list to no confuse user
Press Key N Times ${keypress} ${ARROW_UP}
END
RETURN ${construction}

Parse Netboot.Xyz Linux Install Menu Snapshot Into Construction
[Documentation] Breaks grabbed netboot.xyz Linux install menu data into
... selectable lines.
[Arguments] ${menu}
${menu}= Remove String ${menu} \r
@{menu_lines}= Split To Lines ${menu}
@{construction}= Create List
${nextpage}= Set Variable ${FALSE}
FOR ${line} IN @{menu_lines}
${match}= Run Keyword And Return Status Should Match Regexp ${line} \\w+( \\w+)*$
IF ${match}
${line}= Strip String ${line}
# If the resulting line is not empty, add it as a menu entry
${length}= Get Length ${line}
IF ${length} > 0 Append To List ${construction} ${line}
END
END
Remove Values From List
... ${construction}
... Linux Installers - Current Arch [ x86_64 ]
... Linux Distros:
${nextpage}= Strip String ${menu_lines[-1]}
IF "${nextpage}" == "..."
${keypress}= Get Length ${construction}
Press Key N Times ${keypress} ${ARROW_DOWN}
${out}= Read From Terminal
${out}= Fetch From Right ${out} ...
${menu}= Parse Netboot.Xyz Linux Install Menu Snapshot Into Construction ${out}
${construction}= Combine Lists ${construction} ${menu}
# We have to get back to top of the list to no confuse user
Press Key N Times ${keypress} ${ARROW_UP}
END
RETURN ${construction}

Enter Netboot.Xyz And Set Kernel Cmdline Params
[Documentation] Enter Netboot.Xyz Utilities and set kernel cmdline params
[Arguments] ${params}
${menu}= Enter Netboot.Xyz Utilities Menu And Return Construction
${index}= Get Index Of Matching Option In Menu ${menu} Kernel cmdline params: [] ${TRUE}
Should Not Be Equal '${index}' -1 The option was not found in menu
Press Key N Times And Enter ${index} ${ARROW_DOWN}
${out}= Read From Terminal
Write Bare Into Terminal ${params}\n 0.1
${out}= Read From Terminal
Press Key N Times 2 ${ESC}
Loading
Loading