From 02e65c7fc19f7521737f1c134582f12fd4317633 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 9 Nov 2023 22:47:10 +0900 Subject: [PATCH] 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 --- functions | 63 +++++++++++++++++++++++----------------------- install_modules.sh | 10 -------- run_tests.sh | 32 ++++++++++++++++++++--- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/functions b/functions index 4d376cbca..bd1116645 100644 --- a/functions +++ b/functions @@ -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 } diff --git a/install_modules.sh b/install_modules.sh index 774417cb9..458ada79c 100755 --- a/install_modules.sh +++ b/install_modules.sh @@ -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)' diff --git a/run_tests.sh b/run_tests.sh index 7b86de31a..89569bf2f 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -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