+# List of extra services to extract from journalctl
+# Add new services on a separate line, in alpha order, add \ at the end
+extra_services_cntl=" \
+ dnsmasq.service \
+ httpd.service \
+ libvirtd.service \
+ openvswitch.service \
+ ovs-vswitchd.service \
+ ovsdb-server.service \
+ rabbitmq-server.service \
+"
+
+extra_services_cmp=" \
+ libvirtd.service \
+ openvswitch.service \
+ ovs-vswitchd.service \
+ ovsdb-server.service \
+"
+
+# Collect the logs for the openstack services
+# First get all the services started by devstack which would have devstack@ as a prefix
+# Next get all the extra services
+function collect_openstack_logs() {
+ local -r ip=${1}
+ local -r folder=${2}
+ local -r node_type=${3}
+ local oslogs="${folder}/oslogs"
+
+ printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}\n"
+ rm -rf ${oslogs}
+ mkdir -p ${oslogs}
+ # There are always some logs in /opt/stack/logs and this also covers the
+ # pre-queens branches which always use /opt/stack/logs
+ rsync -avhe ssh ${ip}:/opt/stack/logs/* ${oslogs} # rsync to prevent copying of symbolic links
+
+ # Starting with queens break out the logs from journalctl
+ if [ "${OPENSTACK_BRANCH}" = "stable/queens" ]; then
+ cat > ${WORKSPACE}/collect_openstack_logs.sh << EOF
+extra_services_cntl="${extra_services_cntl}"
+extra_services_cmp="${extra_services_cmp}"
+
+function extract_from_journal() {
+ local -r services=\${1}
+ local -r folder=\${2}
+ local -r node_type=\${3}
+ printf "extract_from_journal folder: \${folder}, services: \${services}\n"
+ for service in \${services}; do
+ # strip anything before @ and anything after .
+ # devstack@g-api.service will end as g-api
+ service_="\${service#*@}"
+ service_="\${service_%.*}"
+ sudo journalctl -u "\${service}" > "\${folder}/\${service_}.log"
+ done
+}
+
+rm -rf /tmp/oslogs
+mkdir -p /tmp/oslogs
+systemctl list-unit-files --all > /tmp/oslogs/systemctl.units.log 2>&1
+svcs=\$(grep devstack@ /tmp/oslogs/systemctl.units.log | awk '{print \$1}')
+extract_from_journal "\${svcs}" "/tmp/oslogs"
+if [ "\${node_type}" = "control" ]; then
+ extract_from_journal "\${extra_services_cntl}" "/tmp/oslogs"
+else
+ extract_from_journal "\${extra_services_cmp}" "/tmp/oslogs"
+fi
+ls -al /tmp/oslogs
+EOF
+ printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}, executing script\n"
+ cat ${WORKSPACE}/collect_openstack_logs.sh
+ scp ${WORKSPACE}/collect_openstack_logs.sh ${ip}:/tmp
+ ${SSH} ${ip} "bash /tmp/collect_openstack_logs.sh > /tmp/collect_openstack_logs.log 2>&1"
+ rsync -avhe ssh ${ip}:/tmp/oslogs/* ${oslogs}
+ scp ${ip}:/tmp/collect_openstack_logs.log ${oslogs}
+ fi
+}
+
+function collect_logs() {