From: Alexandru Avadanii Date: Tue, 30 Jan 2018 00:25:06 +0000 (+0100) Subject: [patch] Group APT calls for salt formula install X-Git-Tag: opnfv-6.0.0~125^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F51333%2F4;p=fuel.git [patch] Group APT calls for salt formula install When installing salt-formula-* on cfg01, we used to call APT for each package. Instead, handle them all at once. While at it, stop using colored output on terminals that don't support it (e.g. 'vt220' used by OPNFV Jenkins). Change-Id: Ib8f2cee9638c43cdf648487bf05b07cd49802d3e Signed-off-by: Alexandru Avadanii --- diff --git a/mcp/patches/scripts/0002-salt-master-setup-Group-APT-install-formulas.patch b/mcp/patches/scripts/0002-salt-master-setup-Group-APT-install-formulas.patch new file mode 100644 index 000000000..71632681e --- /dev/null +++ b/mcp/patches/scripts/0002-salt-master-setup-Group-APT-install-formulas.patch @@ -0,0 +1,68 @@ +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +: Copyright (c) 2017 Mirantis Inc., Enea AB and others. +: +: All rights reserved. This program and the accompanying materials +: are made available under the terms of the Apache License, Version 2.0 +: which accompanies this distribution, and is available at +: http://www.apache.org/licenses/LICENSE-2.0 +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +From: Alexandru Avadanii +Date: Tue, 30 Jan 2018 01:23:54 +0100 +Subject: [PATCH] salt-master-setup: Group APT install formulas + +Instead of calling `apt install` for each salt formula package that +we miss, construct a list and install them all at once. + +While at it, disable colored output on terminals that don't support +it, like vt220 (used in OPNFV CI). + +Signed-off-by: Alexandru Avadanii +--- + salt-master-init.sh | 6 ++++++ + salt-master-setup.sh | 12 +++++++----- + 2 files changed, 13 insertions(+), 5 deletions(-) + +diff --git a/salt-master-init.sh b/salt-master-init.sh +index 343324c..48a05b9 100755 +--- a/salt-master-init.sh ++++ b/salt-master-init.sh +@@ -24,6 +24,12 @@ options() { + export $(find $path -maxdepth 1 -name '*.env' 2> /dev/null | xargs --no-run-if-empty cat ) > /dev/null + done; + ++ # If terminal does not support color output, stop using it ++ if ! tput setaf 1 && tput sgr0; then ++ SALT_OPTS="${SALT_OPTS/--force-color/--no-color}" ++ return 0 ++ fi ++ + export MAGENTA='\033[0;95m' + export YELLOW='\033[1;33m' + export BLUE='\033[0;35m' +diff --git a/salt-master-setup.sh b/salt-master-setup.sh +index 0dd3036..a0c6311 100755 +--- a/salt-master-setup.sh ++++ b/salt-master-setup.sh +@@ -347,15 +347,17 @@ install_salt_formula_pkg() + # Set essentials if FORMULAS_SALT_MASTER is not defined at all + [ -z ${FORMULAS_SALT_MASTER+x} ] && declare -a FORMULAS_SALT_MASTER=("linux" "reclass" "salt" "memcached") + for formula_service in "${FORMULAS_SALT_MASTER[@]}"; do +- echo -e "\nConfiguring salt formula ${formula_service} ...\n" ++ echo -e "Configuring salt formula ${formula_service} ..." + [ ! -d "${FORMULAS_PATH}/env/${formula_service}" ] && \ +- if ! $SUDO apt-get install -y salt-formula-${formula_service}; then +- echo -e "\nInstall salt-formula-${formula_service} failed.\n" +- exit 1 +- fi ++ _FORMULAS_SALT_MASTER="${_FORMULAS_SALT_MASTER} salt-formula-${formula_service}" ++ # Create links first, install pkgs later + [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && \ + ln -sf ${FORMULAS_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service} + done ++ if ! $SUDO apt-get install -qqq -y ${_FORMULAS_SALT_MASTER}; then ++ echo -e "\nInstall ${_FORMULAS_SALT_MASTER} failed.\n" ++ exit 1 ++ fi + ;; + rhel) + # TODO diff --git a/mcp/scripts/salt.sh b/mcp/scripts/salt.sh index 547137afe..03218e27f 100755 --- a/mcp/scripts/salt.sh +++ b/mcp/scripts/salt.sh @@ -47,6 +47,7 @@ fi ssh ${SSH_OPTS} "${SSH_SALT}" bash -s -e << SALT_INSTALL_END sudo -i set -e + export TERM=${TERM} export CI_DEBUG=${CI_DEBUG}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x echo -n 'Checking out cloud-init has finished running ...' @@ -71,7 +72,7 @@ ssh ${SSH_OPTS} "${SSH_SALT}" bash -s -e << SALT_INSTALL_END cd /srv/salt/scripts export DEBIAN_FRONTEND=noninteractive echo 'Dpkg::Use-Pty "0";' > /etc/apt/apt.conf.d/90silence-dpkg - OLD_DOMAIN=\$(grep -Pzo "id: cfg01\.\K(\S*)" /etc/salt/minion.d/minion.conf) || true + OLD_DOMAIN=\$(grep -sPzo "id: cfg01\.\K(\S*)" /etc/salt/minion.d/minion.conf) || true BOOTSTRAP_SALTSTACK_OPTS=" -r -dX stable 2016.11 " \ MASTER_HOSTNAME=cfg01.${CLUSTER_DOMAIN} DISTRIB_REVISION=stable \ EXTRA_FORMULAS="nfs" \ @@ -87,7 +88,7 @@ ssh ${SSH_OPTS} "${SSH_SALT}" bash -s -e << SALT_INSTALL_END # In case scenario changed (and implicitly domain name), re-register minions if [ -n "\${OLD_DOMAIN}" ] && [ "\${OLD_DOMAIN}" != "${CLUSTER_DOMAIN}" ]; then - salt "*.\${OLD_DOMAIN}" cmd.run "grep \${OLD_DOMAIN} -Rl /etc/salt | \ + salt "*.\${OLD_DOMAIN}" cmd.run "grep \${OLD_DOMAIN} -sRl /etc/salt | \ xargs --no-run-if-empty sed -i 's/\${OLD_DOMAIN}/${CLUSTER_DOMAIN}/g'; \ service salt-minion restart" || true salt-key -yd "*.\${OLD_DOMAIN}"