tripleo-common/workbooks/support.yaml
Dougal Matthews b5d5cbab32 Verify the Swift container exists with a small utility workflow
The previous method of `swift.head_container` worked well, but it caused
Mistral to log the exception raised by swiftclient. This then left a red
flag in the logs that confused users debugging.

This new method checks for the container by listing all the containers
in the account and checking for the name. We only consider containers
that start with the full name we are looking for - Swift doesn't have an
exact match, only a prefix filter.

The workflow then can be used to create the container, capturing the
logic that was duplicated in each individual workflow.

Closes-Bug: #1730712
Depends-On: I41649d15c57e16bffcf7870a52bc01177aae7cc8
Change-Id: I4a6b5b9b31a4f76840a6c6070a1d733ceade5c64
2018-06-28 12:33:59 +01:00

323 lines
9.9 KiB
YAML

---
version: '2.0'
name: tripleo.support.v1
description: TripleO support workflows
workflows:
collect_logs:
description: >
This workflow runs sosreport on the servers where their names match the
provided server_name input. The logs are stored in the provided sos_dir.
input:
- server_name
- sos_dir: /var/tmp/tripleo-sos
- sos_options: boot,cluster,hardware,kernel,memory,nfs,openstack,packagemanager,performance,services,storage,system,webserver,virt
- queue_name: tripleo
tags:
- tripleo-common-managed
tasks:
collect_logs_on_servers:
workflow: tripleo.deployment.v1.deploy_on_servers
on-success: send_message
on-error: set_collect_logs_on_servers_failed
input:
server_name: <% $.server_name %>
config_name: 'run_sosreport'
config: |
#!/bin/bash
mkdir -p <% $.sos_dir %>
sosreport --batch \
-p <% $.sos_options %> \
--tmp-dir <% $.sos_dir %>
set_collect_logs_on_servers_failed:
on-complete:
- send_message
publish:
type: tripleo.deployment.v1.fetch_logs
status: FAILED
message: <% task().result %>
# status messaging
send_message:
workflow: tripleo.messaging.v1.send
input:
queue_name: <% $.queue_name %>
type: <% $.get('type', execution().name) %>
status: <% $.get('status', 'SUCCESS') %>
execution: <% execution() %>
message: <% $.get('message', '') %>
upload_logs:
description: >
This workflow uploads the sosreport files stored in the provide sos_dir
on the provided host (server_uuid) to a swift container on the undercloud
input:
- server_uuid
- server_name
- container
- sos_dir: /var/tmp/tripleo-sos
- queue_name: tripleo
tags:
- tripleo-common-managed
tasks:
# actions
get_swift_information:
action: tripleo.swift.swift_information
on-success: do_log_upload
on-error: set_get_swift_information_failed
input:
container: <% $.container %>
publish:
container_url: <% task().result.container_url %>
auth_key: <% task().result.auth_key %>
set_get_swift_information_failed:
on-complete:
- send_message
publish:
status: FAILED
message: <% task(get_swift_information).result %>
do_log_upload:
action: tripleo.deployment.config
on-success: send_message
on-error: set_do_log_upload_failed
input:
server_id: <% $.server_uuid %>
name: "upload_logs"
config: |
#!/bin/bash
CONTAINER_URL="<% $.container_url %>"
TOKEN="<% $.auth_key %>"
SOS_DIR="<% $.sos_dir %>"
for FILE in $(find $SOS_DIR -type f); do
FILENAME=$(basename $FILE)
curl -X PUT -i -H "X-Auth-Token: $TOKEN" -T $FILE $CONTAINER_URL/$FILENAME
if [ $? -eq 0 ]; then
rm -f $FILE
fi
done
group: "script"
publish:
message: "Uploaded logs from <% $.server_name %>"
set_do_log_upload_failed:
on-complete:
- send_message
publish:
status: FAILED
message: <% tag(do_log_upload).result %>
# status messaging
send_message:
workflow: tripleo.messaging.v1.send
input:
queue_name: <% $.queue_name %>
type: <% $.get('type', execution().name) %>
status: <% $.get('status', 'SUCCESS') %>
execution: <% execution() %>
message: <% $.get('message', '') %>
create_container:
description: >
This work flow is used to check if the container exists and creates it
if it does not exist.
input:
- container
- queue_name: tripleo
tags:
- tripleo-common-managed
tasks:
check_container:
workflow: tripleo.swift.v1.container_exists
input:
container: <% $.container %>
create_container: true
headers:
x-container-meta-usage-tripleo: support
on-complete: send_message
publish-on-error:
type: tripleo.support.v1.create_container.create_container
status: FAILED
message: <% task(create_container).result %>
# status messaging
send_message:
workflow: tripleo.messaging.v1.send
input:
queue_name: <% $.queue_name %>
type: <% $.get('type', execution().name) %>
status: <% $.get('status', 'SUCCESS') %>
execution: <% execution() %>
message: <% $.get('message', '') %>
delete_container:
description: >
This workflow deletes all the objects in a provided swift container and
then removes the container itself from the undercloud.
input:
- container
- concurrency: 5
- timeout: 900
- queue_name: tripleo
tags:
- tripleo-common-managed
tasks:
# actions
check_container:
workflow: tripleo.swift.v1.container_exists container=<% $.container %>
on-success: list_objects
publish-on-error:
status: FAILED
type: tripleo.support.v1.delete_container.check_container
message: <% task().result %>
on-error: send_message
list_objects:
action: swift.get_container container=<% $.container %>
on-success: delete_objects
on-error: set_list_objects_failure
publish:
log_objects: <% task().result[1] %>
set_list_objects_failure:
on-complete: send_message
publish:
status: FAILED
type: tripleo.support.v1.delete_container.list_objects
message: <% task(list_objects).result %>
delete_objects:
action: swift.delete_object
concurrency: <% $.concurrency %>
timeout: <% $.timeout %>
with-items: object in <% $.log_objects %>
input:
container: <% $.container %>
obj: <% $.object.name %>
on-success: remove_container
on-error: set_delete_objects_failure
set_delete_objects_failure:
on-complete: send_message
publish:
status: FAILED
type: tripleo.support.v1.delete_container.delete_objects
message: <% task(delete_objects).result %>
remove_container:
action: swift.delete_container container=<% $.container %>
on-success: send_message
on-error: set_remove_container_failure
set_remove_container_failure:
on-complete: send_message
publish:
status: FAILED
type: tripleo.support.v1.delete_container.remove_container
message: <% task(remove_container).result %>
# status messaging
send_message:
workflow: tripleo.messaging.v1.send
input:
queue_name: <% $.queue_name %>
type: <% $.get('type', execution().name) %>
status: <% $.get('status', 'SUCCESS') %>
execution: <% execution() %>
message: <% $.get('message', '') %>
fetch_logs:
description: >
This workflow creates a container on the undercloud, executes the log
collection on the servers whose names match the provided server_name, and
executes the log upload process on all the servers to the container on
the undercloud.
input:
- server_name
- container
- concurrency: 5
- timeout: 1800
- queue_name: tripleo
tags:
- tripleo-common-managed
tasks:
# actions
create_container:
workflow: tripleo.support.v1.create_container
on-success: get_servers_matching
on-error: set_create_container_failed
input:
container: <% $.container %>
queue_name: <% $.queue_name %>
set_create_container_failed:
on-complete: send_message
publish:
type: tripleo.support.v1.fetch_logs.create_container
status: FAILED
message: <% task(create_container).result %>
get_servers_matching:
action: nova.servers_list
on-success: collect_logs_on_servers
publish:
servers_with_name: <% task().result._info.where($.name.indexOf(execution().input.server_name) > -1) %>
collect_logs_on_servers:
workflow: tripleo.support.v1.collect_logs
timeout: <% $.timeout %>
on-success: upload_logs_on_servers
on-error: set_collect_logs_on_servers_failed
input:
server_name: <% $.server_name %>
queue_name: <% $.queue_name %>
set_collect_logs_on_servers_failed:
on-complete: send_message
publish:
type: tripleo.support.v1.fetch_logs.collect_logs_on_servers
status: FAILED
message: <% task(collect_logs_on_servers).result %>
upload_logs_on_servers:
on-success: send_message
on-error: set_upload_logs_on_servers_failed
with-items: server in <% $.servers_with_name %>
concurrency: <% $.concurrency %>
workflow: tripleo.support.v1.upload_logs
input:
server_name: <% $.server.name %>
server_uuid: <% $.server.id %>
container: <% $.container %>
queue_name: <% $.queue_name %>
set_upload_logs_on_servers_failed:
on-complete: send_message
publish:
type: tripleo.support.v1.fetch_logs.upload_logs
status: FAILED
message: <% task(upload_logs_on_servers).result %>
# status messaging
send_message:
workflow: tripleo.messaging.v1.send
input:
queue_name: <% $.queue_name %>
type: <% $.get('type', execution().name) %>
status: <% $.get('status', 'SUCCESS') %>
execution: <% execution() %>
message: <% $.get('message', '') %>