Skip to content

Commit

Permalink
Add support for SoC separate var partition
Browse files Browse the repository at this point in the history
Updating tests/e2e/set-ffi-env-e2e to mkfs.ext4
On free sde partiton it finds
Move disk functions to lib/diskutils script
Increase timers for memory and qm-oom-score-adj

Signed-off-by: Yariv Rachmani <[email protected]>
  • Loading branch information
Yarboa committed Aug 30, 2024
1 parent 32bb6d3 commit 2f5ec32
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 49 deletions.
109 changes: 109 additions & 0 deletions tests/e2e/lib/diskutils
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash
#
# Copyright 2023 The qm Authors
#
# 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 2
# of the License, or (at your option) any later version.
#
# 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/>.

select_disk_to_partition(){
###########################################################################
# Description: #
# Select free partition with size in "G" #
# #
# Arguments: should be be exported by calling script #
# DEVICE, set free /dev/ device #
# PART_ID, set device partition #
###########################################################################

local disk_table
disk_table=$(lsblk --noheadings --raw)
local disks_arr
disks_arr=$(echo "$disk_table" | awk '$1~// && $6=="disk" {print $1}')
info_message "select_disk_to_partition, found ${disks_arr}"
info_message "=============================="

for disk in $disks_arr; do
if [[ ${disk} == "vda" || \
$(echo "${disk_table}" | grep -c "${disk}" ) -eq 1 && ${disk} != "zram0" ]];then
new_part="$( (echo n; echo p; echo ; echo ; echo ; echo w) | fdisk "/dev/${disk}")"
part_id="$(echo "${new_part}" | grep -Po "new partition \K([0-9])")"
DISK="${disk}"
if [[ $(echo "${DISK}" | grep -c nvme) -eq 1 ]]; then
PART_ID="p${part_id}"
info_message "select_disk_to_partition, found /dev/${DISK}${PART_ID}"
info_message "=============================="
break;
fi
fi
if [ -e "${SOC_DISTRO_FILE}" ]; then
if grep -qi "${QC_SOC}" "${SOC_DISTRO_FILE}"; then
if [[ "${disk}" == "${QC_SOC_DISK}" ]]; then
DISK=${disk}
part=$(echo "${disk_table}" | grep "G" | grep "${QC_SOC_DISK}[0-9]." | grep -v "/" | cut -d" " -f1 )
PART_ID=${part:3}
break;
fi
fi
fi
done
}

create_qm_var_part() {
###########################################################################
# Description: #
# Create relevant filesystem #
# support fstype, non ostree, xfs (c9s vm), ext4(soc) #
# ARGUMENTS: should be be exported by calling script #
# DEVICE, set free /dev/ device #
# PART_ID, set device partition #
###########################################################################

select_disk_to_partition

local slash_var
slash_var="/var"

# Check is SoC aboot exist, else regular image
if [ -e "${SOC_DISTRO_FILE}" ]; then
if grep -qi "${QC_SOC}" "${SOC_DISTRO_FILE}"; then
mkfs.ext4 "/dev/${DISK}${PART_ID}"
if_error_exit "Error: mkfs.ext4 /dev/${DISK}${PART_ID} failed on ${QC_SOC}"
info_message "Create_qm_disks, prepare SoC ext4 fs"
info_message "=============================="
fi
else
# VM use case
mkfs.xfs "/dev/${DISK}${PART_ID}"
if_error_exit "Error: mkfs.xfs /dev/${DISK}${PART_ID} failed on VM"
info_message "Create_qm_disks, prepare regular xfs fs"
info_message "=============================="

fi

mkdir -p /new_var
mount "/dev/${DISK}${PART_ID}" /new_var
rsync -aqxXP /var/* /new_var
if_error_exit "Error: rsync failed"
systemctl stop var-lib-nfs-rpc_pipefs.mount
umount /new_var
rm -rf "${slash_var:?}"/*
info_message "Create_qm_disks, prepare and mount ${slash_var}"
info_message "=============================="
mount "/dev/${DISK}${PART_ID}" "${slash_var}"
if_error_exit "Error: mount /dev/${DISK}${PART_ID} on ${slash_var} failed"
systemctl start var-lib-nfs-rpc_pipefs.mount
if_error_exit "Error: service var-lib-nfs-rpc_pipefs.mount start failed"
}



71 changes: 25 additions & 46 deletions tests/e2e/set-ffi-env-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ source "${SCRIPT_DIR}"/lib/container
source "${SCRIPT_DIR}"/lib/systemd
# shellcheck disable=SC1091
source "${SCRIPT_DIR}"/lib/tests
# shellcheck disable=SC1091
source "${SCRIPT_DIR}"/lib/diskutils

# GLOBALS
export CONFIG_NODE_AGENT_PATH="/etc/bluechi/agent.conf.d/agent.conf"
Expand All @@ -41,6 +43,11 @@ export NODES_FOR_TESTING=("control" "node1")
export IP_CONTROL_MACHINE=""
export CONTAINER_CAP_ADD=""
export ARCH=""
export DISK=""
export PART_ID=""
export QC_SOC="${QC_SOC_TYPE:-SA8775P}"
export SOC_DISTRO_FILE="${SOC_FILE:-/sys/devices/soc0/machine}"
export QC_SOC_DISK="${QC_DISK_NAME:-sde}"

export BUILD_BLUECHI_FROM_GH_URL=""
export QM_GH_URL=""
Expand Down Expand Up @@ -140,42 +147,6 @@ while [ $# -gt 0 ]; do
esac
done

create_qm_disks() {

local disk_table
disk_table=$(lsblk --noheadings --raw)
local disks_arr
local slash_var
slash_var="/var"
disks_arr=$(echo "$disk_table" | awk '$1~// && $6=="disk" {print $1}')
info_message "Create_qm_disks, found ${disks_arr}"
info_message "=============================="

for disk in $disks_arr; do
if [[ ${disk} == "vda" || \
$(echo "${disk_table}" | grep -c "${disk}" ) -eq 1 && ${disk} != "zram0" ]];then
new_part="$( (echo n; echo p; echo ; echo ; echo ; echo w) | fdisk "/dev/${disk}")"
part_id="$(echo "${new_part}" | grep -Po "new partition \K([0-9])")"
if [[ $(echo "${disk}" | grep -c nvme) -eq 1 ]]; then
part_id=p${part_id}
fi
mkfs.xfs "/dev/${disk}${part_id}"
info_message "Create_qm_disks, prepare and mount /new_var"
info_message "=============================="
mkdir -p /new_var
mount "/dev/${disk}${part_id}" /new_var
rsync -aqxP /var/* /new_var
systemctl stop var-lib-nfs-rpc_pipefs.mount
umount /new_var
rm -rf "${slash_var:?}"/*
info_message "Create_qm_disks, prepare and mount ${slash_var}"
info_message "=============================="
mount "/dev/${disk}${part_id}" "${slash_var}"
systemctl start var-lib-nfs-rpc_pipefs.mount
fi
done
}

install_qm_rpms() {

info_message "Installing qm setup rpm"
Expand Down Expand Up @@ -273,12 +244,30 @@ then
exit
fi

if stat /run/ostree-booted > /dev/null 2>&1; then
info_message "Warning: script can not run on ostree image"
info_message "=============================="
exit 0
fi

# Creates partitions for QM env on VM
echo
info_message "Check if qm requires additional partition"
info_message "=============================="
if [ -n "${SET_QM_PART}" ]; then
create_qm_var_part
fi

echo
info_message "Checking if QM already installed"
info_message "=============================="
QM_STATUS="$(systemctl is-enabled qm 2>&1)"
if [ "$QM_STATUS" == "generated" ]; then
if [ "$(systemctl is-active qm)" == "active" ]; then
# Restart QM after mount /var on separate partition
if grep -qi "${QC_SOC}" "${SOC_DISTRO_FILE}"; then
systemctl restart qm
fi
info_message "QM Enabled and Active"
info_message "=============================="
exit 0
Expand All @@ -290,12 +279,6 @@ if [ "$QM_STATUS" == "generated" ]; then
fi
fi

if stat /run/ostree-booted > /dev/null 2>&1; then
info_message "Warning: script can not run on ostree image"
info_message "=============================="
exit 0
fi

info_message "Cleaning any previous e2e files"
info_message "=============================="
cleanup
Expand All @@ -304,10 +287,6 @@ echo
info_message "Preparing QM environment"
info_message "=============================="

# Creates the QM env on VM
if [ -n "${SET_QM_PART}" ]; then
create_qm_disks
fi
install_qm_rpms
setup_qm_services

Expand Down
8 changes: 7 additions & 1 deletion tests/ffi/disk/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ cat << EOF > "${DROP_IN_DIR}"/oom.conf
[Service]
OOMScoreAdjust=
OOMScoreAdjust=1000
[Container]
PodmanArgs=
PodmanArgs=--pids-limit=-1 --security-opt seccomp=/usr/share/qm/seccomp.json --security-opt label=nested --security-opt unmask=all --memory 5G
EOF

reload_config
prepare_images

exec_cmd "podman exec -it qm /bin/bash -c \
'podman run -d --replace --name ffi-qm \
'podman run -d --replace --name ffi-qm \
quay.io/centos-sig-automotive/ffi-tools:latest \
tail -f /dev/null'"

Expand All @@ -31,4 +36,5 @@ fi

ls -lh /root/file.lock

disk_cleanup

2 changes: 1 addition & 1 deletion tests/ffi/memory/main.fmf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
summary: Test is calling systemd as stand alone test
test: /bin/bash ./test.sh
duration: 20m
duration: 25m
tag: ffi
framework: shell
id: fff26f33-a051-4d9e-aae2-97935e425273
2 changes: 1 addition & 1 deletion tests/ffi/qm-oom-score-adj/main.fmf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
summary: Test the qm's oom-score-adj values
test: /bin/bash ./test.sh
duration: 20m
duration: 25m
tag: ffi
framework: shell
id: 6e6c5cea-efc7-48e9-8b4c-d355229ab1c2

0 comments on commit 2f5ec32

Please sign in to comment.