-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add noble_oemscript device-connector and updated docs. Updated image-…
…deploy.sh script
- Loading branch information
1 parent
dd03ec1
commit e44a1ba
Showing
6 changed files
with
301 additions
and
15 deletions.
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
device-connectors/src/testflinger_device_connectors/data/muxpi/oemscript/image-deploy.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#!/bin/bash | ||
|
||
exec 2>&1 | ||
set -euox pipefail | ||
# This script was adapted to testflinger agent environment and used | ||
# to provision OEM devices with Ubuntu Noble images | ||
# Downloading ISO is not supported, because agent is in charge of ISO download | ||
|
||
usage() | ||
{ | ||
cat <<EOF | ||
Usage: | ||
$0 [OPTIONS] <TARGET_IP 1> <TARGET_IP 2> ... | ||
Options: | ||
-h|--help The manual of the script | ||
--iso ISO file path to be deployed on the target | ||
-u|--user The user of the target, default ubuntu | ||
-o|--timeout The timeout for doing the deployment, default 3600 seconds | ||
EOF | ||
} | ||
|
||
if [ $# -lt 3 ]; then | ||
usage | ||
exit | ||
fi | ||
|
||
TARGET_USER="ubuntu" | ||
TARGET_IPS=() | ||
ISO_PATH= | ||
ISO= | ||
STORE_PART="" | ||
TIMEOUT=3600 | ||
SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" | ||
SSH="ssh $SSH_OPTS" | ||
SCP="scp $SSH_OPTS" | ||
|
||
if [ ! -d "$HOME/.cache/oem-scripts" ]; then | ||
mkdir -p "$HOME/.cache/oem-scripts" | ||
fi | ||
|
||
OPTS="$(getopt -o u:o:l: --long iso:,user:,timeout:,local-config: -n 'image-deploy.sh' -- "$@")" | ||
eval set -- "${OPTS}" | ||
while :; do | ||
case "$1" in | ||
('-h'|'--help') | ||
usage | ||
exit;; | ||
('--iso') | ||
ISO_PATH="$2" | ||
ISO=$(basename "$ISO_PATH") | ||
shift 2;; | ||
('-u'|'--user') | ||
TARGET_USER="$2" | ||
shift 2;; | ||
('-o'|'--timeout') | ||
TIMEOUT="$2" | ||
shift 2;; | ||
('-l'|'--local-config') | ||
CONFIG_REPO_PATH="$2" | ||
SKIP_GIT="TRUE" | ||
shift 2;; | ||
('--') shift; break ;; | ||
(*) break ;; | ||
esac | ||
done | ||
|
||
if [ ! -f "$ISO_PATH" ]; then | ||
echo "No designated ISO file" | ||
exit | ||
fi | ||
|
||
read -ra TARGET_IPS <<< "$@" | ||
|
||
for addr in "${TARGET_IPS[@]}"; | ||
do | ||
# Clear the knonw host | ||
if [ -f "$HOME/.ssh/known_hosts" ]; then | ||
ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$addr" | ||
fi | ||
|
||
# Find the partitions | ||
while read -r name fstype mountpoint; | ||
do | ||
echo "$name,$fstype,$mountpoint" | ||
if [ "$fstype" = "ext4" ]; then | ||
if [ "$mountpoint" = "/home/$TARGET_USER" ] || [ "$mountpoint" = "/" ]; then | ||
STORE_PART="/dev/$name" | ||
break | ||
fi | ||
fi | ||
done < <($SSH "$TARGET_USER"@"$addr" -- lsblk -n -l -o NAME,FSTYPE,MOUNTPOINT) | ||
|
||
if [ -z "$STORE_PART" ]; then | ||
echo "Can't find partition to store ISO on target $addr" | ||
exit | ||
fi | ||
RESET_PART="${STORE_PART:0:-1}2" | ||
RESET_PARTUUID=$($SSH "$TARGET_USER"@"$addr" -- lsblk -n -o PARTUUID "$RESET_PART") | ||
EFI_PART="${STORE_PART:0:-1}1" | ||
|
||
# Copy ISO to the target | ||
$SCP "$ISO_PATH" "$TARGET_USER"@"$addr":/home/"$TARGET_USER" | ||
|
||
# Copy cloud-config redeploy to the target | ||
$SSH "$TARGET_USER"@"$addr" -- mkdir -p /home/"$TARGET_USER"/redeploy/cloud-configs/redeploy | ||
$SSH "$TARGET_USER"@"$addr" -- mkdir -p /home/"$TARGET_USER"/redeploy/cloud-configs/grub | ||
$SCP "$CONFIG_REPO_PATH"/alloem-init/cloud-configs/redeploy/meta-data "$TARGET_USER"@"$addr":/home/"$TARGET_USER"/redeploy/cloud-configs/redeploy/ | ||
$SCP "$CONFIG_REPO_PATH"/alloem-init/cloud-configs/redeploy/user-data "$TARGET_USER"@"$addr":/home/"$TARGET_USER"/redeploy/cloud-configs/redeploy/ | ||
$SCP "$CONFIG_REPO_PATH"/alloem-init/cloud-configs/grub/redeploy.cfg "$TARGET_USER"@"$addr":/home/"$TARGET_USER"/redeploy/cloud-configs/grub/redeploy.cfg | ||
|
||
# Copy ssh key from alloem-init injections to the target | ||
$SCP -r "$CONFIG_REPO_PATH"/injections/alloem-init/chroot/minimal.standard.live.hotfix.squashfs/etc/ssh "$TARGET_USER"@"$addr":/home/"$TARGET_USER"/redeploy/ssh-config | ||
|
||
# Umount the partitions | ||
MOUNT=$($SSH "$TARGET_USER"@"$addr" -- lsblk -n -o MOUNTPOINT "$RESET_PART") | ||
if [ -n "$MOUNT" ]; then | ||
$SSH "$TARGET_USER"@"$addr" -- sudo umount "$RESET_PART" | ||
fi | ||
MOUNT=$($SSH "$TARGET_USER"@"$addr" -- lsblk -n -o MOUNTPOINT "$EFI_PART") | ||
if [ -n "$MOUNT" ]; then | ||
$SSH "$TARGET_USER"@"$addr" -- sudo umount "$EFI_PART" | ||
fi | ||
|
||
# Format partitions | ||
$SSH "$TARGET_USER"@"$addr" -- sudo mkfs.vfat "$RESET_PART" | ||
$SSH "$TARGET_USER"@"$addr" -- sudo mkfs.vfat "$EFI_PART" | ||
|
||
# Mount ISO and reset partition | ||
$SSH "$TARGET_USER"@"$addr" -- mkdir -p /home/"$TARGET_USER"/iso || true | ||
$SSH "$TARGET_USER"@"$addr" -- mkdir -p /home/"$TARGET_USER"/reset || true | ||
$SSH "$TARGET_USER"@"$addr" -- sudo mount -o loop /home/"$TARGET_USER"/"$ISO" /home/"$TARGET_USER"/iso || true | ||
$SSH "$TARGET_USER"@"$addr" -- sudo mount "$RESET_PART" /home/"$TARGET_USER"/reset || true | ||
|
||
# Sync ISO to the reset partition | ||
$SSH "$TARGET_USER"@"$addr" -- sudo rsync -avP /home/"$TARGET_USER"/iso/ /home/"$TARGET_USER"/reset || true | ||
|
||
# Sync cloud-configs to the reset partition | ||
$SSH "$TARGET_USER"@"$addr" -- sudo mkdir -p /home/"$TARGET_USER"/reset/cloud-configs || true | ||
$SSH "$TARGET_USER"@"$addr" -- sudo cp -r /home/"$TARGET_USER"/redeploy/cloud-configs/redeploy/ /home/"$TARGET_USER"/reset/cloud-configs/ | ||
$SSH "$TARGET_USER"@"$addr" -- sudo cp -r /home/"$TARGET_USER"/redeploy/ssh-config/ /home/"$TARGET_USER"/reset/ | ||
$SSH "$TARGET_USER"@"$addr" -- sudo cp /home/"$TARGET_USER"/redeploy/cloud-configs/grub/redeploy.cfg /home/"$TARGET_USER"/reset/boot/grub/grub.cfg | ||
$SSH "$TARGET_USER"@"$addr" -- sudo sed -i "s/RP_PARTUUID/${RESET_PARTUUID}/" /home/"$TARGET_USER"/reset/boot/grub/grub.cfg | ||
|
||
# Reboot the target | ||
$SSH "$TARGET_USER"@"$addr" -- sudo reboot || true | ||
done | ||
|
||
# Clear the known hosts | ||
for addr in "${TARGET_IPS[@]}"; | ||
do | ||
if [ -f "$HOME/.ssh/known_hosts" ]; then | ||
ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$addr" | ||
fi | ||
done | ||
|
||
# Polling the targets | ||
STARTED=("${TARGET_IPS[@]}") | ||
finished=0 | ||
startTime=$(date +%s) | ||
while :; | ||
do | ||
sleep 180 | ||
currentTime=$(date +%s) | ||
if [[ $((currentTime - startTime)) -gt $TIMEOUT ]]; then | ||
echo "Timeout is reached, deployment are not finished" | ||
break | ||
fi | ||
|
||
for addr in "${STARTED[@]}"; | ||
do | ||
if $SSH "$TARGET_USER"@"$addr" -- exit; then | ||
STARTED=("${STARTED[@]/$addr}") | ||
finished=$((finished + 1)) | ||
fi | ||
done | ||
|
||
if [ $finished -eq ${#TARGET_IPS[@]} ]; then | ||
echo "Deployment are done" | ||
break | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"fake_connector", | ||
"hp_oemscript", | ||
"lenovo_oemscript", | ||
"noble_oemscript", | ||
"maas2", | ||
"multi", | ||
"muxpi", | ||
|
44 changes: 44 additions & 0 deletions
44
device-connectors/src/testflinger_device_connectors/devices/noble_oemscript/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (C) 2023 Canonical | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
Ubuntu OEM Recovery Provisioning for OEM laptops with Ubuntu Noble series. | ||
Starting from 24.04 OEM uses the same image and script for all vendors. | ||
Use this for systems that can use the oem image-deploy.sh script | ||
for provisioning. | ||
""" | ||
|
||
import logging | ||
|
||
from testflinger_device_connectors.devices import ( | ||
DefaultDevice, | ||
RecoveryError, | ||
catch, | ||
) | ||
from .noble_oemscript import NobleOemScript | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DeviceConnector(DefaultDevice): | ||
"""Tool for provisioning Noble OEM devices with an oem image.""" | ||
|
||
@catch(RecoveryError, 46) | ||
def provision(self, args): | ||
"""Method called when the command is invoked.""" | ||
device = NobleOemScript(args.config, args.job_data) | ||
logger.info("BEGIN provision") | ||
logger.info("Provisioning device") | ||
device.provision() | ||
logger.info("END provision") |
28 changes: 28 additions & 0 deletions
28
...e-connectors/src/testflinger_device_connectors/devices/noble_oemscript/noble_oemscript.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (C) 2023 Canonical | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Ubuntu OEM Script provisioning for OEM devices with Ubuntu Noble series | ||
For systems that use the oem image-deploy.sh script for provisioning | ||
""" | ||
|
||
import logging | ||
from testflinger_device_connectors.devices.oemscript.oemscript import OemScript | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NobleOemScript(OemScript): | ||
"""Device Agent for Noble OEM devices.""" | ||
|
||
distro = "noble" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters