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

Add ability to delete all Linux Boot Manager entries #111

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions Jenkinsfiles/hw_test_set
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ zipImagePath = ''
bootSuite = 'boot-test/'
performanceSuite = 'performance-tests/'
batSuite = 'bat-tests/'
efibootSuite = 'efibootmgr/'
deviceName = ''
usbHubSerial = ''
sdMuxUsbPort = ''
Expand All @@ -30,7 +31,9 @@ pipeline {
bootJob = "${splitted[0]}/Testing/boot_test"
batJob = "${splitted[0]}/Testing/smoke_tests"
performanceJob = "${splitted[0]}/Testing/Performance_tests"
removebootmanagerJob = "${splitted[0]}/Testing/remove_efibootentries"
turnoffJob = "${splitted[0]}/Testing/turn_off_device"
turnonJob = "${splitted[0]}/Testing/turn_on_device"
configPath = "/home/${params.label}/Jenkins-agent/workspace/${splitted[0]}/Testing/test_config.json"

// Check for which agent and which target device
Expand Down Expand Up @@ -156,6 +159,25 @@ pipeline {
}
}
}
stage('Installer') {
steps {
script{
if ("${params.job}" == "lenovo-x1-carbon-gen10-debug-installer"){
build = build(
job: "${turnonJob}", propagate: false,
parameters: [
[$class: 'StringParameterValue', name: 'DESCRIPTION', value: "${params.server} buildID: ${params.buildID}"],
[$class: 'StringParameterValue', name: 'DEVICE_NAME', value: "${deviceName}"],
[$class: 'StringParameterValue', name: 'DEVICE_TYPE', value: "${params.device}"]
]
)
sh "python3 installer.py ${deviceName} ghaf"
sh "./BrainStem_dev_kit/bin/AcronameHubCLI -u 0 -s ${usbHubSerial}"
// no need to reboot device (it will be done in boot test)
}
}
}
}
stage('Boot Test') {
steps {
script{
Expand Down Expand Up @@ -258,6 +280,22 @@ pipeline {
}
}
}
stage('Remove Linux Boot Manager') {
steps {
script {
if ("${params.job}" == "lenovo-x1-carbon-gen11-debug-installer"){
build = build(
job: "${batJob}", propagate: false,
parameters: [
[$class: 'StringParameterValue', name: 'RF_SUITE', value: "${efibootSuite}"],
[$class: 'StringParameterValue', name: 'DESCRIPTION', value: "${params.server} buildID: ${params.buildID}"],
[$class: 'StringParameterValue', name: 'DEVICE_NAME', value: "${deviceName}"],
[$class: 'StringParameterValue', name: 'INCLD_TAG', value: "efiboot-modAND${params.device}"]
]
)
}
}
}
stage('Turn off device') {
steps {
script {
Expand Down
18 changes: 18 additions & 0 deletions Robot-Framework/test-suites/efibootmgr/__init__.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
Documentation Modify boot order
Resource ../../resources/ssh_keywords.resource
Resource ../../config/variables.robot
Suite Setup Common Setup
Suite Teardown Common Teardown


*** Keywords ***

Common Setup
Set Variables ${DEVICE}

Common Teardown
Close All Connections
7 changes: 7 additions & 0 deletions Robot-Framework/test-suites/efibootmgr/efiboot_mod_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

for f in $(efibootmgr | grep Linux | awk 'NR > 0 {print $1}' | cut -c 5-8)
do
sudo efibootmgr -q -b ${f} -B
done
91 changes: 91 additions & 0 deletions Robot-Framework/test-suites/efibootmgr/efibootmgr.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
Documentation Removing Linux Boot Manager entries from UEFI boot order.
Force Tags efiboot-mod
Resource ../../resources/serial_keywords.resource
Resource ../../resources/ssh_keywords.resource
Resource ../../resources/device_control.resource
Resource ../../config/variables.robot


*** Variables ***
${CONNECTION_TYPE} ssh
${IS_AVAILABLE} False
${DEVICE_TYPE} ${EMPTY}
${ENTRIES}

*** Test Cases ***

Remove Linux Boot Manager entries
[Documentation] Remove all Linux Boot Manager entries from UEFI boot order list
[Tags] lenovo-x1 efiboot-mod

Check If Device Is Up
IF ${IS_AVAILABLE} == False
FAIL Cannot modify the UEFI boot order
ELSE
Log To Console Connecting to ghaf-host
END

Connect
Put File efibootmgr/efiboot_mod_script /home/ghaf
Execute Command chmod 777 efiboot_mod_script sudo=True sudo_password=${PASSWORD}
Log To Console Deleting all 'Linux' entries from UEFI boot order with efibootmgr
Execute Command ./efiboot_mod_script sudo=True sudo_password=${PASSWORD}
${ENTRIES} Execute Command efibootmgr | grep Linux
Log To Console efibootmgr check after removing Linux Boot Manager entries: \n${ENTRIES}
IF "${ENTRIES}" != ""
FAIL Failed in removing all Linux Boot Manager entries
ELSE
Log To Console All Linux Boot Manager entries cleared
END
[Teardown] Teardown


*** Keywords ***

Teardown
IF "${CONNECTION_TYPE}" == "ssh"
Run Keyword If Test Failed ssh_keywords.Save log
ELSE IF "${CONNECTION_TYPE}" == "serial"
Run Keyword If Test Failed serial_keywords.Save log
END
Close All Connections
Delete All Ports

Check If Device Is Up
[Arguments] ${range}=5
Set Global Variable ${IS_AVAILABLE} False
${start_time}= Get Time epoch
FOR ${i} IN RANGE ${range}
${ping}= Ping Host ${DEVICE_IP_ADDRESS}
IF ${ping}
Log To Console Ping ${DEVICE_IP_ADDRESS} successfull
BREAK
END
Sleep 1
END

IF ${ping}
${port_22_is_available} Check if ssh is ready on device
IF ${port_22_is_available}
Set Global Variable ${IS_AVAILABLE} True
ELSE
Set Global Variable ${IS_AVAILABLE} False
END
END

${diff}= Evaluate int(time.time()) - int(${start_time})

IF ${IS_AVAILABLE} Log To Console Device ssh port available.

IF ${IS_AVAILABLE} == False
Log To Console Device is not available!
IF "${SERIAL_PORT}" == "NONE"
Log To Console There is no address for serial connection
ELSE
Check Serial Connection
END
END
78 changes: 78 additions & 0 deletions installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from paramiko import Ed25519Key
import paramiko
import sys
import json
import os
import time

if len(sys.argv) < 3:
print("Usage: python3 installer.py <device_name> <sudo_password>")
sys.exit(1)

ssh_key_path = '~/.ssh/id_ed25519_autotests'
ssh_key_path = os.path.expanduser(ssh_key_path)
device_name = sys.argv[1]
password = sys.argv[2]


config_file_path = '../test_config.json'
try:
with open(config_file_path, 'r') as file:
data = json.load(file)
ip_address = data["addresses"][device_name]['device_ip_address']
except FileNotFoundError:
print(f"Error: The configuration file '{config_file_path}' was not found.")
sys.exit(1)
except KeyError:
print(f"Error: Device '{device_name}' not found in configuration file.")
sys.exit(1)
except json.JSONDecodeError:
print("Error: JSON file is malformed.")
sys.exit(1)

# SSH Client setup
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
key = Ed25519Key.from_private_key_file(ssh_key_path)
client.connect(hostname=ip_address, username='nixos', pkey=key)
print(f"Successfully connected to {ip_address}")

session = client.get_transport().open_session()
session.get_pty()
session.exec_command('sudo ghaf-installer.sh')

stdin = session.makefile('wb', -1)
stdout = session.makefile('rb', -1)
stderr = session.makefile_stderr('rb', -1)

# Send the sudo password
stdin.write(password + '\n')
stdin.flush()

while True:
if session.recv_ready():
output = stdout.readline() # Reading line by line
if not output:
break
print(output.decode('utf-8'), end='')

if session.recv_stderr_ready():
error_output = stderr.readline()
if not error_output:
break
print(error_output.decode('utf-8'), end='', file=sys.stderr)

# Exit the loop if the command has completed
if session.exit_status_ready():
break

time.sleep(0.1) # Avoid tight loop

except Exception as e:
print(f"An error occurred: {e}")
session = None
finally:
if session:
session.close()
client.close()
Loading