Refactor puppet installation in integration job

This splits the existing function to repository set up and actual
package installation and adds an additional knob to skip setting up
puppetlabs repo (and install puppet from distributions).

Change-Id: I3568883537e8cc29f234754c78fc2425ad6a8f4b
This commit is contained in:
Takashi Kajinami 2023-11-09 22:47:10 +09:00
parent c2000f96e5
commit 02e65c7fc1
3 changed files with 60 additions and 45 deletions

View File

@ -189,40 +189,21 @@ print_header() {
fi
}
install_puppet() {
install_puppetlabs_repo() {
print_header 'Install Puppetlabs repo'
if uses_debs; then
print_header 'Setup (Debian based)'
if [ "${MANAGE_REPOS}" == "true" ] ; then
PUPPET_CODENAME=$(lsb_release -s -c)
DISTRIBUTION_VENDOR=$(lsb_release -s -i)
# In Debian, we use the distro packages
if [ "${DISTRIBUTION_VENDOR}" = "Ubuntu" ] ; then
$SUDO mkdir -p /etc/apt/sources.list.d
echo "deb ${NODEPOOL_PUPPETLABS_MIRROR} ${PUPPET_CODENAME} puppet${PUPPET_MAJ_VERSION}" | $SUDO tee /etc/apt/sources.list.d/puppetlabs.list
$SUDO apt-key add files/GPG-KEY-puppetlabs
$SUDO apt-key add files/GPG-KEY-ceph
$SUDO apt-get update
fi
fi
# In Debian, the distro package name is simply "puppet"
# and there's no reason to have it in a variable.
if [ "${DISTRIBUTION_VENDOR}" = "Debian" ] ; then
$SUDO apt-get install -y puppet
else
$SUDO apt-get install -y ${PUPPET_PKG}
fi
PUPPET_CODENAME=$(lsb_release -s -c)
$SUDO mkdir -p /etc/apt/sources.list.d
echo "deb ${NODEPOOL_PUPPETLABS_MIRROR} ${PUPPET_CODENAME} puppet${PUPPET_MAJ_VERSION}" | $SUDO tee /etc/apt/sources.list.d/puppetlabs.list
$SUDO apt-key add files/GPG-KEY-puppetlabs
$SUDO apt-key add files/GPG-KEY-ceph
$SUDO apt-get update
elif is_fedora; then
print_header 'Setup (RedHat based)'
# EPEL does not work fine with RDO, we need to make sure EPEL is really disabled
if rpm --quiet -q epel-release; then
$SUDO $YUM remove -y epel-release
fi
source /etc/os-release
if [ "${MANAGE_REPOS}" == "true" ] ; then
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppetlabs
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppet
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppet-20250406
$SUDO bash -c "cat << EOF > /etc/yum.repos.d/puppetlabs.repo
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppetlabs
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppet
$SUDO rpm --import ${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppet-20250406
$SUDO bash -c "cat << EOF > /etc/yum.repos.d/puppetlabs.repo
[puppetlabs-products]
name=Puppet Labs Products El ${VERSION_ID} - x86_64
baseurl=${NODEPOOL_PUPPETLABS_MIRROR}/puppet${PUPPET_MAJ_VERSION}/el/${VERSION_ID}/x86_64/
@ -232,7 +213,27 @@ gpgkey=${NODEPOOL_PUPPETLABS_MIRROR}/RPM-GPG-KEY-puppetlabs
enabled=1
gpgcheck=1
EOF"
fi
}
install_puppet() {
print_header 'Install Puppet'
if uses_debs; then
$SUDO apt-get install -y ${PUPPET_PKG}
DISTRIBUTION_VENDOR=$(lsb_release -s -i)
if [ ${DISTRIBUTION_VENDOR} = 'Debian' ]; then
if [ "${USE_PUPPETLABS}" != 'true' ] && [ "${PUPPET_PKG}" = 'puppet' ]; then
# NOTE(tkajinam): puppet pacakge in Debian is separated to
# sub packages.
$SUDO apt-get install -y \
puppet-module-puppetlabs-augeas-core \
puppet-module-puppetlabs-cron-core \
puppet-module-puppetlabs-mount-core \
puppet-module-puppetlabs-sshkeys-core
fi
fi
elif is_fedora; then
$SUDO $YUM install -y ${PUPPET_PKG}
fi
}

View File

@ -10,17 +10,7 @@ if [ -n "${GEM_HOME}" ]; then
GEM_INSTALL_CMD="${GEM_INSTALL_CMD} --install-dir=$GEM_HOME --bindir=${GEM_BIN_DIR}"
fi
# NOTE(aschultz): since puppet 3 is now EOL, and beaker-puppet_install_helper
# version 0.6.0 has made the agent version the default, we need to symlink
# puppet to the /opt/puppetlabs version when specifically not version 3.
if [ -e /opt/puppetlabs/bin/puppet ]; then
export PUPPET_BASE_PATH=/etc/puppetlabs/code
export PATH=${PATH}:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin
sudo -E ln -sfn /opt/puppetlabs/bin/puppet /usr/sbin/puppet
fi
export SCRIPT_DIR=$(cd `dirname $0` && pwd -P)
export PUPPETFILE_DIR=${PUPPETFILE_DIR:-${PUPPET_BASE_PATH}/modules}
source $SCRIPT_DIR/functions
print_header 'Start (install_modules.sh)'

View File

@ -22,11 +22,27 @@ export PUPPET_MAJ_VERSION=${PUPPET_MAJ_VERSION:-6}
export SCENARIO=${SCENARIO:-scenario001}
export MANAGE_PUPPET_MODULES=${MANAGE_PUPPET_MODULES:-true}
export MANAGE_REPOS=${MANAGE_REPOS:-true}
export USE_PUPPETLABS=${USE_PUPPETLABS:-true}
export ADD_SWAP=${ADD_SWAP:-true}
export SWAP_SIZE_GB=${SWAP_SIZE_GB:-8}
export HIERA_CONFIG=${HIERA_CONFIG:-${SCRIPT_DIR}/hiera.yaml}
export MANAGE_HIERA=${MANAGE_HIERA:-true}
if [ "${USE_PUPPETLABS}" = true ];then
export PATH=${PATH}:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin
export PUPPET_BASE_PATH=/etc/puppetlabs/code
export PUPPET_PKG=${PUPPET_PKG:-puppet-agent}
else
if is_fedora; then
export PUPPET_BASE_PATH=/etc/puppet
else
export PUPPET_BASE_PATH=/etc/puppet/code
fi
export PUPPET_PKG=${PUPPET_PKG:-puppet}
fi
export PUPPETFILE_DIR=${PUPPETFILE_DIR:-${PUPPET_BASE_PATH}/modules}
export PUPPET_ARGS="${PUPPET_ARGS} --detailed-exitcodes --color=false --test --summarize --trace --hiera_config ${HIERA_CONFIG} --logdest ${WORKSPACE}/puppet.log"
# If openstack/tempest is broken on master, we can pin the repository to a specific commit
# by using the following line:
export TEMPEST_VERSION=${TEMPEST_VERSION:-'master'}
@ -50,10 +66,6 @@ export CIRROS_VERSION=${CIRROS_VERSION:-0.6.2}
export WRITE_FACTS=false
source ${SCRIPT_DIR}/configure_facts.sh
export PATH=${PATH}:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin
export PUPPET_BASE_PATH=/etc/puppetlabs/code
export PUPPET_PKG=${PUPPET_PKG:-puppet-agent}
print_header 'Start (run_tests.sh)'
if [ ! -f fixtures/${SCENARIO}.pp ]; then
@ -140,8 +152,20 @@ ln -s $IMG_DIR/cirros-${CIRROS_VERSION}-x86_64-disk.img $IMG_DIR/cirros-${CIRROS
# NOTE(tkajinam): Prepare raw format image
qemu-img convert -f qcow2 -O raw $IMG_DIR/cirros-${CIRROS_VERSION}-x86_64-disk.img $IMG_DIR/cirros-${CIRROS_VERSION}-x86_64-disk-raw.img
if is_fedora; then
# EPEL does not work fine with RDO, we need to make sure EPEL is really disabled
if rpm --quiet -q epel-release; then
$SUDO $YUM remove -y epel-release
fi
fi
if [ "${MANAGE_REPOS}" = true ] && [ "${USE_PUPPETLABS}" = true ]; then
install_puppetlabs_repo
fi
install_puppet
PUPPET_FULL_PATH=$(which puppet)
if [ "${MANAGE_HIERA}" = true ]; then
configure_hiera
fi