Skip to content

Commit

Permalink
device-connectors: oemscripts to wget ISO directly to DUT (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur-at-work authored Aug 26, 2024
1 parent b864fad commit fcadd6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ temp_folder="$(mktemp -d -p "$PWD")"
GIT="git -C $temp_folder"
ubuntu_release=""
enable_sb="no"
dut_iso_url=""
dut_iso=""

enable_secureboot() {
if [ "${ubr}" != "yes" ] && [ "$enable_sb" = "yes" ]; then
Expand All @@ -30,7 +32,7 @@ clear_all() {
}
trap clear_all EXIT
# shellcheck disable=SC2046
eval set -- $(getopt -o "su:c:j:b:t:h" -l "local-iso:,sync,url:,jenkins-credential:,jenkins-job:,jenkins-job-build-no:,oem-share-url:,oem-share-credential:,target-ip:,ubr,enable-secureboot,inject-ssh-key:,help" -- "$@")
eval set -- $(getopt -o "su:c:j:b:t:h" -l "local-iso:,dut-iso-url:,sync,url:,jenkins-credential:,jenkins-job:,jenkins-job-build-no:,oem-share-url:,oem-share-credential:,target-ip:,ubr,enable-secureboot,inject-ssh-key:,help" -- "$@")

usage() {
set +x
Expand Down Expand Up @@ -407,20 +409,46 @@ sync_to_swift() {
download_image "$oem_share_path" "$img_name" "$oem_share_credential"
}

wget_iso_on_dut() {
# Download ISO on DUT
WGET_OPTS="--no-verbose --tries=3 --no-check-certificate"
dut_iso="$(basename "$dut_iso_url")"
echo "Downloading ISO on DUT..."
if ! $SSH "$user_on_target"@"$target_ip" -- sudo wget "$WGET_OPTS" -O /home/"$user_on_target"/"$dut_iso" "$dut_iso_url"; then
echo "Downloading ISO on DUT failed."
exit 4
fi

if ! $SSH "$user_on_target"@"$target_ip" -- sudo test -e /home/"$user_on_target"/"$dut_iso"; then
echo "ISO file doesn't exist after downloading."
exit 4
fi
# successfully downloaded the file
}


download_iso() {
if [ "$enable_sync_to_swift" = true ]; then
sync_to_swift
elif [ -n "$dut_iso_url" ]; then
wget_iso_on_dut
else
download_from_jenkins
fi

}

inject_recovery_iso() {
if [ -z "$local_iso" ]; then
download_iso
fi

img_name="$(basename "$local_iso")"
if [ -n "$dut_iso" ]; then
img_name="$dut_iso"
else
img_name="$(basename "$local_iso")"
fi

if [ -z "${img_name##*stella*}" ] ||
[ -z "${img_name##*sutton*}" ]; then
ubr="yes"
Expand All @@ -431,7 +459,11 @@ inject_recovery_iso() {
ubuntu_release="focal"
fi
rsync_opts="--exclude=efi --delete --temp-dir=/var/tmp/rsync"
$SCP "$local_iso" "$user_on_target"@"$target_ip":~/

if [ -n "$local_iso" ]; then
$SCP "$local_iso" "$user_on_target"@"$target_ip":~/
fi
# by now, $dut_iso already present on the DUT
cat <<EOF > "$temp_folder/$script_on_target_machine"
#!/bin/bash
set -ex
Expand Down Expand Up @@ -500,6 +532,10 @@ main() {
shift
local_iso="$1"
;;
--dut-iso-url)
shift
dut_iso_url="$1"
;;
-s | --sync)
enable_sync_to_swift=true
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import time
import yaml

from testflinger_device_connectors import download
from testflinger_device_connectors.devices import (
ProvisioningError,
RecoveryError,
Expand Down Expand Up @@ -97,18 +96,11 @@ def provision(self):
"Please provide an image 'url' in the provision_data section"
)
raise ProvisioningError("No image url provided")
try:
image_file = download(image_url)

self.run_recovery_script(image_file)

self.check_device_booted()
finally:
# remove the .iso image
if image_file:
os.unlink(image_file)
self.run_recovery_script(image_url)
self.check_device_booted()

def run_recovery_script(self, image_file):
def run_recovery_script(self, image_url):
"""Download and run the OEM recovery script"""
device_ip = self.config["device_ip"]

Expand All @@ -120,8 +112,8 @@ def run_recovery_script(self, image_file):
cmd = [
recovery_script,
*self.extra_script_args,
"--local-iso",
image_file,
"--dut-iso-url",
image_url,
"--inject-ssh-key",
os.path.expanduser("~/.ssh/id_rsa.pub"),
"-t",
Expand Down

0 comments on commit fcadd6d

Please sign in to comment.