From 943f5504158980853e636bec2c39879f8644f46e Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Wed, 7 Sep 2016 08:09:29 +0100 Subject: [PATCH] Update plan files when re-deploying When doing a second deploy we need to update the plan templates to match those passed into the deploy command. The cleanest way to do this is to remove the existing files in swift and then upload the new files. Closes-Bug: #1620932 Depends-On: I35be5ed5062bb26ca31b55d049780a1423c2ce46 Change-Id: I7620c09005ee35bdb2fff1c77471548bb56baff7 --- tripleoclient/v1/overcloud_deploy.py | 28 ++++++++++----- tripleoclient/workflows/parameters.py | 5 +++ tripleoclient/workflows/plan_management.py | 40 ++++++++++++++++++++-- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 84a792ab3..519814dc6 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -44,7 +44,7 @@ from tripleoclient import constants from tripleoclient import exceptions from tripleoclient import utils from tripleoclient.workflows import deployment -from tripleoclient.workflows import parameters +from tripleoclient.workflows import parameters as workflow_params from tripleoclient.workflows import plan_management @@ -352,8 +352,8 @@ class DeployOvercloud(command.Command): # means the UI can find them. if 'parameter_defaults' in env: params = env.pop('parameter_defaults') - parameters.update_parameters(mistral, container=container_name, - parameters=params) + workflow_params.update_parameters( + mistral, container=container_name, parameters=params) contents = yaml.safe_dump(env) @@ -361,11 +361,13 @@ class DeployOvercloud(command.Command): swift_client.put_object(container_name, swift_path, contents) mistral_env = mistral.environments.get(container_name) - mistral_env.variables['environments'].append({'path': swift_path}) - mistral.environments.update( - name=container_name, - variables=mistral_env.variables - ) + user_env = {'path': swift_path} + if user_env not in mistral_env.variables['environments']: + mistral_env.variables['environments'].append(user_env) + mistral.environments.update( + name=container_name, + variables=mistral_env.variables + ) def _upload_missing_files(self, container_name, swift_client, files_dict, tht_root): @@ -416,7 +418,15 @@ class DeployOvercloud(command.Command): tht_root = parsed_args.templates plans = plan_management.list_deployment_plans(workflow_client) - if parsed_args.stack not in plans: + + # TODO(d0ugal): We need to put a more robust strategy in place here to + # handle updating plans. + if parsed_args.stack in plans: + # Upload the new plan templates to swift to replace the existing + # templates. + plan_management.update_plan_from_templates( + clients, parsed_args.stack, tht_root) + else: plan_management.create_plan_from_templates( clients, parsed_args.stack, tht_root) diff --git a/tripleoclient/workflows/parameters.py b/tripleoclient/workflows/parameters.py index 8fa131a75..1f385106e 100644 --- a/tripleoclient/workflows/parameters.py +++ b/tripleoclient/workflows/parameters.py @@ -16,3 +16,8 @@ from tripleoclient.workflows import base def update_parameters(workflow_client, **input_): return base.call_action(workflow_client, 'tripleo.update_parameters', **input_) + + +def reset_parameters(workflow_client, **input_): + return base.call_action(workflow_client, 'tripleo.parameters.reset', + **input_) diff --git a/tripleoclient/workflows/plan_management.py b/tripleoclient/workflows/plan_management.py index 059cf703a..02cbf3236 100644 --- a/tripleoclient/workflows/plan_management.py +++ b/tripleoclient/workflows/plan_management.py @@ -47,19 +47,25 @@ def create_default_plan(clients, **workflow_input): 'Exception creating plan: {}'.format(payload['message'])) -def create_deployment_plan(clients, **workflow_input): +def _create_update_deployment_plan(clients, workflow, **workflow_input): workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient queue_name = workflow_input['queue_name'] execution = workflow_client.executions.create( - 'tripleo.plan_management.v1.create_deployment_plan', + workflow, workflow_input=workflow_input ) with tripleoclients.messaging_websocket(queue_name) as ws: - payload = ws.wait_for_message(execution.id) + return ws.wait_for_message(execution.id) + + +def create_deployment_plan(clients, **workflow_input): + payload = _create_update_deployment_plan( + clients, 'tripleo.plan_management.v1.create_deployment_plan', + **workflow_input) if payload['status'] == 'SUCCESS': print ("Plan created") @@ -68,6 +74,18 @@ def create_deployment_plan(clients, **workflow_input): 'Exception creating plan: {}'.format(payload['message'])) +def update_deployment_plan(clients, **workflow_input): + payload = _create_update_deployment_plan( + clients, 'tripleo.plan_management.v1.update_deployment_plan', + **workflow_input) + + if payload['status'] == 'SUCCESS': + print ("Plan updated") + else: + raise exceptions.WorkflowServiceError( + 'Exception updating plan: {}'.format(payload['message'])) + + def list_deployment_plans(workflow_client, **input_): return base.call_action(workflow_client, 'tripleo.list_plans', **input_) @@ -87,3 +105,19 @@ def create_plan_from_templates(clients, name, tht_root): _upload_templates(swift_client, name, tht_root) create_deployment_plan(clients, container=name, queue_name=str(uuid.uuid4())) + + +def update_plan_from_templates(clients, name, tht_root): + swift_client = clients.tripleoclient.object_store + + # TODO(dmatthews): Remvoing the exisitng plan files should probably be + # a Mistral action. + print("Removing the current plan files") + headers, objects = swift_client.get_container(name) + for object_ in objects: + swift_client.delete_object(name, object_['name']) + + print("Uploading new plan files") + _upload_templates(swift_client, name, tht_root) + update_deployment_plan(clients, container=name, + queue_name=str(uuid.uuid4()))