| #!/bin/bash |
| |
| cd $(dirname $(readlink -f $0))/.. |
| |
| if [[ $# -ne 1 ]]; then |
| echo "usage: $(basename $0) <boardname>" >&2 |
| exit 1 |
| fi |
| |
| # We set BOARD to be the name of the non-freon board we're |
| # working to swap, and FREON to the name of the corresponding |
| # freon board. |
| # |
| # For the sake of users who seem to have trouble remembering |
| # what to say, we allow either the freon or the non-freon |
| # board to be named. |
| |
| BOARD="$1" |
| case "${BOARD}" in |
| *?freon) FREON=${BOARD} BOARD=${FREON%?freon} ;; |
| *_*) FREON=${BOARD}-freon ;; |
| *) FREON=${BOARD}_freon ;; |
| esac |
| |
| # The default platform name is derived from a string in the |
| # firmware, not the board name. wmatrix reports results based |
| # on the platform name, so we can't change pre-existing platform |
| # names, and the freon names have to be different. |
| # |
| # So, calculate the non-freon platform name based on some static |
| # rules, and use the (freon) board name as the platform for freon |
| # boards. |
| |
| case "${BOARD}" in |
| x86-*) PLATFORM=${BOARD#x86-} ;; |
| daisy) PLATFORM=snow ;; |
| daisy_spring) PLATFORM=spring ;; |
| daisy_skate) PLATFORM=skate ;; |
| parrot_ivb) PLATFORM=parrot_2 ;; |
| falco_li) PLATFORM=falco ;; |
| *) PLATFORM=$BOARD ;; |
| esac |
| |
| # BROKEN is set to the list of all broken freon boards. |
| BROKEN=( $(site_utils/dut_status.py -n -b $FREON) ) |
| if [[ ${#BROKEN[@]} -eq 0 ]]; then |
| echo "No broken DUTs for $FREON" >&2 |
| exit 0 |
| fi |
| echo "Found ${#BROKEN[@]} broken $FREON DUTs" >&2 |
| |
| |
| # Extract a list of non-freon DUTs that can be used as spares. |
| # Requirements for inclusion; |
| # - Correct board:label |
| # - In pool:suites |
| # - Not in any other pool |
| # - Working (according to dut_status) |
| # |
| # The list of working DUTs is limited to the number of |
| # broken DUTs to be replaced. |
| |
| # HOST_FILTER is an awk program to print host names from the output |
| # of the `atest` command. It removes the atest command header, and |
| # also filters hosts with more than one pool: label. |
| |
| HOST_FILTER=' |
| NR == 1 || /pool:.*pool:/ {next} |
| {print $1} |
| ' |
| ELIGIBLE=( $(cli/atest host list -b board:$BOARD,pool:suites | |
| awk "${HOST_FILTER}") ) |
| WORKING=( $(site_utils/dut_status.py -w "${ELIGIBLE[@]}" | |
| tail -${#BROKEN[@]}) ) |
| if [[ ${#WORKING[@]} -eq 0 ]]; then |
| echo "No working $BOARD spares for $FREON" >&2 |
| exit 1 |
| fi |
| echo "Found ${#WORKING[@]} working $BOARD DUTs" >&2 |
| |
| |
| # At thos point BROKEN is a list of broken freon DUTs that need to |
| # be replaced, and WORKING is a list of working non-freon DUTs that |
| # will replace them. Check for and report any shortfall. |
| # |
| # If there's a shortfall, remove excess DUTs from the BROKEN list, |
| # so that the size of BROKEN and WORKING will be the same. |
| |
| if [[ ${#WORKING[@]} -lt ${#BROKEN[@]} ]]; then |
| echo "$BOARD is short by $(( ${#BROKEN[@]} - ${#WORKING[@]} )) spares" >&2 |
| echo "Not all broken DUTs will be swapped" >&2 |
| while [[ ${#WORKING[@]} -lt ${#BROKEN[@]} ]]; do |
| unset BROKEN[$(( ${#BROKEN[@]} - 1 ))] |
| done |
| fi |
| |
| |
| # We're good to go! Remove the freon labels from the broken freon |
| # DUTs, and replace them with non-freon labels. Do the reverse for |
| # the working non-freon DUTs. |
| # |
| # Ordering of the `atest` commands matters here, because you have |
| # to remove the old platform label before adding the new one. |
| |
| BROKEN_M=$(echo "${BROKEN[@]}" | sed 's/ /,/g') |
| WORKING_M=$(echo "${WORKING[@]}" | sed 's/ /,/g') |
| |
| cli/atest label remove -m $BROKEN_M pool:bvt board:$FREON $FREON |
| cli/atest label add -m $BROKEN_M pool:suites board:$BOARD $PLATFORM |
| cli/atest label remove -m $WORKING_M pool:suites board:$BOARD $PLATFORM |
| cli/atest label add -m $WORKING_M pool:bvt board:$FREON $FREON |