Add puppet integration DEP-8 test

Run a puppet integration test using autopkgtests. Connect PuppetDB and
Puppet master and perform an agent run, checking the results.
parent 0f30605d
STATUS_URL="http://localhost:8080/status/v1/services/puppetdb-status"
QUERY_URL="http://localhost:8080/pdb/query/v4"
set -e
cleanup () {
retval=$?
set +e
if [ -n "${AUTOPKGTEST_ARTIFACTS}" ]; then
cp /var/log/puppetdb/puppetdb.log "${AUTOPKGTEST_ARTIFACTS}"
if [ -d /run/systemd/system ]; then
journalctl -u puppetdb.service > "${AUTOPKGTEST_ARTIFACTS}/journal.log"
fi
fi
return $retval
}
get_status () {
curl -s "$STATUS_URL"
}
check_status_var () {
get_status | jq -e ".status[\"$1\"] == $2"
}
query () {
curl -s "${QUERY_URL}/$1"
}
wait_for_pdb() {
local state="boot"
local timeout=120
for count in $(seq 1 $timeout); do
case "$state" in
boot)
if curl -s --connect-timeout 1 "$STATUS_URL" >/dev/null; then
state="starting"
echo "PuppetDB is responding, checking maintenance mode"
continue
else
sleep 1
fi
;;
starting)
if check_status_var maintenance_mode? true >/dev/null; then
echo "Still in maintenance mode"
sleep 1
else
echo "Maintenance mode disabled"
break
fi
;;
esac
done
if [ $count -eq $timeout ]; then
echo "Timed out"
exit 1
fi
}
Tests: standalone
Depends: postgresql-contrib, puppetdb, curl, jq
Restrictions: needs-root
Tests: puppet
Depends: postgresql-contrib, puppetdb, puppet-master-passenger, puppet-terminus-puppetdb, curl, jq
Restrictions: needs-root
#!/bin/sh
# Test PuppetDB & Puppet integration
# Configure PuppetDB and Puppet master to talk to each other, do a client run
# and check the results.
. "$(dirname $0)/common.sh"
set -e
trap 'cleanup' EXIT
certname="$(puppet config print certname)"
hostcert="$(puppet config print hostcert)"
hostkey="$(puppet config print hostprivkey)"
cacert="$(puppet config print cacert)"
adduser puppetdb puppet
cat >>/etc/puppetdb/conf.d/jetty.ini <<-EOF
ssl-host = 0.0.0.0
ssl-port = 8081
ssl-key = ${hostkey}
ssl-cert = ${hostcert}
ssl-ca-cert = ${cacert}
EOF
systemctl restart puppetdb
puppet config set --section=master reports puppetdb
puppet config set --section=master storeconfigs true
puppet config set --section=master storeconfigs_backend puppetdb
cp /usr/share/doc/puppet-terminus-puppetdb/routes.yaml.example /etc/puppet/routes.yaml
cat >/etc/puppet/puppetdb.conf <<-EOF
[main]
server_urls = https://${certname}:8081
EOF
systemctl reload apache2
mkdir -p /etc/puppet/code/environments/production/manifests
cat >/etc/puppet/code/environments/production/manifests/default.pp <<-EOF
node default {
file { '/tmp/testfile' :
ensure => present,
content => "autopkgtest\n",
}
}
EOF
echo "Waiting for PuppetDB to start"
wait_for_pdb
echo "Running puppet"
puppet agent --test --server "$certname" && [ $? -eq 2]
echo "Checking for /tmp/testfile"
test -f /tmp/testfile
echo "Checking for node existence"
query "nodes/${certname}" | jq -e ".certname == \"${certname}\""
echo "Checking the fqdn fact"
query "nodes/${certname}/facts/fqdn" | jq -e ".[0].value == \"${certname}\""
echo "Checking the node's catalog"
query "catalogs/${certname}" | jq -e 'has("catalog_uuid")'
echo "Checking the node's report"
query "reports" | jq -e "(map(select(.certname == \"${certname}\")) | length) >= 1"
echo "Checking 'puppet node status ${certname}'"
puppet node status "$certname" | grep -qi "\bactive\b"
echo "Deactivating node"
puppet node deactivate "$certname"
sleep 2 # Let PuppetDB process everything
echo "Checking 'puppet node estatus ${certname}' again"
puppet node status "$certname" | grep -qi "Deactivated"
......@@ -4,68 +4,11 @@
# Perform basic checks using the REST endpoints. No puppet integration is
# tested at this point.
STATUS_URL="http://localhost:8080/status/v1/services/puppetdb-status"
QUERY_URL="http://localhost:8080/pdb/query/v4"
. "$(dirname $0)/common.sh"
CERTNAME="autopkgtest"
set -e
cleanup () {
retval=$?
set +e
if [ -n "${AUTOPKGTEST_ARTIFACTS}" ]; then
cp /var/log/puppetdb/puppetdb.log "${AUTOPKGTEST_ARTIFACTS}"
if [ -d /run/systemd/system ]; then
journalctl -u puppetdb.service > "${AUTOPKGTEST_ARTIFACTS}/journal.log"
fi
fi
return $retval
}
get_status () {
curl -s "$STATUS_URL"
}
check_status_var () {
get_status | jq -e ".status[\"$1\"] == $2"
}
query () {
curl -s "${QUERY_URL}/$1"
}
wait_for_pdb() {
local state="boot"
local timeout=120
for count in $(seq 1 $timeout); do
case "$state" in
boot)
if curl -s --connect-timeout 1 "$STATUS_URL" >/dev/null; then
state="starting"
echo "PuppetDB is responding, checking maintenance mode"
continue
else
sleep 1
fi
;;
starting)
if check_status_var maintenance_mode? true >/dev/null; then
echo "Still in maintenance mode"
sleep 1
else
echo "Maintenance mode disabled"
break
fi
;;
esac
done
if [ $count -eq $timeout ]; then
echo "Timed out"
exit 1
fi
}
trap 'cleanup' EXIT
echo "Waiting for PuppetDB to start"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment