mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-22 23:21:08 +02:00
* [VAULT-27917] fix(enos): handle SLES guestregister.service unreliability The SLES provided `guestregister.service` systemd unit is unreliable enough that it will fail ~ 1/9 times when provisioning SLES instances. When this happens the machine will never successfully exec SUSEConnect to enroll and we'll get no access to the SLES repositories and subsequently break our scenarios. I resolved this by restructuring our `install_packages` module to to separate repository synchronization, repository addition, and package installation into different scripts and resources and by adding special case handling for SLES and the `guestregister.service`. I also make a distinction between `dnf` and `yum` because while they are sort of the same thing on RHEL, it is not the case with Amazon2. I also shimmed out the rest of the support for Apt in case we ever need to add repos there. * Revert "Temporarily remove SLES from samples (#27378)" This reverts commit 490cdd90661a57cf849c7d64aec545e87fb393c8. Signed-off-by: Ryan Cragun <me@ryan.ec>
106 lines
3.0 KiB
Bash
106 lines
3.0 KiB
Bash
#!/bin/bash
|
|
# Copyright (c) HashiCorp, Inc.
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
set -e
|
|
|
|
fail() {
|
|
echo "$1" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
[[ -z "${RETRY_INTERVAL}" ]] && fail "RETRY_INTERVAL env variable has not been set"
|
|
[[ -z "${TIMEOUT_SECONDS}" ]] && fail "TIMEOUT_SECONDS env variable has not been set"
|
|
[[ -z "${PACKAGES}" ]] && fail "PACKAGES env variable has not been set"
|
|
[[ -z "${PACKAGE_MANAGER}" ]] && fail "PACKAGE_MANAGER env variable has not been set"
|
|
|
|
# Install packages based on the provided packages and package manager. We assume that the repositories
|
|
# have already been synchronized by the repo setup that is a prerequisite for this script.
|
|
install_packages() {
|
|
if [[ "${PACKAGES}" = "__skip" ]]; then
|
|
return 0
|
|
fi
|
|
|
|
set -x
|
|
echo "Installing Dependencies: ${PACKAGES}"
|
|
|
|
# Use the default package manager of the current Linux distro to install packages
|
|
case $PACKAGE_MANAGER in
|
|
apt)
|
|
for package in ${PACKAGES}; do
|
|
if dpkg -s "${package}"; then
|
|
echo "Skipping installation of ${package} because it is already installed"
|
|
continue
|
|
else
|
|
echo "Installing ${package}"
|
|
local output
|
|
if ! output=$(sudo apt install -y "${package}" 2>&1); then
|
|
echo "Failed to install ${package}: ${output}" 1>&2
|
|
return 1
|
|
fi
|
|
fi
|
|
done
|
|
;;
|
|
dnf)
|
|
for package in ${PACKAGES}; do
|
|
if rpm -q "${package}"; then
|
|
echo "Skipping installation of ${package} because it is already installed"
|
|
continue
|
|
else
|
|
echo "Installing ${package}"
|
|
local output
|
|
if ! output=$(sudo dnf -y install "${package}" 2>&1); then
|
|
echo "Failed to install ${package}: ${output}" 1>&2
|
|
return 1
|
|
fi
|
|
fi
|
|
done
|
|
;;
|
|
yum)
|
|
for package in ${PACKAGES}; do
|
|
if rpm -q "${package}"; then
|
|
echo "Skipping installation of ${package} because it is already installed"
|
|
continue
|
|
else
|
|
echo "Installing ${package}"
|
|
local output
|
|
if ! output=$(sudo yum -y install "${package}" 2>&1); then
|
|
echo "Failed to install ${package}: ${output}" 1>&2
|
|
return 1
|
|
fi
|
|
fi
|
|
done
|
|
;;
|
|
zypper)
|
|
for package in ${PACKAGES}; do
|
|
if rpm -q "${package}"; then
|
|
echo "Skipping installation of ${package} because it is already installed"
|
|
continue
|
|
else
|
|
echo "Installing ${package}"
|
|
local output
|
|
if ! output=$(sudo zypper --non-interactive install -y -l --force-resolution "${package}" 2>&1); then
|
|
echo "Failed to install ${package}: ${output}" 1>&2
|
|
return 1
|
|
fi
|
|
fi
|
|
done
|
|
;;
|
|
*)
|
|
fail "No matching package manager provided."
|
|
;;
|
|
esac
|
|
}
|
|
|
|
begin_time=$(date +%s)
|
|
end_time=$((begin_time + TIMEOUT_SECONDS))
|
|
while [[ "$(date +%s)" -lt "${end_time}" ]]; do
|
|
if install_packages; then
|
|
exit 0
|
|
fi
|
|
|
|
sleep "${RETRY_INTERVAL}"
|
|
done
|
|
|
|
fail "Timed out waiting for packages to install"
|