2015-10-05 16:39:26 -04:00
#!/bin/bash
#
# functions - puppet-openstack-integration specific functions
#
# Install external Puppet modules with r10k
# Uses the following variables:
#
# - ``SCRIPT_DIR`` must be set to script path
# - ``GEM_BIN_DIR`` must be set to Gem bin directory
install_external() {
2018-02-06 03:34:34 +00:00
PUPPETFILE=${SCRIPT_DIR}/Puppetfile1 r10k -v DEBUG puppetfile install
2015-10-05 16:39:26 -04:00
}
# Install Puppet OpenStack modules with zuul-cloner
# Uses the following variables:
#
2018-02-06 03:34:34 +00:00
# - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
2015-10-05 16:39:26 -04:00
# - ``SCRIPT_DIR`` must be set to script path
2016-04-20 09:38:56 -04:00
# - ``ZUUL_BRANCH`` must be set to Zuul branch. Fallback to 'master'.
2018-07-02 09:31:53 +02:00
# - ``CEPH_VERSION`` can be set to override Ceph version.
2015-10-05 16:39:26 -04:00
install_openstack() {
2018-06-19 17:32:27 +02:00
# Periodic jobs run without ref on master
ZUUL_BRANCH=${ZUUL_BRANCH:-master}
2018-07-02 09:31:53 +02:00
if [ "$ZUUL_PROJECT" != "openstack/puppet-ceph" ] && [ -n "$CEPH_VERSION" ]; then
if [ "$CEPH_VERSION" == "mimic" ]; then
2018-06-19 17:32:27 +02:00
ZUUL_BRANCH="master"
else
ZUUL_BRANCH="stable/$CEPH_VERSION"
fi
fi
2015-10-05 16:39:26 -04:00
cat > clonemap.yaml <<EOF
clonemap:
- name: '(.*?)/puppet-(.*)'
2018-02-06 03:34:34 +00:00
dest: '$PUPPETFILE_DIR/\2'
2015-10-05 16:39:26 -04:00
EOF
local project_names=$(awk '{ if ($1 == ":git") print $3 }' \
${SCRIPT_DIR}/Puppetfile0 | tr -d "'," | cut -d '/' -f 4- | xargs
)
2016-09-16 11:48:00 -04:00
project_names="${project_names} openstack/puppet-openstack-integration"
2015-10-05 16:39:26 -04:00
/usr/zuul-env/bin/zuul-cloner -m clonemap.yaml \
--cache-dir /opt/git \
--zuul-branch $ZUUL_BRANCH \
git://git.openstack.org $project_names
2015-11-06 14:43:25 -05:00
# Because openstack-integration can't be a class name.
# https://projects.puppetlabs.com/issues/5268
2018-02-06 03:34:34 +00:00
mv $PUPPETFILE_DIR/openstack-integration $PUPPETFILE_DIR/openstack_integration
2015-10-05 16:39:26 -04:00
}
# Install all Puppet modules with r10k
# Uses the following variables:
#
# - ``SCRIPT_DIR`` must be set to script path
install_all() {
2016-09-16 11:48:00 -04:00
# When installing from local source, we want to install the current source
# we're working from.
2018-02-06 03:34:34 +00:00
PUPPETFILE=${SCRIPT_DIR}/Puppetfile r10k -v DEBUG puppetfile install
cp -a ${SCRIPT_DIR} ${PUPPETFILE_DIR}/openstack_integration
2015-10-05 16:39:26 -04:00
}
# Install Puppet OpenStack modules and dependencies by using
# zuul-cloner or r10k.
# Uses the following variables:
#
2018-02-06 03:34:34 +00:00
# - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
2015-10-05 16:39:26 -04:00
# - ``SCRIPT_DIR`` must be set to script path
# - ``ZUUL_BRANCH`` must be set to Zuul branch
install_modules() {
# If zuul-cloner is there, have it install modules using zuul refs
if [ -e /usr/zuul-env/bin/zuul-cloner ] ; then
csplit ${SCRIPT_DIR}/Puppetfile /'External modules'/ \
--prefix ${SCRIPT_DIR}/Puppetfile \
--suffix '%d'
install_external
install_openstack
else
install_all
fi
}
2015-11-05 12:02:15 -05:00
2016-07-13 13:50:17 -06:00
# Write out basic hiera configuration
#
# Uses the following variables:
# - ``SCRIPT_DIR`` must be set to the dir that contains a /hiera folder to use
# - ``HIERA_CONFIG`` must be set to the hiera config file location
#
configure_hiera() {
cat <<EOF >$HIERA_CONFIG
---
:backends:
- yaml
:yaml:
:datadir: "${SCRIPT_DIR}/hiera"
:hierarchy:
- "%{::operatingsystem}"
- "%{::osfamily}"
- common
EOF
}
2015-11-05 12:02:15 -05:00
is_fedora() {
if [ -f /etc/os-release ]; then
source /etc/os-release
test "$ID" = "fedora" -o "$ID" = "centos"
else
return 1
fi
}
uses_debs() {
# check if apt-get is installed, valid for debian based
type "apt-get" 2>/dev/null
}
2018-06-13 19:07:02 +05:30
if type "dnf" 2>/dev/null;then
export YUM=dnf
else
export YUM=yum
fi
2016-04-14 14:04:57 -06:00
print_header() {
if [ -n "$(set | grep xtrace)" ]; then
set +x
local enable_xtrace='yes'
fi
local msg=$1
printf '%.0s-' {1..80}; echo
printf '| %-76s |\n' "${msg}"
printf '%.0s-' {1..80}; echo
if [ -n "${enable_xtrace}" ]; then
set -x
fi
}
2016-06-08 11:31:00 -04:00
install_puppet() {
if uses_debs; then
print_header 'Setup (Debian based)'
2017-10-09 14:27:38 -04:00
if [ "${MANAGE_REPOS}" == "true" ] ; then
2018-05-02 20:57:42 +02:00
if [ $PUPPET_MAJ_VERSION == 4 ]; then
local PUPPET_APT_POOL="PC1"
2018-10-21 19:00:16 +02:00
else
local PUPPET_APT_POOL="puppet${PUPPET_MAJ_VERSION}"
2018-05-02 20:57:42 +02:00
fi
2018-05-06 14:18:52 +02:00
PUPPET_CODENAME=$(lsb_release -s -c)
if [ $PUPPET_CODENAME == "bionic" ]; then
# For some reason this directory does not exist in Bionic
$SUDO mkdir -p /etc/apt/sources.list.d
fi
echo "deb ${NODEPOOL_PUPPETLABS_MIRROR} ${PUPPET_CODENAME} ${PUPPET_APT_POOL}" | $SUDO tee /etc/apt/sources.list.d/puppetlabs.list
2017-10-09 14:27:38 -04:00
$SUDO apt-key add files/GPG-KEY-puppetlabs
$SUDO apt-key add files/GPG-KEY-ceph
$SUDO apt-get update
fi
2016-06-08 11:31:00 -04:00
$SUDO apt-get install -y ${PUPPET_PKG}
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 rpm -e epel-release
fi
2017-05-30 11:48:50 +02:00
if [ "${MANAGE_REPOS}" == "true" ] ; then
2018-05-02 20:57:42 +02:00
if [ $PUPPET_MAJ_VERSION == 4 ]; then
local PUPPET_YUM_SUFFIX="/el/7/PC1/x86_64/"
2018-10-21 19:00:16 +02:00
else
local PUPPET_YUM_SUFFIX="/puppet${PUPPET_MAJ_VERSION}/el/7/x86_64/"
2018-05-02 20:57:42 +02:00
fi
2018-01-24 23:01:06 -08:00
$SUDO rpm --import files/GPG-KEY-puppetlabs
$SUDO rpm --import files/GPG-KEY-puppet
$SUDO bash -c "cat << EOF > /etc/yum.repos.d/puppetlabs.repo
[puppetlabs-products]
name=Puppet Labs Products El 7 - x86_64
2018-05-02 20:57:42 +02:00
baseurl=${NODEPOOL_PUPPETLABS_MIRROR}${PUPPET_YUM_SUFFIX}
2018-01-24 23:01:06 -08:00
gpgkey=file:///etc/pki/rpm-gpg/GPG-KEY-puppetlabs
file:///etc/pki/rpm-gpg/GPG-KEY-puppet
enabled=1
gpgcheck=1
EOF"
2017-05-30 11:48:50 +02:00
fi
2018-06-13 19:07:02 +05:30
$SUDO $YUM install -y ${PUPPET_PKG}
2016-06-08 11:31:00 -04:00
fi
}
2016-06-08 11:44:10 -04:00
function run_puppet() {
local manifest=$1
$SUDO $PUPPET_FULL_PATH apply $PUPPET_ARGS fixtures/${manifest}.pp
local res=$?
return $res
}
function catch_selinux_alerts() {
if is_fedora; then
$SUDO sealert -a /var/log/audit/audit.log
if $SUDO grep -iq 'type=AVC' /var/log/audit/audit.log; then
echo "AVC detected in /var/log/audit/audit.log"
# TODO: figure why latest rabbitmq deployed with SSL tries to write in SSL pem file.
# https://bugzilla.redhat.com/show_bug.cgi?id=1341738
if $SUDO grep -iqE 'denied.*system_r:rabbitmq_t' /var/log/audit/audit.log; then
echo "non-critical RabbitMQ AVC, ignoring it now."
2018-05-29 16:35:15 +00:00
# FIXME(ykarel) catch_selinux_alerts not work with non ssl scenarios(no rabbitmq alert),
# currently running scenario-py3 without ssl because glance py3 has issues when
# running with eventlet + ssl: https://bugs.launchpad.net/glance/+bug/1769006
2018-09-07 20:05:46 +05:30
elif [[ "$SCENARIO" = "scenario-py3" ]]; then
2018-05-29 16:35:15 +00:00
echo "non ssl scenario-py3, ignoring it now."
2016-06-08 11:44:10 -04:00
else
echo "Please file a bug on https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20OpenStack&component=openstack-selinux showing sealert output."
exit 1
fi
else
echo 'No AVC detected in /var/log/audit/audit.log'
fi
fi
}
2016-10-31 15:15:34 -06:00
function timestamp_puppet_log() {
2016-12-02 10:45:17 -07:00
$SUDO mv ${WORKSPACE}/puppet.log ${WORKSPACE}/puppet-$(date +%Y%m%d_%H%M%S).log
2016-10-31 15:15:34 -06:00
}
function catch_puppet_failures() {
2018-03-19 17:44:12 +08:00
$SUDO grep -wiE '(Error|\(err\))' ${WORKSPACE}/puppet.log
2016-10-31 15:15:34 -06:00
}