Skip to content

Commit

Permalink
src: deploy: Use kernel_img_name for the kernel image
Browse files Browse the repository at this point in the history
In the kworkflow.config file, we have a variable named kernel_img_name
used to define the binary kernel prefix used during the deploy. Even
though we have this variable, we were ignoring it. As a result, when we
deploy a new kernel image to a rasp system, we see a kernel image with a
vmlinuz prefix. This commit fixes this issue by stopping to ignore that
config variable and only set vmlinuz if that variable is empty.

Signed-off-by: Rodrigo Siqueira <siqueirajordao@riseup.net>
  • Loading branch information
rodrigosiqueira committed Mar 26, 2022
1 parent d94f563 commit 4bd8b79
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 48 deletions.
57 changes: 30 additions & 27 deletions src/deploy.sh
Expand Up @@ -878,10 +878,11 @@ function pack_kernel_files_and_send()
{
local flag="$1"
local target="$2"
local kernel_img_name="$3"
local name="$4"
local kernel_binary_file_name="$3"
local kernel_name="$4"
local arch=${5-${configurations[arch]}}
local build_and_deploy="$6"
local config_kernel_img_name=${configurations[kernel_img_name]}
local base_boot_path
local config_path
local config_local_version
Expand All @@ -898,9 +899,11 @@ function pack_kernel_files_and_send()
cache_boot_files_path="${cache_to_deploy_path}/boot"
tar_file_path="${cache_to_deploy_path}/${name}_boot.tar"

base_boot_path="arch/$arch_target/boot"
base_boot_path="arch/$arch/boot"
dts_base_path="${base_boot_path}/dts"

[[ -z "$config_kernel_img_name" ]] && config_kernel_img_name='kernel'

# Centralizing kernel files in a single place
mkdir -p "$cache_boot_files_path"

Expand All @@ -911,30 +914,31 @@ function pack_kernel_files_and_send()
else
config_local_version=$(sed -nr '/CONFIG_LOCALVERSION=/s/CONFIG_LOCALVERSION="(.*)"/\1/p' "$config_path")

if [[ -n "$build_and_deploy" || "$name" =~ $config_local_version.*$ ]]; then
cmd="cp $config_path ${cache_boot_files_path}/config-$name"
if [[ -n "$build_and_deploy" || "$kernel_name" =~ $config_local_version.*$ ]]; then
cmd="cp $config_path ${cache_boot_files_path}/config-$kernel_name"
cmd_manager "$flag" "$cmd"
fi
fi

# 2. Copy kernel image
case "$arch" in
'arm')
kernel_name_arch="kernel-${name}.img"
'arm' | 'arm64')
kernel_name_arch="${config_kernel_img_name}-${kernel_name}"
;;
*)
kernel_name_arch="vmlinuz-${name}"
# X86 system usually uses vmlinuz
kernel_name_arch="vmlinuz-${kernel_name}"
;;
esac

cmd="cp ${base_boot_path}/${kernel_img_name}"
cmd="cp ${base_boot_path}/${kernel_binary_file_name}"
cmd+=" ${cache_boot_files_path}/${kernel_name_arch}"
cmd_manager "$flag" "$cmd"

# 3. If we have dtb files, let's copy it
if [[ -d "$dts_base_path" ]]; then
# Simple patter, e.g., copy_pattern='broadcom/*'
copy_pattern=$(compose_copy_source_parameter_for_dtb "$arch_target")
copy_pattern=$(compose_copy_source_parameter_for_dtb "$arch")
cmd_manager "$flag" "cp ${copy_pattern} ${cache_boot_files_path}/"

if [[ -d "${dts_base_path}/overlays" ]]; then
Expand Down Expand Up @@ -986,17 +990,17 @@ function run_kernel_install()
local user="${5:-${remote_parameters['REMOTE_USER']}}"
local build_and_deploy="$6"
local distro='none'
local kernel_name="${configurations[kernel_name]}"
local kernel_name="${configurations[kernel_img_name]}"
local mkinitcpio_name="${configurations[mkinitcpio_name]}"
local arch_target="${configurations[arch]}"
local kernel_img_name="${configurations[kernel_img_name]}"
local kernel_binary_file_name
local remote
local port
local config_local_version
local cmd

# We have to guarantee some default values values
kernel_name=${kernel_name:-'nothing'}
kernel_name=${kernel_img_name:-'nothing'}
mkinitcpio_name=${mkinitcpio_name:-'nothing'}
name=${name:-'kw'}
flag=${flag:-'SILENT'}
Expand All @@ -1008,20 +1012,19 @@ function run_kernel_install()
fi
fi

if [[ ! -f "arch/$arch_target/boot/$kernel_img_name" ]]; then
# Try to infer the kernel image name
kernel_img_name=$(find "arch/$arch_target/boot/" -name '*Image' 2> /dev/null)
kernel_img_name=$(basename "$kernel_img_name")
if [[ -z "$kernel_img_name" ]]; then
complain "We could not find a valid kernel image at arch/$arch_target/boot"
complain 'Please, check your compilation and/or the option kernel_img_name inside kworkflow.config'
exit 125 # ECANCELED
fi
warning "kw inferred arch/$arch_target/boot/$kernel_img_name as a kernel image"
# Try to find the latest generated kernel image
kernel_binary_file_name=$(find "arch/$arch_target/boot/" -name '*Image' \
-printf '%T+ %p\n' 2> /dev/null | sort -r | head -1)
kernel_binary_file_name=$(basename "$kernel_binary_file_name")
if [[ -z "$kernel_binary_file_name" ]]; then
complain "We could not find a valid kernel image at arch/$arch_target/boot"
complain 'Please, check if your compilation successfully completed or'
complain 'check your kworkflow.config'
exit 125 # ECANCELED
fi

say '* Sending kernel boot files'
pack_kernel_files_and_send "$flag" "$target" "$kernel_img_name" \
pack_kernel_files_and_send "$flag" "$target" "$kernel_binary_file_name" \
"$name" "$arch_target" "$build_and_deploy"

case "$target" in
Expand All @@ -1038,7 +1041,7 @@ function run_kernel_install()
include "$KW_PLUGINS_DIR/kernel_install/utils.sh"
update_deploy_variables # Make sure we use the right variable values

install_kernel "$name" "$distro" "$kernel_img_name" "$reboot" "$arch_target" 'vm' "$flag"
install_kernel "$name" "$distro" "$kernel_binary_file_name" "$reboot" "$arch_target" 'vm' "$flag"
return "$?"
;;
2) # LOCAL_TARGET
Expand All @@ -1059,7 +1062,7 @@ function run_kernel_install()
include "$KW_PLUGINS_DIR/kernel_install/utils.sh"
update_deploy_variables # Ensure that we are using the right variable

install_kernel "$name" "$distro" "$kernel_img_name" "$reboot" "$arch_target" 'local' "$flag"
install_kernel "$name" "$distro" "$kernel_binary_file_name" "$reboot" "$arch_target" 'local' "$flag"
return "$?"
;;
3) # REMOTE_TARGET
Expand All @@ -1071,7 +1074,7 @@ function run_kernel_install()
distro=$(detect_distro '/' "$distro_info")

# Deploy
local cmd_parameters="$name $distro $kernel_img_name $reboot $arch_target 'remote' $flag"
local cmd_parameters="$name $distro $kernel_binary_file_name $reboot $arch_target 'remote' $flag"
cmd="$REMOTE_INTERACE_CMD_PREFIX"
cmd+=" --kernel-update $cmd_parameters"

Expand Down
50 changes: 29 additions & 21 deletions tests/deploy_test.sh
Expand Up @@ -71,7 +71,7 @@ function setUp()
# Repetive command composing
NAME='test'
COPY_CONFIG_FILE="cp .config ${TO_DEPLOY_BOOT_PATH}/config-${NAME}"
COPY_KERNEL_IMAGE="cp arch/arm64/boot/Image ${TO_DEPLOY_BOOT_PATH}/vmlinuz-${NAME}"
COPY_KERNEL_IMAGE="cp arch/arm64/boot/Image ${TO_DEPLOY_BOOT_PATH}/Image-${NAME}"

GENERATE_BOOT_TAR_FILE="tar --auto-compress --directory='${LOCAL_TO_DEPLOY_PATH}'"
GENERATE_BOOT_TAR_FILE+=" --create --file='${LOCAL_TO_DEPLOY_PATH}/${NAME}_boot.tar' boot"
Expand All @@ -83,7 +83,7 @@ function setUp()
declare -ga BASE_EXPECTED_CMD_ARM_LOCAL=(
"$SENDING_KERNEL_MSG"
"$UNDEFINED_CONFIG"
"$COPY_KERNEL_IMAGE"
"cp arch/arm64/boot/vmlinuz-5 ${TO_DEPLOY_BOOT_PATH}/Image-${NAME}"
"sudo cp -r $LOCAL_TO_DEPLOY_PATH/boot/* /boot/"
'generate_debian_temporary_root_file_system TEST_MODE test local GRUB'
'sudo -E grub-mkconfig -o /boot/grub/grub.cfg'
Expand Down Expand Up @@ -141,7 +141,9 @@ function tearDown()
configurations=()
BASE_EXPECTED_CMD_ARM_REMOTE=()
BASE_EXPECTED_CMD_X86_REMOTE=()
BASE_EXPECTED_CMD_ARM_LOCAL=()

unalias -a find
rm -rf "$FAKE_KERNEL"
}

Expand Down Expand Up @@ -562,25 +564,26 @@ function test_kernel_install_x86_64_to_remote_no_kernel_image_failure()

}

function test_kernel_install_x86_64_to_remote_name_infer()
function test_kernel_install_binary_name_without_kernel_img_name_param()
{
local original="$PWD"
local expected_msg
local output

# Test preparation
cd "$original" || {
fail "($LINENO) It was not possible to move back from temp directory"
return
}

# Reset values
configurations=()
remote_parameters=()
cp "$KW_CONFIG_SAMPLE_X86" "$FAKE_KERNEL/kworkflow.config"
parse_configuration "$FAKE_KERNEL/kworkflow.config"
local deploy_params
local execute_deploy_remote

configurations['kernel_img_name']=''
deploy_params="${NAME} debian Image 1 arm64 'remote' TEST_MODE"
execute_deploy_remote=$(get_deploy_cmd_helper "$deploy_params")

declare -ga BASE_EXPECTED_CMD_CUSTOM_ARM_REMOTE=(
"$SENDING_KERNEL_MSG"
"$UNDEFINED_CONFIG"
"cp arch/arm64/boot/Image ${TO_DEPLOY_BOOT_PATH}/kernel-${NAME}"
"$GENERATE_BOOT_TAR_FILE"
"rsync --info=progress2 -e 'ssh -p 3333' ${LOCAL_TO_DEPLOY_PATH}/${NAME}_boot.tar juca@127.0.0.1:$KW_DEPLOY_TMP_FILE $STD_RSYNC_FLAG"
"$execute_deploy_remote"
)

cd "$FAKE_KERNEL" || {
fail "($LINENO) It was not possible to move to temporary directory"
Expand All @@ -589,9 +592,8 @@ function test_kernel_install_x86_64_to_remote_name_infer()

# Test kernel image infer
output=$(run_kernel_install 1 'test' 'TEST_MODE' 3 '127.0.0.1:3333' |
tail -n +1 | head -1)
expected_msg='kw inferred arch/x86_64/boot/bzImage as a kernel image'
assert_equals_helper "Infer kernel image" "$LINENO" "$expected_msg" "$output"
tail -n +1)
compare_command_sequence '' "$LINENO" 'BASE_EXPECTED_CMD_CUSTOM_ARM_REMOTE' "$output"

cd "$original" || {
fail "($LINENO) It was not possible to move back from temp directory"
Expand All @@ -610,10 +612,11 @@ function test_kernel_install_arm_local_no_config()
}

alias collect_deploy_info='collect_deploy_info_mock'
# This mock refers to the function run_bootloader_update

# This mock the find command, to add multiple kernel images
alias find='find_kernels_mock'
output=$(run_kernel_install 1 'test' 'TEST_MODE' 2)

output=$(run_kernel_install 1 'test' 'TEST_MODE' 2)
compare_command_sequence '' "$LINENO" 'BASE_EXPECTED_CMD_ARM_LOCAL' "$output"

cd "$original" || {
Expand Down Expand Up @@ -1154,13 +1157,18 @@ function test_collect_target_info_for_deploy()
{
local output

# Avoid alias overwrite
include "$KW_PLUGINS_DIR/kernel_install/bootloader_utils.sh"
include "$KW_PLUGINS_DIR/kernel_install/utils.sh"

# Corner-cases
alias detect_distro='which_distro_none_mock'
output=$(collect_target_info_for_deploy 1 'TEST_MODE')
assert_equals_helper 'Wrong return value' "($LINENO)" 95 "$?"

# VM
alias detect_distro='which_distro_mock'
alias collect_deploy_info='collect_deploy_info_mock'
alias detect_distro='detect_distro_arch_mock'
collect_target_info_for_deploy 1 'TEST_MODE'
assert_equals_helper 'Check bootloader' "($LINENO)" "${target_deploy_info[bootloader]}" 'GRUB'
assert_equals_helper 'Check distro' "($LINENO)" "${target_deploy_info[distro]}" 'arch'
Expand Down

0 comments on commit 4bd8b79

Please sign in to comment.