Action lifecycle mapping include unknown

When a dag_status is not in the known list of statuses, indicate
unknown, and include the returned status parenthetically.

Change-Id: I42a083433e26c6f48aa4ef8195f0df03d1567d71
This commit is contained in:
Bryan Strassner 2017-11-07 10:39:10 -06:00
parent 2a826d5a43
commit ccebbeb5ef
4 changed files with 39 additions and 27 deletions

1
.gitignore vendored
View File

@ -103,6 +103,7 @@ ENV/
# Generated bogus docs
ChangeLog
AUTHORS
# build/lint artifacts
/charts/shipyard/charts

14
AUTHORS
View File

@ -1,14 +0,0 @@
Alan Meadows <alan.meadows@gmail.com>
Anthony Lin <anthony.jclin@gmail.com>
Bryan Strassner <bryan.strassner@gmail.com>
Felipe Monteiro <felipe.monteiro@att.com>
Hassan Kaous <hkyq8@mst.edu>
Mark Burnett <mark.m.burnett@gmail.com>
One-Fine-Day <vd789v@att.com>
Pete Birley <pete@port.direct>
Rodolfo <rp2723@att.com>
Scott Hussey <sh8121@att.com>
Stacey Fletcher <staceylynnfletcher@gmail.com>
Tin Lam <tin@irrational.io>
Vamsi Krishna Surapureddi <vamsi.skrishna@gmail.com>
eanylin <anthony.jclin@gmail.com>

View File

@ -11,9 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Common methods for use by action api classes as necessary
"""
""" Common methods for use by action api classes as necessary """
DAG_STATE_MAPPING = {
'QUEUED': 'Pending',
@ -32,18 +30,17 @@ DAG_STATE_MAPPING = {
def determine_lifecycle(dag_status=None):
"""
Convert a dag_status to an action_lifecycle value
"""
""" Convert a dag_status to an action_lifecycle value """
if dag_status is None:
dag_status = 'NONE'
return DAG_STATE_MAPPING.get(dag_status.upper())
lifecycle = DAG_STATE_MAPPING.get(dag_status.upper())
if lifecycle is None:
lifecycle = 'Unknown ({})'.format(dag_status)
return lifecycle
def format_action_steps(action_id, steps):
"""
Converts a list of action step database records to desired format
"""
""" Converts a list of action step db records to desired format """
if not steps:
return []
steps_response = []
@ -55,9 +52,7 @@ def format_action_steps(action_id, steps):
def format_step(action_id, step, index):
"""
reformat a step (dictionary) into a common response format
"""
""" reformat a step (dictionary) into a common response format """
return {
'url': '/actions/{}/steps/{}'.format(action_id, step.get('task_id')),
'state': step.get('state'),

View File

@ -0,0 +1,30 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Tests for the action_helper.py module """
from shipyard_airflow.control.action import action_helper
def test_determine_lifecycle():
dag_statuses = [
{'input': 'queued', 'expected': 'Pending'},
{'input': 'ShUTdown', 'expected': 'Failed'},
{'input': 'RUNNING', 'expected': 'Processing'},
{'input': 'None', 'expected': 'Pending'},
{'input': None, 'expected': 'Pending'},
{'input': 'bogusBroken', 'expected': 'Unknown (bogusBroken)'},
]
for status_pair in dag_statuses:
assert(status_pair['expected'] ==
action_helper.determine_lifecycle(status_pair['input']))