Changes Delete Plan to Call Workflow

This patch updates the code and associated tests to change the
from directly calling the tripleo.plan.delete action to calling
the tripleo.plan_management.v1.delete_deployment_plan workflow.

Change-Id: I6d41f74f9271c17bcae67eb3c09460051f55667f
Depends-On: Ibaf3ee800de56309e014be53e698affc358c9f5a
Partial-Bug: 1640436
This commit is contained in:
Ryan Brady 2018-01-29 18:21:36 -05:00
parent 1e033c98fa
commit af19f35b00
4 changed files with 59 additions and 37 deletions

View File

@ -56,37 +56,50 @@ class TestOvercloudDeletePlan(utils.TestCommand):
self.cmd = overcloud_plan.DeletePlan(self.app, None)
self.app.client_manager.workflow_engine = mock.Mock()
self.tripleoclient = mock.Mock()
self.websocket = mock.Mock()
self.websocket.__enter__ = lambda s: self.websocket
self.websocket.__exit__ = lambda s, *exc: None
self.tripleoclient = mock.Mock()
self.tripleoclient.messaging_websocket.return_value = self.websocket
self.app.client_manager.tripleoclient = self.tripleoclient
self.workflow = self.app.client_manager.workflow_engine
@mock.patch(
'tripleoclient.workflows.plan_management.delete_deployment_plan',
autospec=True)
def test_delete_plan(self, delete_deployment_plan_mock):
def test_delete_plan(self):
parsed_args = self.check_parser(self.cmd, ['test-plan'],
[('plans', ['test-plan'])])
self.websocket.wait_for_messages.return_value = iter([{
"execution": {"id": "IDID"},
"status": "SUCCESS"
}])
self.cmd.take_action(parsed_args)
delete_deployment_plan_mock.assert_called_once_with(
self.workflow,
container='test-plan')
self.workflow.executions.create.assert_called_once_with(
'tripleo.plan_management.v1.delete_deployment_plan',
workflow_input={'container': 'test-plan'})
@mock.patch(
'tripleoclient.workflows.plan_management.delete_deployment_plan',
autospec=True)
def test_delete_multiple_plans(self, delete_deployment_plan_mock):
def test_delete_multiple_plans(self):
argslist = ['test-plan1', 'test-plan2']
verifylist = [('plans', ['test-plan1', 'test-plan2'])]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.websocket.wait_for_messages.return_value = iter([{
"execution": {"id": "IDID"},
"status": "SUCCESS"
}])
self.cmd.take_action(parsed_args)
expected = [
mock.call(self.workflow, container='test-plan1'),
mock.call(self.workflow, container='test-plan2'),
]
self.assertEqual(delete_deployment_plan_mock.call_args_list,
expected)
self.workflow.executions.create.assert_has_calls([
mock.call('tripleo.plan_management.v1.delete_deployment_plan',
workflow_input={'container': 'test-plan1'}),
mock.call('tripleo.plan_management.v1.delete_deployment_plan',
workflow_input={'container': 'test-plan2'}),
], any_order=True)
class TestOvercloudCreatePlan(utils.TestCommand):

View File

@ -175,17 +175,17 @@ class TestPlanCreationWorkflows(utils.TestCommand):
'test-overcloud', 'network_data.yaml', mock_open_context())
def test_delete_plan(self):
self.workflow.action_executions.create.return_value = (
mock.Mock(output='{"result": null}'))
output = mock.Mock(output='{"result": ""}')
self.workflow.action_executions.create.return_value = output
self.websocket.wait_for_messages.return_value = self.message_success
plan_management.delete_deployment_plan(
self.workflow,
container='overcloud')
self.app.client_manager,
container='test-overcloud')
self.workflow.action_executions.create.assert_called_once_with(
'tripleo.plan.delete',
{'container': 'overcloud'},
run_sync=True, save_result=True)
self.workflow.executions.create.assert_called_once_with(
'tripleo.plan_management.v1.delete_deployment_plan',
workflow_input={'container': 'test-overcloud'})
@mock.patch('tripleoclient.workflows.plan_management.tarball',
autospec=True)

View File

@ -67,11 +67,11 @@ class DeletePlan(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
workflow_client = self.app.client_manager.workflow_engine
clients = self.app.client_manager
for plan in parsed_args.plans:
print("Deleting plan %s..." % plan)
plan_management.delete_deployment_plan(workflow_client,
plan_management.delete_deployment_plan(clients,
container=plan)

View File

@ -91,16 +91,25 @@ def create_deployment_plan(clients, **workflow_input):
'Exception creating plan: {}'.format(payload['message']))
def delete_deployment_plan(workflow_client, **input_):
try:
results = base.call_action(workflow_client,
'tripleo.plan.delete',
**input_)
if results is not None:
print(results)
except Exception as err:
raise exceptions.WorkflowServiceError(
'Exception deleting plan: {}'.format(err))
def delete_deployment_plan(clients, **workflow_input):
workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient
execution = base.start_workflow(
workflow_client,
'tripleo.plan_management.v1.delete_deployment_plan',
workflow_input=workflow_input
)
with tripleoclients.messaging_websocket() as ws:
for payload in base.wait_for_messages(workflow_client, ws, execution,
_WORKFLOW_TIMEOUT):
if 'message' in payload:
print(payload['message'])
if payload['status'] != 'SUCCESS':
raise exceptions.WorkflowServiceError(
'Exception deleting plan: {}'.format(payload['message']))
def update_deployment_plan(clients, **workflow_input):