Update failures listing to use latest ansible-errors.json location
Since the config-download files are stored per plan name, we don't need to reach for deployment status object and execution any more. This change also updates get_deployment_failures workflow to set status FAILED when an error message is returned from the action. Closes-Bug: 1779093 Change-Id: I49805f1e2ce845b1cebc04df813261cca12ec431
This commit is contained in:
parent
81b022ce03
commit
eec131ee5e
|
@ -16,7 +16,6 @@ import json
|
|||
import logging
|
||||
import os
|
||||
import time
|
||||
import yaml
|
||||
|
||||
from heatclient.common import deployment_utils
|
||||
from heatclient import exc as heat_exc
|
||||
|
@ -300,13 +299,10 @@ class DeploymentFailuresAction(base.TripleOAction):
|
|||
|
||||
def __init__(self,
|
||||
plan=constants.DEFAULT_CONTAINER_NAME,
|
||||
deployment_status_file=constants.DEPLOYMENT_STATUS_FILE,
|
||||
work_dir=constants.MISTRAL_WORK_DIR,
|
||||
ansible_errors_file=constants.ANSIBLE_ERRORS_FILE):
|
||||
super(DeploymentFailuresAction, self).__init__()
|
||||
self.plan = plan
|
||||
self.messages_container = "%s-messages" % self.plan
|
||||
self.deployment_status_file = deployment_status_file
|
||||
self.work_dir = work_dir
|
||||
self.ansible_errors_file = ansible_errors_file
|
||||
|
||||
|
@ -315,25 +311,8 @@ class DeploymentFailuresAction(base.TripleOAction):
|
|||
failures=failures)
|
||||
|
||||
def run(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
|
||||
try:
|
||||
deployment_status_obj = swift.get_object(
|
||||
self.messages_container, self.deployment_status_file)[1]
|
||||
except swiftexceptions.ClientException:
|
||||
return self._format_return(
|
||||
'Swift container %s not found' % self.messages_container)
|
||||
|
||||
try:
|
||||
deployment_status = yaml.safe_load(deployment_status_obj)
|
||||
execution_id = \
|
||||
deployment_status['workflow_status']['payload']['execution_id']
|
||||
except KeyError:
|
||||
return self._format_return(
|
||||
'Execution not found in %s' % self.deployment_status_file)
|
||||
|
||||
try:
|
||||
failures_file = os.path.join(self.work_dir, execution_id,
|
||||
failures_file = os.path.join(self.work_dir, self.plan,
|
||||
self.ansible_errors_file)
|
||||
failures = json.loads(open(failures_file).read())
|
||||
return self._format_return('', failures)
|
||||
|
|
|
@ -510,73 +510,24 @@ class DeploymentFailuresActionTest(base.TestCase):
|
|||
self.plan = 'overcloud'
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.deployment.yaml.safe_load')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('tripleo_common.actions.deployment.open')
|
||||
def test_get_deployment_failures(
|
||||
self, mock_open, mock_obj_client, mock_yaml_load):
|
||||
def test_get_deployment_failures(self, mock_open):
|
||||
|
||||
test_result = dict(host0=["a", "b", "c"])
|
||||
mock_read = mock.MagicMock()
|
||||
mock_read.read.return_value = json.dumps(test_result)
|
||||
mock_open.return_value = mock_read
|
||||
status_return = json.loads('{"workflow_status": {"payload": '
|
||||
'{"execution_id": "foo"}}}')
|
||||
mock_yaml_load.return_value = status_return
|
||||
|
||||
action = deployment.DeploymentFailuresAction(self.plan)
|
||||
result = action.run(self.ctx)
|
||||
|
||||
self.assertEqual(result['failures'], test_result)
|
||||
|
||||
@mock.patch('tripleo_common.actions.deployment.yaml.safe_load')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('tripleo_common.actions.deployment.open')
|
||||
def test_get_deployment_failures_no_container(
|
||||
self, mock_open, mock_obj_client, mock_yaml_load):
|
||||
|
||||
test_result = dict(
|
||||
failures={},
|
||||
message='Swift container overcloud-messages not found')
|
||||
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException("404")
|
||||
mock_obj_client.return_value = swift
|
||||
|
||||
action = deployment.DeploymentFailuresAction(self.plan)
|
||||
result = action.run(self.ctx)
|
||||
|
||||
self.assertEqual(result, test_result)
|
||||
|
||||
@mock.patch('tripleo_common.actions.deployment.yaml.safe_load')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('tripleo_common.actions.deployment.open')
|
||||
def test_get_deployment_failures_no_execution(
|
||||
self, mock_open, mock_obj_client, mock_yaml_load):
|
||||
|
||||
test_result = dict(
|
||||
failures={},
|
||||
message='Execution not found in deployment_status.yaml')
|
||||
|
||||
mock_yaml_load.side_effect = KeyError()
|
||||
|
||||
action = deployment.DeploymentFailuresAction(self.plan)
|
||||
result = action.run(self.ctx)
|
||||
|
||||
self.assertEqual(result, test_result)
|
||||
|
||||
@mock.patch('tripleo_common.actions.deployment.yaml.safe_load')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('tripleo_common.actions.deployment.open')
|
||||
def test_get_deployment_failures_no_file(
|
||||
self, mock_open, mock_obj_client, mock_yaml_load):
|
||||
def test_get_deployment_failures_no_file(self, mock_open):
|
||||
|
||||
mock_open.side_effect = IOError()
|
||||
|
||||
status_return = json.loads('{"workflow_status": {"payload": '
|
||||
'{"execution_id": "foo"}}}')
|
||||
mock_yaml_load.return_value = status_return
|
||||
|
||||
action = deployment.DeploymentFailuresAction(self.plan)
|
||||
result = action.run(self.ctx)
|
||||
|
||||
|
|
|
@ -769,7 +769,9 @@ workflows:
|
|||
input:
|
||||
plan: <% $.plan %>
|
||||
publish:
|
||||
deployment_failures: <% task().result %>
|
||||
deployment_failures: <% task().result.failures %>
|
||||
message: <% task().result.message %>
|
||||
status: <% task().result.message and "FAILED" or "SUCCESS" %>
|
||||
on-complete: send_message
|
||||
publish-on-error:
|
||||
status: FAILED
|
||||
|
|
Loading…
Reference in New Issue