From af7defe48f627bc97698e0d9c59de9c86e2b0be7 Mon Sep 17 00:00:00 2001 From: emacdona Date: Tue, 13 Dec 2022 14:34:26 -0500 Subject: [PATCH] Add error checking to worker_reserved.conf handling This update add error checking and error handling to worker_reserved.conf update handling. Test Plan: PASS: Verify kickstart logging around worker_reserved update for each of the install cases below. PASS: Verify subcloud install PASS: Verify All In One controller install PASS: Verify worker only install PASS: Verify standard Controller install Closes-Bug: 1999561 Signed-off-by: emacdona Change-Id: I7ccdd9cc02908fcb0fe0a403c2b2141bd44b692a --- kickstart/files/kickstart.cfg | 27 +++++++++++++++++++-------- kickstart/files/miniboot.cfg | 25 ++++++++++++++++++------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/kickstart/files/kickstart.cfg b/kickstart/files/kickstart.cfg index 0930182a..22515fd5 100644 --- a/kickstart/files/kickstart.cfg +++ b/kickstart/files/kickstart.cfg @@ -2373,26 +2373,37 @@ if [ "${aio}" = true ] ; then elif [ ${RESERVEDMEM} -gt 8192 ]; then RESERVEDMEM=8192 fi - + # Normally we would set personality based files later # But we need to copy worker_reserved.conf now since it needs to be modified for AIO - cp /usr/share/worker-utils/config/worker_reserved.conf /etc/platform/worker_reserved.conf ilog "${SYSTEM_TYPE__AIO} Reserved Memory: ${RESERVEDMEM}" - sed -i -e "s#\(WORKER_BASE_RESERVED\)=.*#\1=(\"node0:${RESERVEDMEM}MB:1\" \"node1:2000MB:0\" \"node2:2000MB:0\" \"node3:2000MB:0\")#g" /etc/platform/worker_reserved.conf - worker_reserved=$(grep WORKER_BASE_RESERVED /etc/platform/worker_reserved.conf) + TEMPLATE_FILE="/usr/share/worker-utils/config/worker_reserved.conf" + TARGET_FILE="/etc/platform/worker_reserved.conf" + if [ ! -e "${TEMPLATE_FILE}" ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; missing ${TEMPLATE_FILE}" + fi + cp "${TEMPLATE_FILE}" "${TARGET_FILE}" + if [ ! -e "${TARGET_FILE}" ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; missing ${TARGET_FILE}" + fi + sed -i -e "s#\(WORKER_BASE_RESERVED\)=.*#\1=(\"node0:${RESERVEDMEM}MB:1\" \"node1:2000MB:0\" \"node2:2000MB:0\" \"node3:2000MB:0\")#g" "${TARGET_FILE}" + if [ $? -ne 0 ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; previous sed search and replace request failed" + fi + worker_reserved=$(grep WORKER_BASE_RESERVED "${TARGET_FILE}") ilog "${SYSTEM_TYPE__AIO} '${worker_reserved}'" # Update WORKER_CPU_LIST N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}') - sed -i "s/^WORKER_CPU_LIST=.*/WORKER_CPU_LIST=\"0-$((N_CPUS-1))\"/" /etc/platform/worker_reserved.conf + sed -i "s/^WORKER_CPU_LIST=.*/WORKER_CPU_LIST=\"0-$((N_CPUS-1))\"/" "${TARGET_FILE}" - worker_cpu_list=$(grep WORKER_CPU_LIST /etc/platform/worker_reserved.conf) + worker_cpu_list=$(grep WORKER_CPU_LIST "${TARGET_FILE}") ilog "${SYSTEM_TYPE__AIO} '${worker_cpu_list}'" elif [ "${worker}" = true ] ; then # Keep logic contained and copy worker_reserved.conf now since we need # to do the copy for AIO above - ilog "Enable worker_reserved.conf for ${TRAIT__WORKER}" - cp /usr/share/worker-utils/config/worker_reserved.conf /etc/platform/worker_reserved.conf + ilog "Enable ${TARGET_FILE} for ${TRAIT__WORKER}" + cp "${TEMPLATE_FILE}" "${TARGET_FILE}" fi true diff --git a/kickstart/files/miniboot.cfg b/kickstart/files/miniboot.cfg index dc699913..bfea210e 100644 --- a/kickstart/files/miniboot.cfg +++ b/kickstart/files/miniboot.cfg @@ -2541,22 +2541,33 @@ if [ "${aio}" = true ] ; then # Normally we would set personality based files later # But we need to copy worker_reserved.conf now since it needs to be modified for AIO ilog "${SYSTEM_TYPE__AIO} Reserved Memory: ${RESERVEDMEM}" - cp /usr/share/worker-utils/config/worker_reserved.conf /etc/platform/worker_reserved.conf - sed -i -e "s#\(WORKER_BASE_RESERVED\)=.*#\1=(\"node0:${RESERVEDMEM}MB:1\" \"node1:2000MB:0\" \"node2:2000MB:0\" \"node3:2000MB:0\")#g" /etc/platform/worker_reserved.conf - worker_reserved=$(grep WORKER_BASE_RESERVED /etc/platform/worker_reserved.conf) + TEMPLATE_FILE="/usr/share/worker-utils/config/worker_reserved.conf" + TARGET_FILE="/etc/platform/worker_reserved.conf" + if [ ! -e "${TEMPLATE_FILE}" ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; missing ${TEMPLATE_FILE}" + fi + cp "${TEMPLATE_FILE}" "${TARGET_FILE}" + if [ ! -e "${TARGET_FILE}" ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; missing ${TARGET_FILE}" + fi + sed -i -e "s#\(WORKER_BASE_RESERVED\)=.*#\1=(\"node0:${RESERVEDMEM}MB:1\" \"node1:2000MB:0\" \"node2:2000MB:0\" \"node3:2000MB:0\")#g" "${TARGET_FILE}" + if [ $? -ne 0 ] ; then + report_failure_with_msg "Cannot configure worker cpu/memory ; previous sed search and replace request failed" + fi + worker_reserved=$(grep WORKER_BASE_RESERVED "${TARGET_FILE}") ilog "${SYSTEM_TYPE__AIO} '${worker_reserved}'" # Update WORKER_CPU_LIST N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}') - sed -i "s/^WORKER_CPU_LIST=.*/WORKER_CPU_LIST=\"0-$((N_CPUS-1))\"/" /etc/platform/worker_reserved.conf + sed -i "s/^WORKER_CPU_LIST=.*/WORKER_CPU_LIST=\"0-$((N_CPUS-1))\"/" "${TARGET_FILE}" - worker_cpu_list=$(grep WORKER_CPU_LIST /etc/platform/worker_reserved.conf) + worker_cpu_list=$(grep WORKER_CPU_LIST "${TARGET_FILE}") ilog "${SYSTEM_TYPE__AIO} '${worker_cpu_list}'" elif [ "${worker}" = true ] ; then # Keep logic contained and copy worker_reserved.conf now since we need # to do the copy for AIO above - ilog "Enable worker_reserved.conf for ${TRAIT__WORKER}" - cp /usr/share/worker-utils/config/worker_reserved.conf /etc/platform/worker_reserved.conf + ilog "Enable ${TARGET_FILE} for ${TRAIT__WORKER}" + cp "${TEMPLATE_FILE}" "${TARGET_FILE}" fi true