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
This commit is contained in:
Dougal Matthews 2017-12-15 09:27:25 +00:00
parent ea44ebe886
commit b5d5cbab32
5 changed files with 78 additions and 55 deletions

View File

@ -103,16 +103,9 @@ workflows:
on-success: check_status
verify_container_exists:
action: swift.head_container container=<% $.container %>
on-error:
- create_container
on-success:
- wait_for_swift: <% not bool($.deployment_status) %>
- persist_to_swift_plan_latest: <% bool($.deployment_status) %>
- persist_to_swift
create_container:
action: swift.put_container container=<% $.container %>
workflow: tripleo.swift.v1.container_exists container=<% $.container %>
input:
create_container: true
on-success:
- wait_for_swift: <% not bool($.deployment_status) %>
- persist_to_swift_plan_latest: <% bool($.deployment_status) %>
@ -136,7 +129,7 @@ workflows:
wait_for_swift:
# We want persist_to_swift and either persist_to_swift_plan_latest or
# create_container to join here. Two of the three tasks.
# verify_container_exists to join here. Two of the three tasks.
join: 2
on-success: complete_swift

View File

@ -65,17 +65,22 @@ workflows:
- create_plan: <% $.use_default_templates = false and $.source_url = null %>
verify_container_doesnt_exist:
action: swift.head_container container=<% $.container %>
on-success: send_message
on-error: create_container
workflow: tripleo.swift.v1.container_exists
input:
container: <% $.container %>
publish:
status: FAILED
message: "Unable to create plan. The Swift container already exists"
on-success: send_message
on-error: create_container
create_container:
action: tripleo.plan.create_container container=<% $.container %>
on-success: templates_source_check
on-error: create_container_set_status_failed
publish-on-error:
status: FAILED
message: <% task().result %>
on-error: send_message
cleanup_temporary_files:
action: tripleo.git.clean container=<% $.container %>
@ -141,12 +146,6 @@ workflows:
status: SUCCESS
message: 'Plan created.'
create_container_set_status_failed:
on-success: send_message
publish:
status: FAILED
message: <% task(create_container).result %>
clone_git_repo_set_status_failed:
on-success: send_message
publish:
@ -359,9 +358,12 @@ workflows:
tasks:
verify_container_exists:
action: swift.head_container container=<% $.container %>
workflow: tripleo.swift.v1.container_exists container=<% $.container %>
on-success: get_environment_passwords
on-error: verify_container_set_status_failed
publish-on-error:
status: FAILED
message: <% task().result %>
on-error: send_message
get_environment_passwords:
action: tripleo.parameters.get_passwords container=<% $.container %>
@ -380,12 +382,6 @@ workflows:
status: FAILED
message: <% task(get_environment_passwords).result %>
verify_container_set_status_failed:
on-success: send_message
publish:
status: FAILED
message: <% task(verify_container_exists).result %>
send_message:
workflow: tripleo.messaging.v1.send
input:

View File

@ -137,23 +137,14 @@ workflows:
tasks:
check_container:
action: swift.head_container container=<% $.container %>
on-success: send_message
on-error: create_container
create_container:
action: swift.put_container
workflow: tripleo.swift.v1.container_exists
input:
container: <% $.container %>
create_container: true
headers:
x-container-meta-usage-tripleo: support
on-success: send_message
on-error: set_create_container_failed
set_create_container_failed:
on-complete:
- send_message
publish:
on-complete: send_message
publish-on-error:
type: tripleo.support.v1.create_container.create_container
status: FAILED
message: <% task(create_container).result %>
@ -184,16 +175,13 @@ workflows:
tasks:
# actions
check_container:
action: swift.head_container container=<% $.container %>
workflow: tripleo.swift.v1.container_exists container=<% $.container %>
on-success: list_objects
on-error: set_check_container_failure
set_check_container_failure:
on-complete: send_message
publish:
publish-on-error:
status: FAILED
type: tripleo.support.v1.delete_container.check_container
message: <% task(check_container).result %>
message: <% task().result %>
on-error: send_message
list_objects:
action: swift.get_container container=<% $.container %>

49
workbooks/swift.yaml Normal file
View File

@ -0,0 +1,49 @@
---
version: '2.0'
name: tripleo.swift.v1
description: TripleO Swift Utility Workflows
workflows:
container_exists:
description: >-
Verify if a Swift container exists
Given the name of a Swift container this workflow will verify if it
already exists. The workflow will ERROR if it doesn't and end in
SUCCESS if it does.
If create_container: true is passed in, then the container will be
created if it doesn't exist. In this case, if the workflow fails the
container failed to create.
input:
- container
- headers: {}
- create_container: false
tags:
- tripleo-common-managed
tasks:
# We use the "prefix" input to only list the containers starting with
# the container name we want to find. There is no way to do an exact
# match, but this will greatly reduce the possible number of results.
get_containers:
action: swiftservice.list
input:
options:
prefix: <% $.container %>
publish:
container_exists: <% bool(task().result) and $.container in task().result[0].listing.name %>
create_input: <% $.headers and {"container" => $.container, "headers" => $.headers} or {"container" => $.container} %>
on-success:
- succeed: <% $.container_exists %>
- fail: <% not $.create_container and not $.container_exists %>
- create_container: <% $.create_container and not $.container_exists %>
create_container:
action: swift.put_container
input: <% $.create_input %>

View File

@ -22,14 +22,11 @@ workflows:
on-complete: check_container
check_container:
action: swift.head_container container=<% $.swift_rings_container %>
workflow: tripleo.swift.v1.container_exists container=<% $.swift_rings_container %>
input:
create_container: true
on-success: get_tempurl
on-error: create_container
create_container:
action: swift.put_container container=<% $.swift_rings_container %>
on-error: set_create_container_failed
on-success: get_tempurl
get_tempurl:
action: tripleo.swift.tempurl