Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 01_install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ early_deploy_validation true
if [ -z "${METAL3_DEV_ENV:-}" ]; then
export REPO_PATH=${WORKING_DIR}
sync_repo_and_patch metal3-dev-env https://github.com/metal3-io/metal3-dev-env.git
pushd ${METAL3_DEV_ENV_PATH}
pushd "${METAL3_DEV_ENV_PATH}"
# Pin to a specific metal3-dev-env commit to ensure we catch breaking
# changes before they're used by everyone and CI.
# TODO -- come up with a plan for continuously updating this
Expand Down Expand Up @@ -101,7 +101,7 @@ case $DISTRO in
if sudo subscription-manager identity > /dev/null 2>&1; then
# NOTE(elfosardo): a valid RHEL subscription is needed to be able to
# enable the CRB repository
sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
sudo subscription-manager repos --enable "codeready-builder-for-rhel-9-$(arch)-rpms"
fi
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
fi
Expand All @@ -118,7 +118,7 @@ esac
# for CentOS/RHEL so we have to install from pip. We do not want to
# overwrite an existing installation of the golang version, though,
# so check if we have a yq before installing.
if ! which yq 2>&1 >/dev/null; then
if ! which yq >/dev/null 2>&1; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you do

Suggested change
if ! which yq >/dev/null 2>&1; then
if ! which yq &>/dev/null; then

then nobody ever has to think about whether this is the right order or not (it is now) again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First form is more visible and and is everywhere in the repo, let's leave it like this.

sudo python -m pip install 'yq>=3,<4'
else
echo "Using yq from $(which yq)"
Expand Down Expand Up @@ -164,7 +164,7 @@ sudo python -m pip install netaddr lxml

sudo python -m pip install ansible=="${ANSIBLE_VERSION}"

pushd ${METAL3_DEV_ENV_PATH}
pushd "${METAL3_DEV_ENV_PATH}"
ansible-galaxy install -r vm-setup/requirements.yml
# Let's temporarily pin these collections to the latest compatible with ansible-2.15
#ansible-galaxy collection install --upgrade ansible.netcommon ansible.posix ansible.utils community.general
Expand Down
48 changes: 28 additions & 20 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ export GOTRACEBACK=crash
export MOBY_DISABLE_PIGZ=true

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
USER=`whoami`
GROUP=`id -gn`
USER=$(whoami)
GROUP=$(id -gn)

function error () {
# shellcheck disable=SC2068
echo $@ 1>&2
}

is_lower_version () {
if [[ $(echo "$1 $2" | tr " " "\n" | sort -V | head -n1) != $2 ]]; then
if [[ $(echo "$1 $2" | tr " " "\n" | sort -V | head -n1) != "$2" ]]; then
return 0
else
return 1
Expand All @@ -45,7 +46,7 @@ XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$(systemd-path user-configuration)}
# Get variables from the config file
if [ -z "${CONFIG:-}" ]; then
# See if there's a config_$USER.sh in the SCRIPTDIR
if [ -f ${SCRIPTDIR}/config_${USER}.sh ]; then
if [ -f "${SCRIPTDIR}/config_${USER}.sh" ]; then
echo "Using CONFIG ${SCRIPTDIR}/config_${USER}.sh" 1>&2
CONFIG="${SCRIPTDIR}/config_${USER}.sh"
elif [[ -f "${XDG_CONFIG_HOME}/dev-scripts/config" ]]; then
Expand All @@ -57,7 +58,8 @@ if [ -z "${CONFIG:-}" ]; then
exit 1
fi
fi
source $CONFIG
# shellcheck source=/dev/null
source "$CONFIG"

export CLUSTER_NAME=${CLUSTER_NAME:-ostest}

Expand All @@ -71,7 +73,7 @@ export BAREMETAL_NETWORK_NAME=${BAREMETAL_NETWORK_NAME:-${CLUSTER_NAME}bm}

export BASE_DOMAIN=${BASE_DOMAIN:-test.metalkube.org}
export CLUSTER_DOMAIN="${CLUSTER_NAME}.${BASE_DOMAIN}"
export SSH_PUB_KEY="${SSH_PUB_KEY:-$(cat $HOME/.ssh/id_rsa.pub)}"
export SSH_PUB_KEY="${SSH_PUB_KEY:-$(cat "$HOME/.ssh/id_rsa.pub")}"
export SSH_KEY_FILE="${SSH_KEY_FILE:-$HOME/.ssh/id_rsa.pub}"

# mirror images for installation in restricted network
Expand Down Expand Up @@ -122,7 +124,8 @@ export REGISTRY_BACKEND=${REGISTRY_BACKEND:-"podman"}
# Set this variable to build the installer from source
export KNI_INSTALL_FROM_GIT=${KNI_INSTALL_FROM_GIT:-}

export OPENSHIFT_CLIENT_TOOLS_URL=https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/stable/openshift-client-linux.tar.gz
OPENSHIFT_CLIENT_TOOLS_URL=https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/stable/openshift-client-linux.tar.gz
export OPENSHIFT_CLIENT_TOOLS_URL

# Note: when changing defaults for OPENSHIFT_RELEASE_STREAM, make sure to update
# doc in config_example.sh
Expand All @@ -145,8 +148,9 @@ fi
# DNS resolution for amd64.ocp.releases.ci.openshift.org fails
# pretty regularly, so try a few times before giving up.
function get_latest_ci_image() {
# shellcheck disable=SC2034
for i in {1..3}; do
if curl -L https://amd64.ocp.releases.ci.openshift.org/api/v1/releasestream/${OPENSHIFT_RELEASE_STREAM}.0-0.${OPENSHIFT_RELEASE_TYPE}/latest | grep -o 'registry.ci.openshift.org[^"]\+'; then
if curl -L "https://amd64.ocp.releases.ci.openshift.org/api/v1/releasestream/${OPENSHIFT_RELEASE_STREAM}.0-0.${OPENSHIFT_RELEASE_TYPE}/latest"| grep -o 'registry.ci.openshift.org[^"]\+'; then
return
fi
echo "Failed to get CI image" 1>&2
Expand All @@ -160,7 +164,7 @@ function get_latest_ci_image() {
# if we provide OPENSHIFT_RELEASE_IMAGE, do not curl. This is needed for offline installs
if [ -z "${OPENSHIFT_RELEASE_IMAGE:-}" ]; then
if [[ "$OPENSHIFT_RELEASE_TYPE" == "ga" ]]; then
LATEST_CI_IMAGE=$(curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/${OPENSHIFT_VERSION}/release.txt | grep -o 'quay.io/openshift-release-dev/ocp-release[^"]\+')
LATEST_CI_IMAGE=$(curl -L "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/${OPENSHIFT_VERSION}/release.txt" | grep -o 'quay.io/openshift-release-dev/ocp-release[^"]\+')
else
LATEST_CI_IMAGE=$(get_latest_ci_image)
if [ -z "$LATEST_CI_IMAGE" ]; then
Expand All @@ -181,10 +185,12 @@ export HIVE_DEPLOY_IMAGE="${HIVE_DEPLOY_IMAGE:-registry.ci.openshift.org/openshi
export OPENSHIFT_CI=${OPENSHIFT_CI:-""}
export OPENSHIFT_VERSION=${OPENSHIFT_VERSION:-""}
if [[ -z "$OPENSHIFT_CI" ]]; then
export OPENSHIFT_VERSION=${OPENSHIFT_VERSION:-$(echo $OPENSHIFT_RELEASE_IMAGE | sed "s/.*:\([[:digit:]]\.[[:digit:]]*\).*/\1/")}
# shellcheck disable=SC2001
export OPENSHIFT_VERSION=${OPENSHIFT_VERSION:-$(echo "$OPENSHIFT_RELEASE_IMAGE" | sed "s/.*:\([[:digit:]]\.[[:digit:]]*\).*/\1/")}
fi

export OPENSHIFT_RELEASE_TAG=$(echo $OPENSHIFT_RELEASE_IMAGE | sed -E 's/[[:alnum:]\/.-]*(release|okd).*://')
OPENSHIFT_RELEASE_TAG=$(echo "$OPENSHIFT_RELEASE_IMAGE" | sed -E 's/[[:alnum:]\/.-]*(release|okd).*://')
export OPENSHIFT_RELEASE_TAG

# Use "ipmi" for 4.3 as it didn't support redfish, for other versions
# use "redfish", unless its CI where we use "mixed"
Expand All @@ -209,7 +215,7 @@ if [ "${UPSTREAM_IRONIC:-false}" != "false" ] ; then
export IRONIC_LOCAL_IMAGE=${IRONIC_LOCAL_IMAGE:-"quay.io/metal3-io/ironic:main"}
# Starting from Openshift 4.9 the ironic-inspector container is not used anymore
# FIXME: $OPENSHIFT_VERSION is not defined in CI
if is_lower_version $OPENSHIFT_VERSION 4.9; then
if is_lower_version "$OPENSHIFT_VERSION" 4.9; then
export IRONIC_INSPECTOR_LOCAL_IMAGE=${IRONIC_INSPECTOR_LOCAL_IMAGE:-"quay.io/metal3-io/ironic-inspector:master"}
fi
export IRONIC_STATIC_IP_MANAGER_LOCAL_IMAGE=${IRONIC_STATIC_IP_MANAGER_LOCAL_IMAGE:-"quay.io/metal3-io/static-ip-manager"}
Expand Down Expand Up @@ -334,8 +340,8 @@ export PERSONAL_PULL_SECRET=${PERSONAL_PULL_SECRET:-$SCRIPTDIR/pull_secret.json}

# Ensure working dir is always different than script dir. If not, some
# files may get overriden during deployment process.
if [ "$(realpath ${WORKING_DIR})" == "$(realpath ${SCRIPTDIR})" ]; then
error "WORKING_DIR must not be the same as SCRIPTDIR, i.e. $(realpath ${WORKING_DIR})"
if [ "$(realpath "${WORKING_DIR}")" == "$(realpath "${SCRIPTDIR}")" ]; then
error "WORKING_DIR must not be the same as SCRIPTDIR, i.e. $(realpath "${WORKING_DIR}")"
error "is used for both. Please change one of them to another directory."
error "WORKING_DIR will be created automatically if it does not exist."
exit 1
Expand Down Expand Up @@ -384,11 +390,12 @@ export ENABLE_BOOTSTRAP_STATIC_IP=${ENABLE_BOOTSTRAP_STATIC_IP:-}

export EXTERNAL_LOADBALANCER=${EXTERNAL_LOADBALANCER:-}

if [ -n "$EXTERNAL_LOADBALANCER" -a -z "$ENABLE_BOOTSTRAP_STATIC_IP" ]; then
if [ -n "$EXTERNAL_LOADBALANCER" ] && [ -z "$ENABLE_BOOTSTRAP_STATIC_IP" ]; then
error "EXTERNAL_LOADBALANCER requires ENABLE_BOOTSTRAP_STATIC_IP to be set as well"
exit 1
fi

# shellcheck disable=SC1091
source /etc/os-release
export DISTRO="${ID}${VERSION_ID%.*}"

Expand All @@ -406,7 +413,7 @@ fi

# Only redfish BMC driver is supported for two node fencing
if [[ "${BMC_DRIVER}" != "redfish" ]] && [[ "${ENABLE_TWO_NODE_FENCING:-}" == "true" ]]; then
printf "Only redfish BMC driver is supported for Two Node Fencing deployments: BMC_DRIVER=${BMC_DRIVER}, ENABLE_TWO_NODE_FENCING=${ENABLE_TWO_NODE_FENCING}"
printf "Only redfish BMC driver is supported for Two Node Fencing deployments: BMC_DRIVER=%s, ENABLE_TWO_NODE_FENCING=%s" "${BMC_DRIVER}" "${ENABLE_TWO_NODE_FENCING}"
exit 1
fi

Expand All @@ -419,7 +426,7 @@ export AGENT_WAIT_FOR_INSTALL_COMPLETE=${AGENT_WAIT_FOR_INSTALL_COMPLETE:-true}
# Agent specific configuration

function invalidAgentValue() {
printf "Found invalid value \"$AGENT_E2E_TEST_SCENARIO\" for AGENT_E2E_TEST_SCENARIO. Supported values: 'COMPACT_IPXX', 'HA_IPXX', 'SNO_IPXX', 'TNA_IPXX', '4CONTROL_IPXX', or '5CONTROL_IPXX', where XX is 'V4', 'V6', or 'V4V6'"
printf "Found invalid value \"%s\" for AGENT_E2E_TEST_SCENARIO. Supported values: 'COMPACT_IPXX', 'HA_IPXX', 'SNO_IPXX', 'TNA_IPXX', '4CONTROL_IPXX', or '5CONTROL_IPXX', where XX is 'V4', 'V6', or 'V4V6'" "${AGENT_E2E_TEST_SCENARIO}"
exit 1
}

Expand All @@ -445,12 +452,13 @@ export AGENT_OPERATORS=${AGENT_OPERATORS:-""}
SCENARIO=""
if [[ ! -z ${AGENT_E2E_TEST_SCENARIO} ]]; then
IFS='_'
read -a arr <<<"$AGENT_E2E_TEST_SCENARIO"
read -r -a arr <<<"$AGENT_E2E_TEST_SCENARIO"
delimiterCount=$(echo "$AGENT_E2E_TEST_SCENARIO" | tr -cd '_' | wc -c)
unset IFS

SCENARIO=${arr[0]}
export IP_STACK=$(echo ${arr[1]##*IP} | tr V v)
IP_STACK=$(echo "${arr[1]##*IP}" | tr V v)
export IP_STACK

if [[ "$delimiterCount" == "2" ]]; then
export NETWORKING_MODE=${arr[2]}
Expand Down Expand Up @@ -617,7 +625,7 @@ if [[ ! -z ${AGENT_E2E_TEST_BOOT_MODE} ]]; then
# Valid value
;;
*)
printf "Found invalid value \"$AGENT_E2E_TEST_BOOT_MODE\" for AGENT_E2E_TEST_BOOT_MODE. Supported values: ISO (default), PXE, DISKIMAGE, ISCSI, or ISO_NO_REGISTRY."
printf "Found invalid value \"%s\" for AGENT_E2E_TEST_BOOT_MODE. Supported values: ISO (default), PXE, DISKIMAGE, ISCSI, or ISO_NO_REGISTRY." "$AGENT_E2E_TEST_BOOT_MODE"
exit 1
;;
esac
Expand Down
10 changes: 5 additions & 5 deletions logging.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Log output automatically
DEFAULT_LOGDIR="$(dirname $0)/logs"
DEFAULT_LOGDIR="$(dirname "$0")/logs"
LOGDIR=${LOGDIR:-$DEFAULT_LOGDIR}
if [[ -z "${LOGPREFIX:-}" ]]; then
LOGFILE="$LOGDIR/$(basename $0 .sh)-$(date +%F-%H%M%S).log"
LOGFILE="$LOGDIR/$(basename "$0" .sh)-$(date +%F-%H%M%S).log"
else
LOGFILE="$LOGDIR/${LOGPREFIX}$(basename $0 .sh)-$(date +%F-%H%M%S).log"
LOGFILE="$LOGDIR/${LOGPREFIX}$(basename "$0" .sh)-$(date +%F-%H%M%S).log"
fi
if [ ! -d "$(dirname $LOGFILE)" ]; then
mkdir -p "$(dirname $LOGFILE)"
if [ ! -d "$(dirname "$LOGFILE")" ]; then
mkdir -p "$(dirname "$LOGFILE")"
fi
echo "Logging to $LOGFILE"
# Set fd 1 and 2 to write to the log file
Expand Down
10 changes: 5 additions & 5 deletions sanitychecks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ function verifyClean {
}

function verifyWorkingDir {
if [ ! -d $WORKING_DIR ]; then
if [ ! -d "$WORKING_DIR" ]; then
echo "WORKING_DIR ${WORKING_DIR} is not a directory"
exit 1
fi

if [ ! -r $WORKING_DIR -o ! -w $WORKING_DIR ]; then
if [ ! -r "$WORKING_DIR" ] || [ ! -w "$WORKING_DIR" ]; then
echo "Unable to access WORKING_DIR ${WORKING_DIR}"
exit 1
fi

if ! sudo -u nobody test -r ${WORKING_DIR}; then
if ! sudo -u nobody test -r "${WORKING_DIR}"; then
echo "The WORKING_DIR ${WORKING_DIR} is not world-readable!"
exit 1
fi
}

function verifyFreeSpace {
AVAIL=$(df -h --output=avail -B 1G $WORKING_DIR | tail -n 1)
AVAIL=$(df -h --output=avail -B 1G "$WORKING_DIR" | tail -n 1)

if (( $AVAIL < $MIN_SPACE_REQUIRED )); then
if (( "$AVAIL" < "$MIN_SPACE_REQUIRED" )); then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (( "$AVAIL" < "$MIN_SPACE_REQUIRED" )); then
if (( AVAIL < MIN_SPACE_REQUIRED )); then

echo "Not enough free space, at least MIN_SPACE_REQUIRED=${MIN_SPACE_REQUIRED} GB required"
exit 1
fi
Expand Down
Loading