Fixing linters errors E010, E011, E020, E041,E043, E003, E001,E042

Listed below are the errors which were fixed as well as the actions
    taken to fix them:
    E010: do not on the same line as for
    --> let do and for in the same line
    E011: then not on the same line as if or elif
    --> let then and if or elif in the same line
    E020: Function declaration not in format ^function name {$
    --> fix the format to suit ^function name {$
    E041: Usage of $[ for arithmetic is deprecated for $((
    --> fix from $[ to $((
    E043: arithmetic compound has inconsistent return semantics
    --> do not use +=, ++, -=, --; use value=value+?  instead.
    E001: check that lines do not end with trailing whitespace
    --> delete trailing whitespace
    E003: ensure all indents are a multiple of 4 spaces
    --> add/delete spaces
    E042: local declaration hides errors
    --> let declaration and assignment in two lines.

    Listed below are test cases done which run one controller
    and one compute in KVMs
    Test-Install      ----  success

Related: https://review.openstack.org/#/c/600663/
         https://review.openstack.org/#/c/601221/

Story: 2003360
Task: 26213

Change-Id: I3ece37db3a326ea58bd344f43beefcbbbd4f0ad4
Signed-off-by: SidneyAn <ran1.an@intel.com>
This commit is contained in:
SidneyAn 2018-09-07 00:03:47 +08:00
parent 081cbf0240
commit 47ac546217
23 changed files with 486 additions and 541 deletions

View File

@ -21,25 +21,22 @@ LOG_PRIORITY=info
TMPLOG=/tmp/${WHOAMI}.log TMPLOG=/tmp/${WHOAMI}.log
# LOG() - generates log and puts in temporary file # LOG() - generates log and puts in temporary file
function LOG() function LOG {
{ logger -t "${0##*/}[$$]" -p ${LOG_FACILITY}.${LOG_PRIORITY} "$@"
logger -t "${0##*/}[$$]" -p ${LOG_FACILITY}.${LOG_PRIORITY} "$@" echo "${0##*/}[$$]" "$@" >> ${TMPLOG}
echo "${0##*/}[$$]" "$@" >> ${TMPLOG}
} }
function INFO() function INFO {
{ MSG="INFO"
MSG="INFO" LOG "${MSG} $@"
LOG "${MSG} $@"
} }
function ERROR() function ERROR {
{ MSG="ERROR"
MSG="ERROR" LOG "${MSG} $@"
LOG "${MSG} $@"
} }
if [ "$#" -ne 2 ]; then if [ "$#" -ne 2 ]; then
ERROR "Interface name and cpulist are required" ERROR "Interface name and cpulist are required"
exit 1 exit 1
fi fi
interface=$1 interface=$1
@ -47,7 +44,7 @@ cpulist=$2
# Find PCI device matching interface, keep last matching device name # Find PCI device matching interface, keep last matching device name
dev=$(find /sys/devices -name "${interface}" | \ dev=$(find /sys/devices -name "${interface}" | \
perl -ne 'print $1 if /([[:xdigit:]]{4}:[[:xdigit:]]{2}:[[:xdigit:]]{2}\.[[:xdigit:]])\/[[:alpha:]]/;') perl -ne 'print $1 if /([[:xdigit:]]{4}:[[:xdigit:]]{2}:[[:xdigit:]]{2}\.[[:xdigit:]])\/[[:alpha:]]/;')
# Obtain all IRQs for this device # Obtain all IRQs for this device
irq=$(cat /sys/bus/pci/devices/${dev}/irq 2>/dev/null) irq=$(cat /sys/bus/pci/devices/${dev}/irq 2>/dev/null)
@ -56,7 +53,7 @@ msi_irqs=$(ls /sys/bus/pci/devices/${dev}/msi_irqs 2>/dev/null | xargs)
INFO $LINENO "affine ${interface} (dev:${dev} irq:${irq} msi_irqs:${msi_irqs}) with cpus (${cpulist})" INFO $LINENO "affine ${interface} (dev:${dev} irq:${irq} msi_irqs:${msi_irqs}) with cpus (${cpulist})"
for i in $(echo "${irq} ${msi_irqs}"); do echo $i; done | \ for i in $(echo "${irq} ${msi_irqs}"); do echo $i; done | \
xargs --no-run-if-empty -i{} \ xargs --no-run-if-empty -i{} \
/bin/bash -c "[[ -e /proc/irq/{} ]] && echo ${cpulist} > /proc/irq/{}/smp_affinity_list" 2>/dev/null /bin/bash -c "[[ -e /proc/irq/{} ]] && echo ${cpulist} > /proc/irq/{}/smp_affinity_list" 2>/dev/null
exit 0 exit 0

View File

@ -26,8 +26,7 @@ LOG_DEBUG=1
################################################################################ ################################################################################
# Affine all running tasks to the CPULIST provided in the first parameter. # Affine all running tasks to the CPULIST provided in the first parameter.
################################################################################ ################################################################################
function affine_tasks function affine_tasks {
{
local CPULIST=$1 local CPULIST=$1
local PIDLIST local PIDLIST
local RET=0 local RET=0
@ -40,11 +39,11 @@ function affine_tasks
RET=$? RET=$?
if [ $RET -ne 0 ]; then if [ $RET -ne 0 ]; then
log_error "Some tasks failed to be affined to all cores." log_error "Some tasks failed to be affined to all cores."
fi fi
# Get number of logical cpus # Get number of logical cpus
N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | \ N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | \
awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}') awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}')
# Calculate platform cores cpumap # Calculate platform cores cpumap
PLATFORM_COREMASK=$(cpulist_to_cpumap ${CPULIST} ${N_CPUS}) PLATFORM_COREMASK=$(cpulist_to_cpumap ${CPULIST} ${N_CPUS})
@ -66,30 +65,26 @@ function affine_tasks
/bin/bash -c "[[ -e /proc/irq/${i} ]] && echo ${CPULIST} > /proc/irq/${i}/smp_affinity_list" 2>/dev/null /bin/bash -c "[[ -e /proc/irq/${i} ]] && echo ${CPULIST} > /proc/irq/${i}/smp_affinity_list" 2>/dev/null
done done
if [[ "$subfunction" == *"compute,lowlatency" ]]; then if [[ "$subfunction" == *"compute,lowlatency" ]]; then
# Affine work queues to platform cores # Affine work queues to platform cores
echo ${PLATFORM_COREMASK} > /sys/devices/virtual/workqueue/cpumask echo ${PLATFORM_COREMASK} > /sys/devices/virtual/workqueue/cpumask
echo ${PLATFORM_COREMASK} > /sys/bus/workqueue/devices/writeback/cpumask echo ${PLATFORM_COREMASK} > /sys/bus/workqueue/devices/writeback/cpumask
# On low latency compute reassign the per cpu threads rcuc, ksoftirq, # On low latency compute reassign the per cpu threads rcuc, ksoftirq,
# ktimersoftd to FIFO along with the specified priority # ktimersoftd to FIFO along with the specified priority
PIDLIST=$( ps -e -p 2 |grep rcuc | awk '{ print $1; }') PIDLIST=$( ps -e -p 2 |grep rcuc | awk '{ print $1; }')
for PID in ${PIDLIST[@]} for PID in ${PIDLIST[@]}; do
do chrt -p -f 4 ${PID} 2>/dev/null
chrt -p -f 4 ${PID} 2>/dev/null done
done
PIDLIST=$( ps -e -p 2 |grep ksoftirq | awk '{ print $1; }') PIDLIST=$( ps -e -p 2 |grep ksoftirq | awk '{ print $1; }')
for PID in ${PIDLIST[@]} for PID in ${PIDLIST[@]}; do
do chrt -p -f 2 ${PID} 2>/dev/null
chrt -p -f 2 ${PID} 2>/dev/null done
done
PIDLIST=$( ps -e -p 2 |grep ktimersoftd | awk '{ print $1; }') PIDLIST=$( ps -e -p 2 |grep ktimersoftd | awk '{ print $1; }')
for PID in ${PIDLIST[@]} for PID in ${PIDLIST[@]}; do
do chrt -p -f 3 ${PID} 2>/dev/null
chrt -p -f 3 ${PID} 2>/dev/null done
done
fi fi
return 0 return 0
@ -98,8 +93,7 @@ function affine_tasks
################################################################################ ################################################################################
# Start Action # Start Action
################################################################################ ################################################################################
function start function start {
{
local RET=0 local RET=0
echo -n "Starting ${scriptname}: " echo -n "Starting ${scriptname}: "
@ -129,8 +123,7 @@ function start
################################################################################ ################################################################################
# Stop Action - don't do anything # Stop Action - don't do anything
################################################################################ ################################################################################
function stop function stop {
{
local RET=0 local RET=0
echo -n "Stopping ${scriptname}: " echo -n "Stopping ${scriptname}: "
print_status ${RET} print_status ${RET}
@ -140,7 +133,7 @@ function stop
################################################################################ ################################################################################
# Restart Action # Restart Action
################################################################################ ################################################################################
function restart() { function restart {
stop stop
start start
} }

View File

@ -11,20 +11,17 @@ source /etc/platform/platform.conf
################################################################################ ################################################################################
# Utility function to expand a sequence of numbers (e.g., 0-7,16-23) # Utility function to expand a sequence of numbers (e.g., 0-7,16-23)
################################################################################ ################################################################################
function expand_sequence function expand_sequence {
{
SEQUENCE=(${1//,/ }) SEQUENCE=(${1//,/ })
DELIMITER=${2:-","} DELIMITER=${2:-","}
LIST= LIST=
for entry in ${SEQUENCE[@]} for entry in ${SEQUENCE[@]}; do
do
range=(${entry/-/ }) range=(${entry/-/ })
a=${range[0]} a=${range[0]}
b=${range[1]:-${range[0]}} b=${range[1]:-${range[0]}}
for i in $(seq $a $b) for i in $(seq $a $b); do
do
LIST="${LIST}${DELIMITER}${i}" LIST="${LIST}${DELIMITER}${i}"
done done
done done
@ -34,11 +31,10 @@ function expand_sequence
################################################################################ ################################################################################
# Append a string to comma separated list string # Append a string to comma separated list string
################################################################################ ################################################################################
function append_list() { function append_list {
local PUSH=$1 local PUSH=$1
local LIST=$2 local LIST=$2
if [ -z "${LIST}" ] if [ -z "${LIST}" ]; then
then
LIST=${PUSH} LIST=${PUSH}
else else
LIST="${LIST},${PUSH}" LIST="${LIST},${PUSH}"
@ -50,13 +46,12 @@ function append_list() {
################################################################################ ################################################################################
# Condense a sequence of numbers to a list of ranges (e.g, 7-12,15-16) # Condense a sequence of numbers to a list of ranges (e.g, 7-12,15-16)
################################################################################ ################################################################################
function condense_sequence() { function condense_sequence {
local arr=( $(printf '%s\n' "$@" | sort -n) ) local arr=( $(printf '%s\n' "$@" | sort -n) )
local first local first
local last local last
local cpulist="" local cpulist=""
for ((i=0; i < ${#arr[@]}; i++)) for ((i=0; i < ${#arr[@]}; i++)); do
do
num=${arr[$i]} num=${arr[$i]}
if [[ -z $first ]]; then if [[ -z $first ]]; then
first=$num first=$num
@ -89,19 +84,16 @@ function condense_sequence() {
# number but without the leading "0x" characters. # number but without the leading "0x" characters.
# #
################################################################################ ################################################################################
function cpulist_to_cpumap function cpulist_to_cpumap {
{
local CPULIST=$1 local CPULIST=$1
local NR_CPUS=$2 local NR_CPUS=$2
local CPUMAP=0 local CPUMAP=0
local CPUID=0 local CPUID=0
if [ -z "${NR_CPUS}" ] || [ ${NR_CPUS} -eq 0 ] if [ -z "${NR_CPUS}" ] || [ ${NR_CPUS} -eq 0 ]; then
then
echo 0 echo 0
return 0 return 0
fi fi
for CPUID in $(expand_sequence $CPULIST " ") for CPUID in $(expand_sequence $CPULIST " "); do
do
if [ "${CPUID}" -lt "${NR_CPUS}" ]; then if [ "${CPUID}" -lt "${NR_CPUS}" ]; then
CPUMAP=$(echo "${CPUMAP} + (2^${CPUID})" | bc -l) CPUMAP=$(echo "${CPUMAP} + (2^${CPUID})" | bc -l)
fi fi
@ -117,9 +109,9 @@ function cpulist_to_cpumap
# characters. # characters.
# #
################################################################################ ################################################################################
function cpumap_to_cpulist function cpumap_to_cpulist {
{ local CPUMAP
local CPUMAP=$(echo "obase=10;ibase=16;$1" | bc -l) CPUMAP=$(echo "obase=10;ibase=16;$1" | bc -l)
local NR_CPUS=$2 local NR_CPUS=$2
local list=() local list=()
local cpulist="" local cpulist=""
@ -131,8 +123,7 @@ function cpumap_to_cpulist
## if (CPUMAP % (2**(CPUID+1)) > ((2**(CPUID)) - 1)) ## if (CPUMAP % (2**(CPUID+1)) > ((2**(CPUID)) - 1))
## ##
ISSET=$(echo "scale=0; (${CPUMAP} % 2^(${i}+1)) > (2^${i})-1" | bc -l) ISSET=$(echo "scale=0; (${CPUMAP} % 2^(${i}+1)) > (2^${i})-1" | bc -l)
if [ "${ISSET}" -ne 0 ] if [ "${ISSET}" -ne 0 ]; then
then
list+=($i) list+=($i)
fi fi
done done
@ -146,20 +137,19 @@ function cpumap_to_cpulist
# returned as a hexidecimal value but without the leading "0x" characters # returned as a hexidecimal value but without the leading "0x" characters
# #
################################################################################ ################################################################################
function invert_cpumap function invert_cpumap {
{ local CPUMAP
local CPUMAP=$(echo "obase=10;ibase=16;$1" | bc -l) CPUMAP=$(echo "obase=10;ibase=16;$1" | bc -l)
local NR_CPUS=$2 local NR_CPUS=$2
local INVERSE_CPUMAP=0 local INVERSE_CPUMAP=0
for CPUID in $(seq 0 $((NR_CPUS - 1))); for CPUID in $(seq 0 $((NR_CPUS - 1))); do
do
## See comment in previous function ## See comment in previous function
ISSET=$(echo "scale=0; (${CPUMAP} % 2^(${CPUID}+1)) > (2^${CPUID})-1" | bc -l) ISSET=$(echo "scale=0; (${CPUMAP} % 2^(${CPUID}+1)) > (2^${CPUID})-1" | bc -l)
if [ "${ISSET}" -eq 1 ]; then if [ "${ISSET}" -eq 1 ]; then
continue continue
fi fi
INVERSE_CPUMAP=$(echo "${INVERSE_CPUMAP} + (2^${CPUID})" | bc -l) INVERSE_CPUMAP=$(echo "${INVERSE_CPUMAP} + (2^${CPUID})" | bc -l)
done done
@ -171,11 +161,11 @@ function invert_cpumap
# Builds the complement representation of a CPULIST # Builds the complement representation of a CPULIST
# #
################################################################################ ################################################################################
function invert_cpulist function invert_cpulist {
{
local CPULIST=$1 local CPULIST=$1
local NR_CPUS=$2 local NR_CPUS=$2
local CPUMAP=$(cpulist_to_cpumap ${CPULIST} ${NR_CPUS}) local CPUMAP
CPUMAP=$(cpulist_to_cpumap ${CPULIST} ${NR_CPUS})
cpumap_to_cpulist $(invert_cpumap ${CPUMAP} ${NR_CPUS}) ${NR_CPUS} cpumap_to_cpulist $(invert_cpumap ${CPUMAP} ${NR_CPUS}) ${NR_CPUS}
return 0 return 0
} }
@ -188,17 +178,17 @@ function invert_cpulist
# 1 - item is not contained in list # 1 - item is not contained in list
# #
################################################################################ ################################################################################
function in_list() { function in_list {
local item="$1" local item="$1"
local list="$2" local list="$2"
# expand list format 0-3,8-11 to a full sequence {0..3} {8..11} # expand list format 0-3,8-11 to a full sequence {0..3} {8..11}
local exp_list=$(echo ${list} | \ local exp_list
exp_list=$(echo ${list} | \
sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g') sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g')
local e local e
for e in $(eval echo ${exp_list}) for e in $(eval echo ${exp_list}); do
do
[[ "$e" == "$item" ]] && return 0 [[ "$e" == "$item" ]] && return 0
done done
return 1 return 1
@ -212,7 +202,7 @@ function in_list() {
# 1 - no sublist items contained in list # 1 - no sublist items contained in list
# #
################################################################################ ################################################################################
function any_in_list() { function any_in_list {
local sublist="$1" local sublist="$1"
local list="$2" local list="$2"
local e local e
@ -222,8 +212,7 @@ function any_in_list() {
exp_list=$(echo ${list} | \ exp_list=$(echo ${list} | \
sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g') sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g')
declare -A a_list declare -A a_list
for e in $(eval echo ${exp_list}) for e in $(eval echo ${exp_list}); do
do
a_list[$e]=1 a_list[$e]=1
done done
@ -231,16 +220,13 @@ function any_in_list() {
exp_list=$(echo ${sublist} | \ exp_list=$(echo ${sublist} | \
sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g') sed -e 's#,# #g' -e 's#\([0-9]*\)-\([0-9]*\)#{\1\.\.\2}#g')
declare -A a_sublist declare -A a_sublist
for e in $(eval echo ${exp_list}) for e in $(eval echo ${exp_list}); do
do
a_sublist[$e]=1 a_sublist[$e]=1
done done
# Check if any element of sublist is in list # Check if any element of sublist is in list
for e in "${!a_sublist[@]}" for e in "${!a_sublist[@]}"; do
do if [[ "${a_list[$e]}" == 1 ]]; then
if [[ "${a_list[$e]}" == 1 ]]
then
return 0 # matches return 0 # matches
fi fi
done done
@ -250,7 +236,7 @@ function any_in_list() {
################################################################################ ################################################################################
# Return list of CPUs reserved for platform # Return list of CPUs reserved for platform
################################################################################ ################################################################################
function get_platform_cpu_list() { function get_platform_cpu_list {
## Define platform cpulist based on engineering a number of cores and ## Define platform cpulist based on engineering a number of cores and
## whether this is a combo or not, and include SMT siblings. ## whether this is a combo or not, and include SMT siblings.
if [[ $subfunction = *compute* ]]; then if [[ $subfunction = *compute* ]]; then
@ -266,16 +252,17 @@ function get_platform_cpu_list() {
local PLATFORM_START=0 local PLATFORM_START=0
local PLATFORM_CORES=1 local PLATFORM_CORES=1
if [ "$nodetype" = "controller" ]; then if [ "$nodetype" = "controller" ]; then
((PLATFORM_CORES+=1)) PLATFORM_CORES=$(($PLATFORM_CORES+1))
fi fi
local PLATFORM_CPULIST=$(topology_to_cpulist ${PLATFORM_SOCKET} ${PLATFORM_START} ${PLATFORM_CORES}) local PLATFORM_CPULIST
PLATFORM_CPULIST=$(topology_to_cpulist ${PLATFORM_SOCKET} ${PLATFORM_START} ${PLATFORM_CORES})
echo ${PLATFORM_CPULIST} echo ${PLATFORM_CPULIST}
} }
################################################################################ ################################################################################
# Return list of CPUs reserved for vswitch # Return list of CPUs reserved for vswitch
################################################################################ ################################################################################
function get_vswitch_cpu_list() { function get_vswitch_cpu_list {
## Define default avp cpulist based on engineered number of platform cores, ## Define default avp cpulist based on engineered number of platform cores,
## engineered avp cores, and include SMT siblings. ## engineered avp cores, and include SMT siblings.
if [[ $subfunction = *compute* ]]; then if [[ $subfunction = *compute* ]]; then
@ -287,12 +274,13 @@ function get_vswitch_cpu_list() {
fi fi
fi fi
local N_CORES_IN_PKG=$(cat /proc/cpuinfo 2>/dev/null | \ local N_CORES_IN_PKG
N_CORES_IN_PKG=$(cat /proc/cpuinfo 2>/dev/null | \
awk '/^cpu cores/ {n = $4} END { print (n>0) ? n : 1 }') awk '/^cpu cores/ {n = $4} END { print (n>0) ? n : 1 }')
# engineer platform cores # engineer platform cores
local PLATFORM_CORES=1 local PLATFORM_CORES=1
if [ "$nodetype" = "controller" ]; then if [ "$nodetype" = "controller" ]; then
((PLATFORM_CORES+=1)) PLATFORM_CORES=$(($PLATFORM_CORES+1))
fi fi
# engineer AVP cores # engineer AVP cores
@ -300,35 +288,33 @@ function get_vswitch_cpu_list() {
local AVP_START=${PLATFORM_CORES} local AVP_START=${PLATFORM_CORES}
local AVP_CORES=1 local AVP_CORES=1
if [ ${N_CORES_IN_PKG} -gt 4 ]; then if [ ${N_CORES_IN_PKG} -gt 4 ]; then
((AVP_CORES+=1)) AVP_CORES=$(($AVP_CORES+1))
fi fi
local AVP_CPULIST=$(topology_to_cpulist ${AVP_SOCKET} ${AVP_START} ${AVP_CORES}) local AVP_CPULIST
AVP_CPULIST=$(topology_to_cpulist ${AVP_SOCKET} ${AVP_START} ${AVP_CORES})
echo ${AVP_CPULIST} echo ${AVP_CPULIST}
} }
################################################################################ ################################################################################
# vswitch_expanded_cpu_list() - compute the vswitch cpu list, including it's siblings # vswitch_expanded_cpu_list() - compute the vswitch cpu list, including it's siblings
################################################################################ ################################################################################
function vswitch_expanded_cpu_list() { function vswitch_expanded_cpu_list {
list=$(get_vswitch_cpu_list) list=$(get_vswitch_cpu_list)
# Expand vswitch cpulist # Expand vswitch cpulist
vswitch_cpulist=$(expand_sequence ${list} " ") vswitch_cpulist=$(expand_sequence ${list} " ")
cpulist="" cpulist=""
for e in $vswitch_cpulist for e in $vswitch_cpulist; do
do # claim hyperthread siblings if SMT enabled
# claim hyperthread siblings if SMT enabled SIBLINGS_CPULIST=$(cat /sys/devices/system/cpu/cpu${e}/topology/thread_siblings_list 2>/dev/null)
SIBLINGS_CPULIST=$(cat /sys/devices/system/cpu/cpu${e}/topology/thread_siblings_list 2>/dev/null) siblings_cpulist=$(expand_sequence ${SIBLINGS_CPULIST} " ")
siblings_cpulist=$(expand_sequence ${SIBLINGS_CPULIST} " ") for s in $siblings_cpulist; do
for s in $siblings_cpulist in_list ${s} ${cpulist}
do if [ $? -eq 1 ]; then
in_list ${s} ${cpulist} cpulist=$(append_list ${s} ${cpulist})
if [ $? -eq 1 ] fi
then done
cpulist=$(append_list ${s} ${cpulist})
fi
done
done done
echo "$cpulist" echo "$cpulist"
@ -338,26 +324,23 @@ function vswitch_expanded_cpu_list() {
################################################################################ ################################################################################
# platform_expanded_cpu_list() - compute the platform cpu list, including it's siblings # platform_expanded_cpu_list() - compute the platform cpu list, including it's siblings
################################################################################ ################################################################################
function platform_expanded_cpu_list() { function platform_expanded_cpu_list {
list=$(get_platform_cpu_list) list=$(get_platform_cpu_list)
# Expand platform cpulist # Expand platform cpulist
platform_cpulist=$(expand_sequence ${list} " ") platform_cpulist=$(expand_sequence ${list} " ")
cpulist="" cpulist=""
for e in $platform_cpulist for e in $platform_cpulist; do
do # claim hyperthread siblings if SMT enabled
# claim hyperthread siblings if SMT enabled SIBLINGS_CPULIST=$(cat /sys/devices/system/cpu/cpu${e}/topology/thread_siblings_list 2>/dev/null)
SIBLINGS_CPULIST=$(cat /sys/devices/system/cpu/cpu${e}/topology/thread_siblings_list 2>/dev/null) siblings_cpulist=$(expand_sequence ${SIBLINGS_CPULIST} " ")
siblings_cpulist=$(expand_sequence ${SIBLINGS_CPULIST} " ") for s in $siblings_cpulist; do
for s in $siblings_cpulist in_list ${s} ${cpulist}
do if [ $? -eq 1 ]; then
in_list ${s} ${cpulist} cpulist=$(append_list ${s} ${cpulist})
if [ $? -eq 1 ] fi
then done
cpulist=$(append_list ${s} ${cpulist})
fi
done
done done
echo "$cpulist" echo "$cpulist"
@ -368,32 +351,33 @@ function platform_expanded_cpu_list() {
# Return list of CPUs based on cpu topology. Select the socket, starting core # Return list of CPUs based on cpu topology. Select the socket, starting core
# within the socket, select number of cores, and SMT siblings. # within the socket, select number of cores, and SMT siblings.
################################################################################ ################################################################################
function topology_to_cpulist() { function topology_to_cpulist {
local SOCKET=$1 local SOCKET=$1
local CORE_START=$2 local CORE_START=$2
local NUM_CORES=$3 local NUM_CORES=$3
local CPULIST=$(cat /proc/cpuinfo 2>/dev/null | perl -sne \ local CPULIST
CPULIST=$(cat /proc/cpuinfo 2>/dev/null | perl -sne \
'BEGIN { %T = {}; %H = {}; $L = $P = $C = $S = 0; } 'BEGIN { %T = {}; %H = {}; $L = $P = $C = $S = 0; }
{ {
if (/processor\s+:\s+(\d+)/) { $L = $1; } if (/processor\s+:\s+(\d+)/) { $L = $1; }
if (/physical id\s+:\s+(\d+)/) { $P = $1; } if (/physical id\s+:\s+(\d+)/) { $P = $1; }
if (/core id\s+:\s+(\d+)/) { if (/core id\s+:\s+(\d+)/) {
$C = $1; $C = $1;
$T{$P}{$C}++; $T{$P}{$C}++;
$S = $T{$P}{$C}; $S = $T{$P}{$C};
$H{$P}{$C}{$S} = $L; $H{$P}{$C}{$S} = $L;
} }
} }
END { END {
@cores = sort { $a <=> $b } keys $T{$socket}; @cores = sort { $a <=> $b } keys $T{$socket};
@sel_cores = splice @cores, $core_start, $num_cores; @sel_cores = splice @cores, $core_start, $num_cores;
@lcpus = (); @lcpus = ();
for $C (@sel_cores) { for $C (@sel_cores) {
for $S (sort {$a <=> $b } keys %{ $H{$socket}{$C} }) { for $S (sort {$a <=> $b } keys %{ $H{$socket}{$C} }) {
push @lcpus, $H{$socket}{$C}{$S}; push @lcpus, $H{$socket}{$C}{$S};
}
} }
} printf "%s\n", join(",", @lcpus);
printf "%s\n", join(",", @lcpus);
}' -- -socket=${SOCKET} -core_start=${CORE_START} -num_cores=${NUM_CORES}) }' -- -socket=${SOCKET} -core_start=${CORE_START} -num_cores=${NUM_CORES})
echo ${CPULIST} echo ${CPULIST}
} }

View File

@ -13,8 +13,7 @@ if [ ! -z ${1} ]; then
NR_CPUS_LIST=(${1//,/ }) NR_CPUS_LIST=(${1//,/ })
fi fi
function test_cpumap_to_cpulist() function test_cpumap_to_cpulist {
{
local NR_CPUS=$1 local NR_CPUS=$1
declare -A CPULISTS declare -A CPULISTS
@ -49,9 +48,9 @@ function test_cpumap_to_cpulist()
CPULISTS["11111111"]="0,4,8,12,16,20,24,28" CPULISTS["11111111"]="0,4,8,12,16,20,24,28"
CPULISTS["0F0F0F0F"]="0-3,8-11,16-19,24-27" CPULISTS["0F0F0F0F"]="0-3,8-11,16-19,24-27"
CPULISTS["F0F0F0F0"]="4-7,12-15,20-23,28-31" CPULISTS["F0F0F0F0"]="4-7,12-15,20-23,28-31"
CPULISTS["FFFFFFFF"]="0-31" CPULISTS["FFFFFFFF"]="0-31"
CPULISTS["FFFFFFFE"]="1-31" CPULISTS["FFFFFFFE"]="1-31"
CPULISTS["80000001"]="0,31" CPULISTS["80000001"]="0,31"
fi fi
if [ ${NR_CPUS} -ge 64 ]; then if [ ${NR_CPUS} -ge 64 ]; then
CPULISTS["0000000000000000"]="" CPULISTS["0000000000000000"]=""
@ -59,17 +58,17 @@ function test_cpumap_to_cpulist()
CPULISTS["0F0F0F0F0F0F0F0F"]="0-3,8-11,16-19,24-27,32-35,40-43,48-51,56-59" CPULISTS["0F0F0F0F0F0F0F0F"]="0-3,8-11,16-19,24-27,32-35,40-43,48-51,56-59"
CPULISTS["F0F0F0F0F0F0F0F0"]="4-7,12-15,20-23,28-31,36-39,44-47,52-55,60-63" CPULISTS["F0F0F0F0F0F0F0F0"]="4-7,12-15,20-23,28-31,36-39,44-47,52-55,60-63"
CPULISTS["FFFFFFFFFFFFFFFF"]="0-63" CPULISTS["FFFFFFFFFFFFFFFF"]="0-63"
CPULISTS["FFFFFFFFFFFFFFFE"]="1-63" CPULISTS["FFFFFFFFFFFFFFFE"]="1-63"
CPULISTS["8000000000000001"]="0,63" CPULISTS["8000000000000001"]="0,63"
fi fi
if [ ${NR_CPUS} -ge 128 ]; then if [ ${NR_CPUS} -ge 128 ]; then
CPULISTS["00000000000000000000000000000000"]="" CPULISTS["00000000000000000000000000000000"]=""
CPULISTS["11111111111111111111111111111111"]="0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124" CPULISTS["11111111111111111111111111111111"]="0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124"
CPULISTS["0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"]="0-3,8-11,16-19,24-27,32-35,40-43,48-51,56-59,64-67,72-75,80-83,88-91,96-99,104-107,112-115,120-123" CPULISTS["0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"]="0-3,8-11,16-19,24-27,32-35,40-43,48-51,56-59,64-67,72-75,80-83,88-91,96-99,104-107,112-115,120-123"
CPULISTS["F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0"]="4-7,12-15,20-23,28-31,36-39,44-47,52-55,60-63,68-71,76-79,84-87,92-95,100-103,108-111,116-119,124-127" CPULISTS["F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0"]="4-7,12-15,20-23,28-31,36-39,44-47,52-55,60-63,68-71,76-79,84-87,92-95,100-103,108-111,116-119,124-127"
CPULISTS["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]="0-127" CPULISTS["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]="0-127"
CPULISTS["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"]="1-127" CPULISTS["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"]="1-127"
CPULISTS["80000000000000000000000000000001"]="0,127" CPULISTS["80000000000000000000000000000001"]="0,127"
fi fi
for CPUMAP in ${!CPULISTS[@]}; do for CPUMAP in ${!CPULISTS[@]}; do
@ -85,8 +84,7 @@ function test_cpumap_to_cpulist()
printf "\n" printf "\n"
} }
function test_cpulist_to_cpumap() function test_cpulist_to_cpumap {
{
local NR_CPUS=$1 local NR_CPUS=$1
declare -A CPUMAPS declare -A CPUMAPS
@ -152,8 +150,7 @@ function test_cpulist_to_cpumap()
printf "\n" printf "\n"
} }
function test_invert_cpumap() function test_invert_cpumap {
{
local NR_CPUS=$1 local NR_CPUS=$1
declare -A INVERSES declare -A INVERSES
@ -194,27 +191,27 @@ function test_invert_cpumap()
INVERSES["F0F0F0F0"]="FFFFFFFFFFFFFFFFFFFFFFFF0F0F0F0F" INVERSES["F0F0F0F0"]="FFFFFFFFFFFFFFFFFFFFFFFF0F0F0F0F"
INVERSES["FFFFFFFF"]="FFFFFFFFFFFFFFFFFFFFFFFF00000000" INVERSES["FFFFFFFF"]="FFFFFFFFFFFFFFFFFFFFFFFF00000000"
INVERSES["FFFFFFFE"]="FFFFFFFFFFFFFFFFFFFFFFFF00000001" INVERSES["FFFFFFFE"]="FFFFFFFFFFFFFFFFFFFFFFFF00000001"
INVERSES["80000001"]="FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFE" INVERSES["80000001"]="FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFE"
fi fi
if [ ${NR_CPUS} -ge 64 ]; then if [ ${NR_CPUS} -ge 64 ]; then
INVERSES["1111111111111111"]="FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEE" INVERSES["1111111111111111"]="FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEE"
INVERSES["0F0F0F0F0F0F0F0F"]="FFFFFFFFFFFFFFFFF0F0F0F0F0F0F0F0" INVERSES["0F0F0F0F0F0F0F0F"]="FFFFFFFFFFFFFFFFF0F0F0F0F0F0F0F0"
INVERSES["F0F0F0F0F0F0F0F0"]="FFFFFFFFFFFFFFFF0F0F0F0F0F0F0F0F" INVERSES["F0F0F0F0F0F0F0F0"]="FFFFFFFFFFFFFFFF0F0F0F0F0F0F0F0F"
INVERSES["FFFFFFFFFFFFFFFF"]="FFFFFFFFFFFFFFFF0000000000000000" INVERSES["FFFFFFFFFFFFFFFF"]="FFFFFFFFFFFFFFFF0000000000000000"
INVERSES["FFFFFFFFFFFFFFFE"]="FFFFFFFFFFFFFFFF0000000000000001" INVERSES["FFFFFFFFFFFFFFFE"]="FFFFFFFFFFFFFFFF0000000000000001"
INVERSES["8000000000000001"]="FFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFE" INVERSES["8000000000000001"]="FFFFFFFFFFFFFFFF7FFFFFFFFFFFFFFE"
fi fi
if [ ${NR_CPUS} -ge 128 ]; then if [ ${NR_CPUS} -ge 128 ]; then
INVERSES["11111111111111111111111111111111"]="EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE" INVERSES["11111111111111111111111111111111"]="EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
INVERSES["0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"]="F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0" INVERSES["0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"]="F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0"
INVERSES["F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0"]="0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F" INVERSES["F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0"]="0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"
INVERSES["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]="00000000000000000000000000000000" INVERSES["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"]="00000000000000000000000000000000"
INVERSES["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"]="00000000000000000000000000000001" INVERSES["FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"]="00000000000000000000000000000001"
INVERSES["80000000000000000000000000000001"]="7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE" INVERSES["80000000000000000000000000000001"]="7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"
fi fi
for CPUMAP in ${!INVERSES[@]}; do for CPUMAP in ${!INVERSES[@]}; do
EXPECTED=${INVERSES[${CPUMAP}]} EXPECTED=${INVERSES[${CPUMAP}]}
if [ ${NR_CPUS} -lt 128 ]; then if [ ${NR_CPUS} -lt 128 ]; then
EXPECTED=$(echo ${EXPECTED} | cut --complement -c1-$((32-((${NR_CPUS}+3)/4)))) EXPECTED=$(echo ${EXPECTED} | cut --complement -c1-$((32-((${NR_CPUS}+3)/4))))
fi fi

View File

@ -10,8 +10,7 @@
# Log if debug is enabled via LOG_DEBUG # Log if debug is enabled via LOG_DEBUG
# #
################################################################################ ################################################################################
function log_debug function log_debug {
{
if [ ! -z "${LOG_DEBUG}" ]; then if [ ! -z "${LOG_DEBUG}" ]; then
logger -p debug -t "$0[${PPID}]" -s "$@" 2>&1 logger -p debug -t "$0[${PPID}]" -s "$@" 2>&1
fi fi
@ -21,8 +20,7 @@ function log_debug
# Log unconditionally to STDERR # Log unconditionally to STDERR
# #
################################################################################ ################################################################################
function log_error function log_error {
{
logger -p error -t "$0[${PPID}]" -s "$@" logger -p error -t "$0[${PPID}]" -s "$@"
} }
@ -30,8 +28,7 @@ function log_error
# Log unconditionally to STDOUT # Log unconditionally to STDOUT
# #
################################################################################ ################################################################################
function log function log {
{
logger -p info -t "$0[${PPID}]" -s "$@" 2>&1 logger -p info -t "$0[${PPID}]" -s "$@" 2>&1
} }
@ -39,8 +36,7 @@ function log
# Utility function to print the status of a command result # Utility function to print the status of a command result
# #
################################################################################ ################################################################################
function print_status() function print_status {
{
if [ "$1" -eq "0" ]; then if [ "$1" -eq "0" ]; then
echo "[ OK ]" echo "[ OK ]"
else else

View File

@ -12,16 +12,15 @@
printf "%6s %6s %6s %1c %2s %4s %6s %4s %-24s %2s %-16s %s\n" "PID" "TID" "PPID" "S" "PO" "NICE" "RTPRIO" "PR" "AFFINITY" "P" "COMM" "COMMAND" printf "%6s %6s %6s %1c %2s %4s %6s %4s %-24s %2s %-16s %s\n" "PID" "TID" "PPID" "S" "PO" "NICE" "RTPRIO" "PR" "AFFINITY" "P" "COMM" "COMMAND"
ps -eL -o pid=,lwp=,ppid=,state=,class=,nice=,rtprio=,priority=,psr=,comm=,command= | \ ps -eL -o pid=,lwp=,ppid=,state=,class=,nice=,rtprio=,priority=,psr=,comm=,command= | \
while read pid tid ppid state policy nice rtprio priority psr comm command while read pid tid ppid state policy nice rtprio priority psr comm command; do
do bitmask=$(taskset -p $tid 2>/dev/null)
bitmask=$(taskset -p $tid 2>/dev/null) aff=${bitmask##*: }
aff=${bitmask##*: } if [ -z "${aff}" ]; then
if [ -z "${aff}" ]; then aff="0x0"
aff="0x0" else
else aff="0x${aff}"
aff="0x${aff}" fi
fi printf "%6d %6d %6d %1c %2s %4s %6s %4d %-24s %2d %-16s %s\n" $pid $tid $ppid $state $policy $nice $rtprio $priority $aff $psr $comm "$command"
printf "%6d %6d %6d %1c %2s %4s %6s %4d %-24s %2d %-16s %s\n" $pid $tid $ppid $state $policy $nice $rtprio $priority $aff $psr $comm "$command" done
done
exit 0 exit 0

View File

@ -37,12 +37,11 @@ CPU_LIST=$2
NUMBER_OF_CPUS=$(getconf _NPROCESSORS_CONF 2>/dev/null) NUMBER_OF_CPUS=$(getconf _NPROCESSORS_CONF 2>/dev/null)
STATUS=1 STATUS=1
for CPU_NUM in $(expand_sequence "$CPU_LIST" " ") for CPU_NUM in $(expand_sequence "$CPU_LIST" " "); do
do
# Check that we are not setting PM QoS policy for non-existing CPU # Check that we are not setting PM QoS policy for non-existing CPU
if [ "$CPU_NUM" -lt "0" ] || [ "$CPU_NUM" -ge "$NUMBER_OF_CPUS" ]; then if [ "$CPU_NUM" -lt "0" ] || [ "$CPU_NUM" -ge "$NUMBER_OF_CPUS" ]; then
log_error "CPU number ${CPU_NUM} is invalid, available CPUs are 0-${NUMBER_OF_CPUS-1}" log_error "CPU number ${CPU_NUM} is invalid, available CPUs are 0-${NUMBER_OF_CPUS-1}"
exit 1 exit 1
fi fi
# Obtain CPU wakeup latencies for all C-states available starting from operating state to deepest sleep # Obtain CPU wakeup latencies for all C-states available starting from operating state to deepest sleep
@ -70,7 +69,7 @@ do
LATENCY=${LIMITS[${#LIMITS[@]}-1]} LATENCY=${LIMITS[${#LIMITS[@]}-1]}
fi fi
;; ;;
*) *)
log_error "Policy is invalid, can be either low or high" log_error "Policy is invalid, can be either low or high"
exit 1 exit 1
esac esac

View File

@ -20,69 +20,66 @@ TAG="TASKAFFINITY:"
TASK_AFFINING_INCOMPLETE="/etc/platform/.task_affining_incomplete" TASK_AFFINING_INCOMPLETE="/etc/platform/.task_affining_incomplete"
N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | \ N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | \
awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}') awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}')
FULLSET_CPUS="0-"$((N_CPUS-1)) FULLSET_CPUS="0-"$((N_CPUS-1))
FULLSET_MASK=$(cpulist_to_cpumap ${FULLSET_CPUS} ${N_CPUS}) FULLSET_MASK=$(cpulist_to_cpumap ${FULLSET_CPUS} ${N_CPUS})
PLATFORM_CPUS=$(get_platform_cpu_list) PLATFORM_CPUS=$(get_platform_cpu_list)
PLATFORM_CPULIST=$(get_platform_cpu_list| \ PLATFORM_CPULIST=$(get_platform_cpu_list| \
perl -pe 's/(\d+)-(\d+)/join(",",$1..$2)/eg'| \ perl -pe 's/(\d+)-(\d+)/join(",",$1..$2)/eg'| \
sed 's/,/ /g') sed 's/,/ /g')
VSWITCH_CPULIST=$(get_vswitch_cpu_list| \ VSWITCH_CPULIST=$(get_vswitch_cpu_list| \
perl -pe 's/(\d+)-(\d+)/join(",",$1..$2)/eg'| \ perl -pe 's/(\d+)-(\d+)/join(",",$1..$2)/eg'| \
sed 's/,/ /g') sed 's/,/ /g')
IDLE_MARK=95.0 IDLE_MARK=95.0
KERNEL=`uname -a` KERNEL=`uname -a`
################################################################################ ################################################################################
# Check if a given core is one of the platform cores # Check if a given core is one of the platform cores
################################################################################ ################################################################################
function is_platform_core() function is_platform_core {
{ local core=$1
local core=$1 for CPU in ${PLATFORM_CPULIST}; do
for CPU in ${PLATFORM_CPULIST}; do if [ $core -eq $CPU ]; then
if [ $core -eq $CPU ]; then return 1
return 1 fi
fi done
done return 0
return 0
} }
################################################################################ ################################################################################
# Check if a given core is one of the vswitch cores # Check if a given core is one of the vswitch cores
################################################################################ ################################################################################
function is_vswitch_core() function is_vswitch_core {
{ local core=$1
local core=$1 for CPU in ${VSWITCH_CPULIST}; do
for CPU in ${VSWITCH_CPULIST}; do if [ $core -eq $CPU ]; then
if [ $core -eq $CPU ]; then return 1
return 1 fi
fi done
done return 0
return 0
} }
################################################################################ ################################################################################
# An audit and corrective action following a swact # An audit and corrective action following a swact
################################################################################ ################################################################################
function audit_and_reaffine() function audit_and_reaffine {
{ local mask=$1
local mask=$1 local cmd_str=""
local cmd_str="" local tasklist
local tasklist
cmd_str="ps-sched.sh|awk '(\$9==\"$mask\") {print \$2}'" cmd_str="ps-sched.sh|awk '(\$9==\"$mask\") {print \$2}'"
tasklist=($(eval $cmd_str)) tasklist=($(eval $cmd_str))
# log_debug "cmd str = $cmd_str" # log_debug "cmd str = $cmd_str"
log_debug "${TAG} There are ${#tasklist[@]} tasks to reaffine." log_debug "${TAG} There are ${#tasklist[@]} tasks to reaffine."
for task in ${tasklist[@]}; do for task in ${tasklist[@]}; do
taskset -acp ${PLATFORM_CPUS} $task &> /dev/null taskset -acp ${PLATFORM_CPUS} $task &> /dev/null
rc=$? rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc" [[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
done done
tasklist=($(eval $cmd_str)) tasklist=($(eval $cmd_str))
[[ ${#tasklist[@]} -eq 0 ]] && return 0 || return 1 [[ ${#tasklist[@]} -eq 0 ]] && return 0 || return 1
} }
################################################################################ ################################################################################
@ -93,69 +90,67 @@ function audit_and_reaffine()
# The induced tasks migration should be done after all VMs have been restored # The induced tasks migration should be done after all VMs have been restored
# following a host reboot in AIO, hence the delay. # following a host reboot in AIO, hence the delay.
################################################################################ ################################################################################
function move_inactive_threads_to_platform_cores() function move_inactive_threads_to_platform_cores {
{ local tasklist
local tasklist local cmd_str=""
local cmd_str=""
# Compile a list of non-kernel & non-vswitch/VM related threads that are not # Compile a list of non-kernel & non-vswitch/VM related threads that are not
# on platform cores. # on platform cores.
# e.g. if the platform cpulist value is "0 8", the resulting command to be # e.g. if the platform cpulist value is "0 8", the resulting command to be
# evaluated should look like this: # evaluated should look like this:
# ps-sched.sh|grep -v vswitch|awk '($10!=0 && $10!=8 && $3!=2) {if(NR>1)print $2}' # ps-sched.sh|grep -v vswitch|awk '($10!=0 && $10!=8 && $3!=2) {if(NR>1)print $2}'
cmd_str="ps-sched.sh|grep -v vswitch|awk '(" cmd_str="ps-sched.sh|grep -v vswitch|awk '("
for cpu_num in ${PLATFORM_CPULIST}; do for cpu_num in ${PLATFORM_CPULIST}; do
cmd_str=$cmd_str"\$10!="${cpu_num}" && " cmd_str=$cmd_str"\$10!="${cpu_num}" && "
done done
cmd_str=$cmd_str"\$3!=2) {if(NR>1)print \$2}'" cmd_str=$cmd_str"\$3!=2) {if(NR>1)print \$2}'"
echo "selection string = $cmd_str" echo "selection string = $cmd_str"
tasklist=($(eval $cmd_str)) tasklist=($(eval $cmd_str))
log_debug "${TAG} There are ${#tasklist[@]} number of tasks to be moved." log_debug "${TAG} There are ${#tasklist[@]} number of tasks to be moved."
# These sleep tasks are stuck on the wrong core(s). They need to be woken up # These sleep tasks are stuck on the wrong core(s). They need to be woken up
# so they can be migrated to the right ones. Attaching and detaching strace # so they can be migrated to the right ones. Attaching and detaching strace
# momentarily to the task does the trick. # momentarily to the task does the trick.
for task in ${tasklist[@]}; do for task in ${tasklist[@]}; do
strace -p $task 2>/dev/null & strace -p $task 2>/dev/null &
pid=$! pid=$!
sleep 0.1 sleep 0.1
kill -SIGINT $pid kill -SIGINT $pid
done done
tasklist=($(eval $cmd_str)) tasklist=($(eval $cmd_str))
[[ ${#tasklist[@]} -eq 0 ]] && return 0 || return 1 [[ ${#tasklist[@]} -eq 0 ]] && return 0 || return 1
} }
################################################################################ ################################################################################
# The following function is called by affine-platform.sh to affine tasks to # The following function is called by affine-platform.sh to affine tasks to
# all available cores during initial startup and subsequent host reboots. # all available cores during initial startup and subsequent host reboots.
################################################################################ ################################################################################
function affine_tasks_to_all_cores() function affine_tasks_to_all_cores {
{ local pidlist
local pidlist local rc=0
local rc=0
if [[ "${KERNEL}" == *" RT "* ]]; then if [[ "${KERNEL}" == *" RT "* ]]; then
return 0 return 0
fi
log_debug "${TAG} Affining all tasks to CPU (${FULLSET_CPUS})"
pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
for pid in ${pidlist[@]}; do
ppid=$(ps -o ppid= -p $pid |tr -d '[:space:]')
if [ -z $ppid ] || [ $ppid -eq 2 ]; then
continue
fi fi
log_debug "Affining pid $pid, parent pid = $ppid"
taskset --all-tasks --pid --cpu-list ${FULLSET_CPUS} $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
done
# Write the cpu list to a temp file which will be read and removed when
# the tasks are reaffined back to platform cores later on.
echo ${FULLSET_CPUS} > ${TASK_AFFINING_INCOMPLETE}
return $rc log_debug "${TAG} Affining all tasks to CPU (${FULLSET_CPUS})"
pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
for pid in ${pidlist[@]}; do
ppid=$(ps -o ppid= -p $pid |tr -d '[:space:]')
if [ -z $ppid ] || [ $ppid -eq 2 ]; then
continue
fi
log_debug "Affining pid $pid, parent pid = $ppid"
taskset --all-tasks --pid --cpu-list ${FULLSET_CPUS} $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
done
# Write the cpu list to a temp file which will be read and removed when
# the tasks are reaffined back to platform cores later on.
echo ${FULLSET_CPUS} > ${TASK_AFFINING_INCOMPLETE}
return $rc
} }
################################################################################ ################################################################################
@ -170,75 +165,74 @@ function affine_tasks_to_all_cores()
# #
# Kernel, vswitch and VM related tasks are untouched. # Kernel, vswitch and VM related tasks are untouched.
################################################################################ ################################################################################
function affine_tasks_to_idle_cores() function affine_tasks_to_idle_cores {
{ local cpulist
local cpulist local cpuocc_list
local cpuocc_list local vswitch_pid
local vswitch_pid local pidlist
local pidlist local idle_cpulist
local idle_cpulist local platform_cpus
local platform_cpus local rc=0
local rc=0 local cpu=0
local cpu=0
if [ -f ${TASK_AFFINING_INCOMPLETE} ]; then if [ -f ${TASK_AFFINING_INCOMPLETE} ]; then
read cpulist < ${TASK_AFFINING_INCOMPLETE} read cpulist < ${TASK_AFFINING_INCOMPLETE}
log_debug "${TAG} Tasks have already been affined to CPU ($cpulist)." log_debug "${TAG} Tasks have already been affined to CPU ($cpulist)."
return 0 return 0
fi
if [[ "${KERNEL}" == *" RT "* ]]; then
return 0
fi
# Compile a list of cpus with idle percentage greater than 95% in the last
# 5 seconds.
cpuocc_list=($(sar -P ALL 1 5|grep Average|awk '{if(NR>2)print $8}'))
for idle_value in ${cpuocc_list[@]}; do
is_vswitch_core $cpu
if [ $? -eq 1 ]; then
((cpu++))
continue
fi fi
is_platform_core $cpu if [[ "${KERNEL}" == *" RT "* ]]; then
if [ $? -eq 1 ]; then return 0
# Platform core is added to the idle list by default fi
idle_cpulist=$idle_cpulist$cpu","
else # Compile a list of cpus with idle percentage greater than 95% in the last
# 5 seconds.
cpuocc_list=($(sar -P ALL 1 5|grep Average|awk '{if(NR>2)print $8}'))
for idle_value in ${cpuocc_list[@]}; do
is_vswitch_core $cpu
if [ $? -eq 1 ]; then
cpu=$(($cpu+1))
continue
fi
is_platform_core $cpu
if [ $? -eq 1 ]; then
# Platform core is added to the idle list by default
idle_cpulist=$idle_cpulist$cpu","
else
# Non platform core is added to the idle list if it is more than 95% idle # Non platform core is added to the idle list if it is more than 95% idle
[[ $(echo "$idle_value > ${IDLE_MARK}"|bc) -eq 1 ]] && idle_cpulist=$idle_cpulist$cpu"," [[ $(echo "$idle_value > ${IDLE_MARK}"|bc) -eq 1 ]] && idle_cpulist=$idle_cpulist$cpu","
fi fi
((cpu++)) cpu=$(($cpu+1))
done done
idle_cpulist=$(echo $idle_cpulist|sed 's/.$//') idle_cpulist=$(echo $idle_cpulist|sed 's/.$//')
platform_affinity_mask=$(cpulist_to_cpumap ${PLATFORM_CPUS} ${N_CPUS} \ platform_affinity_mask=$(cpulist_to_cpumap ${PLATFORM_CPUS} ${N_CPUS} \
|awk '{print tolower($0)}') |awk '{print tolower($0)}')
log_debug "${TAG} Affining all tasks to idle CPU ($idle_cpulist)"
vswitch_pid=$(pgrep vswitch) log_debug "${TAG} Affining all tasks to idle CPU ($idle_cpulist)"
pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
for pid in ${pidlist[@]}; do
ppid=$(ps -o ppid= -p $pid |tr -d '[:space:]')
if [ -z $ppid ] || [ $ppid -eq 2 ] || [ "$pid" = "$vswitch_pid" ]; then
continue
fi
pid_affinity_mask=$(taskset -p $pid | awk '{print $6}')
if [ "${pid_affinity_mask}" == "${platform_affinity_mask}" ]; then
# log_debug "Affining pid $pid to idle cores..."
taskset --all-tasks --pid --cpu-list $idle_cpulist $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
fi
done
# Save the cpu list to the temp file which will be read and removed when vswitch_pid=$(pgrep vswitch)
# tasks are reaffined to the platform cores later on. pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
echo $idle_cpulist > ${TASK_AFFINING_INCOMPLETE} for pid in ${pidlist[@]}; do
return $rc ppid=$(ps -o ppid= -p $pid |tr -d '[:space:]')
if [ -z $ppid ] || [ $ppid -eq 2 ] || [ "$pid" = "$vswitch_pid" ]; then
continue
fi
pid_affinity_mask=$(taskset -p $pid | awk '{print $6}')
if [ "${pid_affinity_mask}" == "${platform_affinity_mask}" ]; then
# log_debug "Affining pid $pid to idle cores..."
taskset --all-tasks --pid --cpu-list $idle_cpulist $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
fi
done
# Save the cpu list to the temp file which will be read and removed when
# tasks are reaffined to the platform cores later on.
echo $idle_cpulist > ${TASK_AFFINING_INCOMPLETE}
return $rc
} }
################################################################################ ################################################################################
@ -248,83 +242,81 @@ function affine_tasks_to_idle_cores()
# b) sm at the end of swact sequence # b) sm at the end of swact sequence
# to re-affine management tasks back to the platform cores. # to re-affine management tasks back to the platform cores.
################################################################################ ################################################################################
function affine_tasks_to_platform_cores() function affine_tasks_to_platform_cores {
{ local cpulist
local cpulist local pidlist
local pidlist local rc=0
local rc=0 local count=0
local count=0
if [ ! -f ${TASK_AFFINING_INCOMPLETE} ]; then if [ ! -f ${TASK_AFFINING_INCOMPLETE} ]; then
dbg_str="${TAG} Either tasks have never been affined to all/idle cores or" dbg_str="${TAG} Either tasks have never been affined to all/idle cores or"
dbg_str=$dbg_str" they have already been reaffined to platform cores." dbg_str=$dbg_str" they have already been reaffined to platform cores."
log_debug "$dbg_str" log_debug "$dbg_str"
return 0 return 0
fi
read cpulist < ${TASK_AFFINING_INCOMPLETE}
affinity_mask=$(cpulist_to_cpumap $cpulist ${N_CPUS}|awk '{print tolower($0)}')
log_debug "${TAG} Reaffining tasks to platform cores (${PLATFORM_CPUS})..."
pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
for pid in ${pidlist[@]}; do
# log_debug "Processing pid $pid..."
pid_affinity_mask=$(taskset -p $pid | awk '{print $6}')
# Only management tasks need to be reaffined. Kernel, vswitch and VM related
# tasks were not affined previously so they should have different affinity
# mask(s).
if [ "${pid_affinity_mask}" == "${affinity_mask}" ]; then
((count++))
# log_debug "Affining pid $pid to platform cores..."
taskset --all-tasks --pid --cpu-list ${PLATFORM_CPUS} $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
fi fi
done
# A workaround for lack of "end of swact" state read cpulist < ${TASK_AFFINING_INCOMPLETE}
fullmask=$(echo ${FULLSET_MASK} | awk '{print tolower($0)}') affinity_mask=$(cpulist_to_cpumap $cpulist ${N_CPUS}|awk '{print tolower($0)}')
if [ "${affinity_mask}" != "${fullmask}" ]; then
log_debug "${TAG} Schedule an audit and cleanup"
(sleep 60; audit_and_reaffine "0x"$affinity_mask) &
fi
rm -rf ${TASK_AFFINING_INCOMPLETE} log_debug "${TAG} Reaffining tasks to platform cores (${PLATFORM_CPUS})..."
log_debug "${TAG} $count tasks were reaffined to platform cores." pidlist=$(ps --ppid 2 -p 2 --deselect -o pid= | awk '{ print $1; }')
for pid in ${pidlist[@]}; do
# log_debug "Processing pid $pid..."
pid_affinity_mask=$(taskset -p $pid | awk '{print $6}')
# Only management tasks need to be reaffined. Kernel, vswitch and VM related
# tasks were not affined previously so they should have different affinity
# mask(s).
if [ "${pid_affinity_mask}" == "${affinity_mask}" ]; then
count=$(($count+1))
# log_debug "Affining pid $pid to platform cores..."
taskset --all-tasks --pid --cpu-list ${PLATFORM_CPUS} $pid &> /dev/null
rc=$?
[[ $rc -ne 0 ]] && log_error "Failed to set CPU affinity for pid $pid, rc=$rc"
fi
done
return $rc # A workaround for lack of "end of swact" state
fullmask=$(echo ${FULLSET_MASK} | awk '{print tolower($0)}')
if [ "${affinity_mask}" != "${fullmask}" ]; then
log_debug "${TAG} Schedule an audit and cleanup"
(sleep 60; audit_and_reaffine "0x"$affinity_mask) &
fi
rm -rf ${TASK_AFFINING_INCOMPLETE}
log_debug "${TAG} $count tasks were reaffined to platform cores."
return $rc
} }
################################################################################ ################################################################################
# The following function can be leveraged by cron tasks # The following function can be leveraged by cron tasks
################################################################################ ################################################################################
function get_most_idle_core() function get_most_idle_core {
{ local cpuocc_list
local cpuocc_list local cpu=0
local cpu=0 local most_idle_value=${IDLE_MARK}
local most_idle_value=${IDLE_MARK} local most_idle_cpu=0
local most_idle_cpu=0
if [[ "${KERNEL}" == *" RT "* ]]; then if [[ "${KERNEL}" == *" RT "* ]]; then
echo $cpu echo $cpu
return return
fi
cpuocc_list=($(sar -P ALL 1 5|grep Average|awk '{if(NR>2)print $8}'))
for idle_value in ${cpuocc_list[@]}; do
is_vswitch_core $cpu
if [ $? -eq 1 ]; then
((cpu++))
continue
fi fi
if [ $(echo "$idle_value > $most_idle_value"|bc) -eq 1 ]; then cpuocc_list=($(sar -P ALL 1 5|grep Average|awk '{if(NR>2)print $8}'))
most_idle_value=$idle_value
most_idle_cpu=$cpu
fi
((cpu++))
done
echo $most_idle_cpu for idle_value in ${cpuocc_list[@]}; do
is_vswitch_core $cpu
if [ $? -eq 1 ]; then
cpu=$(($cpu+1))
continue
fi
if [ $(echo "$idle_value > $most_idle_value"|bc) -eq 1 ]; then
most_idle_value=$idle_value
most_idle_cpu=$cpu
fi
cpu=$(($cpu+1))
done
echo $most_idle_cpu
} }

View File

@ -13,8 +13,7 @@ VOLATILE_CONFIG_FAIL="/var/run/.config_fail"
logfile=/var/log/patching.log logfile=/var/log/patching.log
if [ -f $VOLATILE_CONFIG_FAIL ] if [ -f $VOLATILE_CONFIG_FAIL ]; then
then
logger "$NAME: Node configuration has failed. Failing goenabled check." logger "$NAME: Node configuration has failed. Failing goenabled check."
exit 1 exit 1
fi fi

View File

@ -9,8 +9,7 @@
SERVICE=computeconfig.service SERVICE=computeconfig.service
while : while :; do
do
systemctl status $SERVICE |grep -q running systemctl status $SERVICE |grep -q running
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit 0 exit 0

View File

@ -25,8 +25,7 @@ case $nodetype in
;; ;;
esac esac
while : while :; do
do
systemctl status $SERVICE |grep -q running systemctl status $SERVICE |grep -q running
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit 0 exit 0

View File

@ -49,8 +49,7 @@ function log {
log "$NAME: performing sample migration from release $FROM_RELEASE to $TO_RELEASE with action $ACTION" log "$NAME: performing sample migration from release $FROM_RELEASE to $TO_RELEASE with action $ACTION"
if [ "$FROM_RELEASE" == "17.06" ] && [ "$ACTION" == "migrate" ] if [ "$FROM_RELEASE" == "17.06" ] && [ "$ACTION" == "migrate" ]; then
then
log "Sample migration from release $FROM_RELEASE" log "Sample migration from release $FROM_RELEASE"
fi fi

View File

@ -13,8 +13,7 @@ VOLATILE_CONFIG_FAIL="/var/run/.config_fail"
logfile=/var/log/patching.log logfile=/var/log/patching.log
if [ -f $VOLATILE_CONFIG_FAIL ] if [ -f $VOLATILE_CONFIG_FAIL ]; then
then
logger "$NAME: Node configuration has failed. Failing goenabled check." logger "$NAME: Node configuration has failed. Failing goenabled check."
exit 1 exit 1
fi fi

View File

@ -9,10 +9,10 @@
NOVAOPENRC="/etc/nova/openrc" NOVAOPENRC="/etc/nova/openrc"
if [ -e ${NOVAOPENRC} ] ; then if [ -e ${NOVAOPENRC} ] ; then
source ${NOVAOPENRC} &>/dev/null source ${NOVAOPENRC} &>/dev/null
else else
echo "Admin credentials not found" echo "Admin credentials not found"
exit exit
fi fi
# Delete all the servers # Delete all the servers

View File

@ -33,11 +33,9 @@ function do_escape {
echo $val_escaped echo $val_escaped
} }
if [ "$ACTION" == "migrate" ] if [ "$ACTION" == "migrate" ]; then
then
log "Creating new $NEW_PIPELINE_FILE file for release $TO_RELEASE" log "Creating new $NEW_PIPELINE_FILE file for release $TO_RELEASE"
if [ ! -d "$NEW_PIPELINE_DIR" ] if [ ! -d "$NEW_PIPELINE_DIR" ]; then
then
mkdir $NEW_PIPELINE_DIR mkdir $NEW_PIPELINE_DIR
fi fi
cp $PIPELINE_SOURCE_FILE $NEW_PIPELINE_FILE cp $PIPELINE_SOURCE_FILE $NEW_PIPELINE_FILE

View File

@ -15,7 +15,6 @@ source $DEST/stx-config/devstack/lib/stx-config
# check for service enabled # check for service enabled
if is_service_enabled sysinv-api sysinv-cond; then if is_service_enabled sysinv-api sysinv-cond; then
if [[ "$1" == "stack" && "$2" == "install" ]]; then if [[ "$1" == "stack" && "$2" == "install" ]]; then
# Perform installation of sysinv source # Perform installation of sysinv source
echo_summary "Installing cgts_client" echo_summary "Installing cgts_client"

View File

@ -31,29 +31,29 @@ if [ ! -d /var/run/network-scripts.puppet/ ] ; then
exit 1 exit 1
fi fi
function log_it() { function log_it {
logger "${0} ${1}" logger "${0} ${1}"
} }
function do_if_up() { function do_if_up {
local iface=$1 local iface=$1
log_it "Bringing $iface up" log_it "Bringing $iface up"
/sbin/ifup $iface /sbin/ifup $iface
} }
function do_if_down() { function do_if_down {
local iface=$1 local iface=$1
log_it "Bringing $iface down" log_it "Bringing $iface down"
/sbin/ifdown $iface /sbin/ifdown $iface
} }
function do_rm() { function do_rm {
local theFile=$1 local theFile=$1
log_it "Removing $theFile" log_it "Removing $theFile"
/bin/rm $theFile /bin/rm $theFile
} }
function do_cp() { function do_cp {
local srcFile=$1 local srcFile=$1
local dstFile=$2 local dstFile=$2
log_it "copying network cfg $srcFile to $dstFile" log_it "copying network cfg $srcFile to $dstFile"
@ -76,10 +76,11 @@ array_diff () {
echo ${result[@]} echo ${result[@]}
} }
function normalized_cfg_attr_value() { function normalized_cfg_attr_value {
local cfg=$1 local cfg=$1
local attr_name=$2 local attr_name=$2
local attr_value=$(cat $cfg | grep $attr_name= | awk -F "=" {'print $2'}) local attr_value
attr_value=$(cat $cfg | grep $attr_name= | awk -F "=" {'print $2'})
# #
@ -93,13 +94,13 @@ function normalized_cfg_attr_value() {
# line. # line.
# #
if [[ "${attr_name}" == "BONDING_OPTS" ]]; then if [[ "${attr_name}" == "BONDING_OPTS" ]]; then
echo "$(cat $cfg | grep $attr_name=)" echo "$(cat $cfg | grep $attr_name=)"
return $(true) return $(true)
fi fi
if [[ "${attr_name}" != "BOOTPROTO" ]]; then if [[ "${attr_name}" != "BOOTPROTO" ]]; then
echo "${attr_value}" echo "${attr_value}"
return $(true) return $(true)
fi fi
# #
# Special case BOOTPROTO attribute. # Special case BOOTPROTO attribute.
@ -124,13 +125,13 @@ function normalized_cfg_attr_value() {
# "dhcp". # "dhcp".
# #
if [[ "${attr_value}" == "none" ]]; then if [[ "${attr_value}" == "none" ]]; then
attr_value="none" attr_value="none"
fi fi
if [[ "${attr_value}" == "manual" ]]; then if [[ "${attr_value}" == "manual" ]]; then
attr_value="none" attr_value="none"
fi fi
if [[ "${attr_value}" == "" ]]; then if [[ "${attr_value}" == "" ]]; then
attr_value="none" attr_value="none"
fi fi
echo "${attr_value}" echo "${attr_value}"
return $(true) return $(true)
@ -139,7 +140,7 @@ function normalized_cfg_attr_value() {
# #
# returns $(true) if cfg file ( $1 ) has property propName ( $2 ) with a value of propValue ( $3 ) # returns $(true) if cfg file ( $1 ) has property propName ( $2 ) with a value of propValue ( $3 )
# #
function cfg_has_property_with_value() { function cfg_has_property_with_value {
local cfg=$1 local cfg=$1
local propname=$2 local propname=$2
local propvalue=$3 local propvalue=$3
@ -154,7 +155,7 @@ function cfg_has_property_with_value() {
# #
# returns $(true) if cfg file is configured as a slave # returns $(true) if cfg file is configured as a slave
# #
function is_slave() { function is_slave {
cfg_has_property_with_value $1 "SLAVE" "yes" cfg_has_property_with_value $1 "SLAVE" "yes"
return $? return $?
} }
@ -162,14 +163,14 @@ function is_slave() {
# #
# returns $(true) if cfg file is configured for DHCP # returns $(true) if cfg file is configured for DHCP
# #
function is_dhcp() { function is_dhcp {
cfg_has_property_with_value $1 "BOOTPROTO" "dhcp" cfg_has_property_with_value $1 "BOOTPROTO" "dhcp"
} }
# #
# returns $(true) if cfg file is configured as a VLAN interface # returns $(true) if cfg file is configured as a VLAN interface
# #
function is_vlan() { function is_vlan {
cfg_has_property_with_value $1 "VLAN" "yes" cfg_has_property_with_value $1 "VLAN" "yes"
return $? return $?
} }
@ -180,7 +181,7 @@ function is_vlan() {
# a vlan or a slave. This includes both regular ethernet interfaces and bonded # a vlan or a slave. This includes both regular ethernet interfaces and bonded
# interfaces. # interfaces.
# #
function is_ethernet() { function is_ethernet {
if ! is_vlan $1; then if ! is_vlan $1; then
if ! is_slave $1; then if ! is_slave $1; then
return $(true) return $(true)
@ -192,7 +193,7 @@ function is_ethernet() {
# #
# returns $(true) if cfg file represents an interface of the specified type. # returns $(true) if cfg file represents an interface of the specified type.
# #
function iftype_filter() { function iftype_filter {
local iftype=$1 local iftype=$1
return $(is_$iftype $2) return $(is_$iftype $2)
@ -202,22 +203,23 @@ function iftype_filter() {
# returns $(true) if ifcfg files have the same number of VFs # returns $(true) if ifcfg files have the same number of VFs
# #
# #
function is_eq_sriov_numvfs() { function is_eq_sriov_numvfs {
local cfg_1=$1 local cfg_1=$1
local cfg_2=$2 local cfg_2=$2
local sriov_numvfs_1
sriov_numvfs_1=$(grep -o 'echo *[1-9].*sriov_numvfs' $cfg_1 | awk {'print $2'})
local sriov_numvfs_2
sriov_numvfs_2=$(grep -o 'echo *[1-9].*sriov_numvfs' $cfg_2 | awk {'print $2'})
local sriov_numvfs_1=$(grep -o 'echo *[1-9].*sriov_numvfs' $cfg_1 | awk {'print $2'}) sriov_numvfs_1=${sriov_numvfs_1:-0}
local sriov_numvfs_2=$(grep -o 'echo *[1-9].*sriov_numvfs' $cfg_2 | awk {'print $2'}) sriov_numvfs_2=${sriov_numvfs_2:-0}
sriov_numvfs_1=${sriov_numvfs_1:-0} if [[ "${sriov_numvfs_1}" != "${sriov_numvfs_2}" ]]; then
sriov_numvfs_2=${sriov_numvfs_2:-0} log_it "$cfg_1 and $cfg_2 differ on attribute sriov_numvfs [${sriov_numvfs_1}:${sriov_numvfs_2}]"
return $(false)
fi
if [[ "${sriov_numvfs_1}" != "${sriov_numvfs_2}" ]]; then return $(true)
log_it "$cfg_1 and $cfg_2 differ on attribute sriov_numvfs [${sriov_numvfs_1}:${sriov_numvfs_2}]"
return $(false)
fi
return $(true)
} }
# #
@ -226,51 +228,52 @@ function is_eq_sriov_numvfs() {
# Warning: Only compares against cfg file attributes: # Warning: Only compares against cfg file attributes:
# BOOTPROTO DEVICE IPADDR NETMASK GATEWAY MTU BONDING_OPTS SRIOV_NUMVFS # BOOTPROTO DEVICE IPADDR NETMASK GATEWAY MTU BONDING_OPTS SRIOV_NUMVFS
# #
function is_eq_ifcfg() { function is_eq_ifcfg {
local cfg_1=$1 local cfg_1=$1
local cfg_2=$2 local cfg_2=$2
for attr in BOOTPROTO DEVICE IPADDR NETMASK GATEWAY MTU BONDING_OPTS for attr in BOOTPROTO DEVICE IPADDR NETMASK GATEWAY MTU BONDING_OPTS; do
do local attr_value1
local attr_value1=$(normalized_cfg_attr_value $cfg_1 $attr) attr_value1=$(normalized_cfg_attr_value $cfg_1 $attr)
local attr_value2=$(normalized_cfg_attr_value $cfg_2 $attr) local attr_value2
if [[ "${attr_value1}" != "${attr_value2}" ]]; then attr_value2=$(normalized_cfg_attr_value $cfg_2 $attr)
log_it "$cfg_1 and $cfg_2 differ on attribute $attr" if [[ "${attr_value1}" != "${attr_value2}" ]]; then
return $(false) log_it "$cfg_1 and $cfg_2 differ on attribute $attr"
fi return $(false)
done fi
done
is_eq_sriov_numvfs $1 $2 is_eq_sriov_numvfs $1 $2
return $? return $?
} }
# Synchronize with sysinv-agent audit (ifup/down to query link speed). # Synchronize with sysinv-agent audit (ifup/down to query link speed).
function sysinv_agent_lock() { function sysinv_agent_lock {
case $1 in case $1 in
$ACQUIRE_LOCK) $ACQUIRE_LOCK)
local lock_file="/var/run/apply_network_config.lock" local lock_file="/var/run/apply_network_config.lock"
# Lock file should be the same as defined in sysinv agent code # Lock file should be the same as defined in sysinv agent code
local lock_timeout=5 local lock_timeout=5
local max=15 local max=15
local n=1 local n=1
LOCK_FD=0 LOCK_FD=0
exec {LOCK_FD}>$lock_file exec {LOCK_FD}>$lock_file
while [[ $n -le $max ]] while [[ $n -le $max ]]; do
do
flock -w $lock_timeout $LOCK_FD && break flock -w $lock_timeout $LOCK_FD && break
log_it "Failed to get lock($LOCK_FD) after $lock_timeout seconds ($n/$max), will retry" log_it "Failed to get lock($LOCK_FD) after $lock_timeout seconds ($n/$max), will retry"
sleep 1 sleep 1
((n++)) n=$(($n+1))
done done
if [[ $n -gt $max ]]; then if [[ $n -gt $max ]]; then
log_it "Failed to acquire lock($LOCK_FD) even after $max retries" log_it "Failed to acquire lock($LOCK_FD) even after $max retries"
exit 1 exit 1
fi fi
;; ;;
$RELEASE_LOCK) $RELEASE_LOCK)
[[ $LOCK_FD -gt 0 ]] && flock -u $LOCK_FD [[ $LOCK_FD -gt 0 ]] && flock -u $LOCK_FD
;; ;;
esac esac
} }
# First thing to do is deal with the case of there being no routes left on an interface. # First thing to do is deal with the case of there being no routes left on an interface.
@ -310,7 +313,7 @@ for rt_path in $(find /var/run/network-scripts.puppet/ -name "${RTNAME_INCLUDE}"
fi fi
fi fi
if [ -s /var/run/network-scripts.puppet/$rt ] ; then if [ -s /var/run/network-scripts.puppet/$rt ] ; then
# Whether this is a new routes file or there are changes, ultimately we will need # Whether this is a new routes file or there are changes, ultimately we will need
# to ifup the file to add any potentially new routes. # to ifup the file to add any potentially new routes.
@ -352,16 +355,16 @@ for cfg_path in $(find /var/run/network-scripts.puppet/ -name "${IFNAME_INCLUDE}
is_dhcp /etc/sysconfig/network-scripts/$cfg ; then is_dhcp /etc/sysconfig/network-scripts/$cfg ; then
# if dhcp type iface, then too many possible attr's to compare against, so # if dhcp type iface, then too many possible attr's to compare against, so
# just add cfg to the upDown list because we know (from above) cfg file is changed # just add cfg to the upDown list because we know (from above) cfg file is changed
log_it "dhcp detected for $cfg - adding to upDown list" log_it "dhcp detected for $cfg - adding to upDown list"
upDown+=($cfg) upDown+=($cfg)
else else
# not in dhcp situation so check if any significant # not in dhcp situation so check if any significant
# cfg attributes have changed to warrant an iface restart # cfg attributes have changed to warrant an iface restart
is_eq_ifcfg /var/run/network-scripts.puppet/$cfg \ is_eq_ifcfg /var/run/network-scripts.puppet/$cfg \
/etc/sysconfig/network-scripts/$cfg /etc/sysconfig/network-scripts/$cfg
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
log_it "$cfg changed - adding to upDown list" log_it "$cfg changed - adding to upDown list"
upDown+=($cfg) upDown+=($cfg)
fi fi
fi fi
fi fi

View File

@ -58,16 +58,15 @@ cp /etc/puppet/hieradata/${PERSONALITY}.yaml ${PUPPET_TMP}/hieradata/personality
# the grub. At this time, copying the host file failed due to a timing issue that # the grub. At this time, copying the host file failed due to a timing issue that
# has not yet been fully understood. Subsequent retries worked. # has not yet been fully understood. Subsequent retries worked.
if [ "${PERSONALITY}" = "compute" ]; then if [ "${PERSONALITY}" = "compute" ]; then
n=0 n=0
until [ $n -ge 3 ] until [ $n -ge 3 ]; do
do cp -f ${HIERADATA}/${HOST}.yaml ${PUPPET_TMP}/hieradata/host.yaml && break
cp -f ${HIERADATA}/${HOST}.yaml ${PUPPET_TMP}/hieradata/host.yaml && break n=$(($n+1))
n=$[$n+1] logger -t $0 "Failed to copy /etc/puppet/hieradata/${HOST}.yaml"
logger -t $0 "Failed to copy /etc/puppet/hieradata/${HOST}.yaml" sleep 15
sleep 15 done
done
else else
cp -f ${HIERADATA}/${HOST}.yaml ${PUPPET_TMP}/hieradata/host.yaml cp -f ${HIERADATA}/${HOST}.yaml ${PUPPET_TMP}/hieradata/host.yaml
fi fi
cp -f ${HIERADATA}/system.yaml \ cp -f ${HIERADATA}/system.yaml \
${HIERADATA}/secure_system.yaml \ ${HIERADATA}/secure_system.yaml \
@ -81,8 +80,7 @@ fi
# Exit function to save logs from initial apply # Exit function to save logs from initial apply
function finish() function finish {
{
local SAVEDLOGS=/var/log/puppet/first_apply.tgz local SAVEDLOGS=/var/log/puppet/first_apply.tgz
if [ ! -f ${SAVEDLOGS} ]; then if [ ! -f ${SAVEDLOGS} ]; then
# Save the logs # Save the logs
@ -102,15 +100,13 @@ echo "Applying puppet ${MANIFEST} manifest..."
flock /var/run/puppet.lock \ flock /var/run/puppet.lock \
puppet apply --debug --trace --modulepath ${PUPPET_MODULES_PATH} ${PUPPET_MANIFEST} \ puppet apply --debug --trace --modulepath ${PUPPET_MODULES_PATH} ${PUPPET_MANIFEST} \
< /dev/null 2>&1 | awk ' { system("date -u +%FT%T.%3N | tr \"\n\" \" \""); print $0; fflush(); } ' > ${LOGFILE} < /dev/null 2>&1 | awk ' { system("date -u +%FT%T.%3N | tr \"\n\" \" \""); print $0; fflush(); } ' > ${LOGFILE}
if [ $? -ne 0 ] if [ $? -ne 0 ]; then
then
echo "[FAILED]" echo "[FAILED]"
echo "See ${LOGFILE} for details" echo "See ${LOGFILE} for details"
exit 1 exit 1
else else
grep -qE '^(.......)?Warning|^....-..-..T..:..:..([.]...)?(.......)?.Warning|^(.......)?Error|^....-..-..T..:..:..([.]...)?(.......)?.Error' ${LOGFILE} grep -qE '^(.......)?Warning|^....-..-..T..:..:..([.]...)?(.......)?.Warning|^(.......)?Error|^....-..-..T..:..:..([.]...)?(.......)?.Error' ${LOGFILE}
if [ $? -eq 0 ] if [ $? -eq 0 ]; then
then
echo "[WARNING]" echo "[WARNING]"
echo "Warnings found. See ${LOGFILE} for details" echo "Warnings found. See ${LOGFILE} for details"
exit 1 exit 1

View File

@ -2,7 +2,6 @@
[ -z "$PS1" -o -n "$KUBECONFIG" ] && return [ -z "$PS1" -o -n "$KUBECONFIG" ] && return
# Set up the location of the k8s config file for anyone who can read it. # Set up the location of the k8s config file for anyone who can read it.
if [ -r /etc/kubernetes/admin.conf ] if [ -r /etc/kubernetes/admin.conf ]; then
then
export KUBECONFIG=/etc/kubernetes/admin.conf export KUBECONFIG=/etc/kubernetes/admin.conf
fi fi

View File

@ -13,8 +13,7 @@ VOLATILE_CONFIG_FAIL="/var/run/.config_fail"
logfile=/var/log/patching.log logfile=/var/log/patching.log
if [ -f $VOLATILE_CONFIG_FAIL ] if [ -f $VOLATILE_CONFIG_FAIL ]; then
then
logger "$NAME: Node configuration has failed. Failing goenabled check." logger "$NAME: Node configuration has failed. Failing goenabled check."
exit 1 exit 1
fi fi

View File

@ -13,24 +13,21 @@ SYSINV_READY_FLAG=/var/run/.sysinv_ready
logfile=/var/log/platform.log logfile=/var/log/platform.log
function LOG() function LOG {
{
logger "$NAME: $*" logger "$NAME: $*"
echo "`date "+%FT%T"`: $NAME: $*" >> $logfile echo "`date "+%FT%T"`: $NAME: $*" >> $logfile
} }
count=0 count=0
while [ $count -le 45 ] while [ $count -le 45 ]; do
do if [ -f $SYSINV_READY_FLAG ]; then
if [ -f $SYSINV_READY_FLAG ]
then
LOG "SysInv is ready. Passing goenabled check." LOG "SysInv is ready. Passing goenabled check."
echo "SysInv goenabled iterations PASS $count" echo "SysInv goenabled iterations PASS $count"
LOG "SysInv goenabled iterations PASS $count" LOG "SysInv goenabled iterations PASS $count"
exit 0 exit 0
fi fi
sleep 1 sleep 1
(( count++ )) count=$(($count+1))
done done
echo "SysInv goenabled iterations FAIL $count" echo "SysInv goenabled iterations FAIL $count"

View File

@ -33,7 +33,8 @@ wlog() {
return return
fi fi
local head="$(date "+%Y-%m-%d %H:%M:%S.%3N") $0 $1" local head
head="$(date "+%Y-%m-%d %H:%M:%S.%3N") $0 $1"
echo "$head $2: $3" >> $LOG_FILE echo "$head $2: $3" >> $LOG_FILE
if [ "$4" = "print_trace" ]; then if [ "$4" = "print_trace" ]; then
# Print out the stack trace # Print out the stack trace
@ -50,8 +51,7 @@ device_path=$1 && shift
part_numbers=( `parted -s $device_path print | awk '$1 == "Number" {i=1; next}; i {print $1}'` ) part_numbers=( `parted -s $device_path print | awk '$1 == "Number" {i=1; next}; i {print $1}'` )
sector_size=$(blockdev --getss $device_path) sector_size=$(blockdev --getss $device_path)
for part_number in "${part_numbers[@]}"; for part_number in "${part_numbers[@]}"; do
do
sgdisk_part_info=$(sgdisk -i $part_number $device_path) sgdisk_part_info=$(sgdisk -i $part_number $device_path)
# Parse the output and put it in the right return format. # Parse the output and put it in the right return format.

14
tox.ini
View File

@ -21,12 +21,14 @@ commands =
-not -name \*~ \ -not -name \*~ \
-not -name \*.md \ -not -name \*.md \
-name \*.sh \ -name \*.sh \
-print0 | xargs -0 bashate -v" -print0 | xargs -0 bashate -v -e E* \
bash -c "find {toxinidir} \ -i E006,E010"
\( -name middleware/io-monitor/recipes-common/io-monitor/io-monitor/io_monitor/test-tools/yaml/* -prune \) \
-o \( -name .tox -prune \) \ # bash -c "find {toxinidir} \
-o -type f -name '*.yaml' \ # \( -name .tox -prune \) \
-print0 | xargs -0 yamllint" # -o -type f -name '*.yaml' \
# -print0 | xargs -0 yamllint -f parsable \
# -c {toxinidir}/.yamllint"
[testenv:pep8] [testenv:pep8]
usedevelop = False usedevelop = False