From 56ecf27f57b28410f7358034d0f471cd2d1088c6 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 17 Feb 2020 09:37:38 -0600 Subject: [PATCH] Remove mistral from the deploy_on_servers workflow This change removes all of mistral from the deploy_on_servers workflow by calling the required functions directly within the command where it is used. Unused methods have been removed from the package_update module. Task: 38439 Story: 2007212 Change-Id: Ife5661fc68961cabb784aa57cccd0a355986fa50 Signed-off-by: Kevin Carter --- tripleoclient/tests/fakes.py | 3 +- .../test_overcloud_ffwd_upgrade.py | 7 +++ tripleoclient/v1/overcloud_execute.py | 58 +++++++++---------- tripleoclient/v1/overcloud_ffwd_upgrade.py | 24 ++++++-- tripleoclient/workflows/package_update.py | 23 -------- 5 files changed, 55 insertions(+), 60 deletions(-) diff --git a/tripleoclient/tests/fakes.py b/tripleoclient/tests/fakes.py index 12489423e..ec342e831 100644 --- a/tripleoclient/tests/fakes.py +++ b/tripleoclient/tests/fakes.py @@ -156,7 +156,8 @@ class FakePlaybookExecution(utils.TestCommand): self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN") self.app.client_manager.baremetal = mock.Mock() - self.app.client_manager.compute = mock.Mock() + compute = self.app.client_manager.compute = mock.Mock() + compute.servers.list.return_value = [] self.app.client_manager.identity = mock.Mock() self.app.client_manager.image = mock.Mock() self.app.client_manager.network = mock.Mock() diff --git a/tripleoclient/tests/v1/overcloud_ffwd_upgrade/test_overcloud_ffwd_upgrade.py b/tripleoclient/tests/v1/overcloud_ffwd_upgrade/test_overcloud_ffwd_upgrade.py index 10594e289..75a1ae037 100644 --- a/tripleoclient/tests/v1/overcloud_ffwd_upgrade/test_overcloud_ffwd_upgrade.py +++ b/tripleoclient/tests/v1/overcloud_ffwd_upgrade/test_overcloud_ffwd_upgrade.py @@ -35,6 +35,13 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare): uuid4_patcher = mock.patch('uuid.uuid4', return_value="UUID4") self.mock_uuid4 = uuid4_patcher.start() self.addCleanup(self.mock_uuid4.stop) + deploy_action = mock.patch( + 'tripleo_common.actions.deployment.OrchestrationDeployAction.run', + autospec=True + ) + deploy_action.start() + deploy_action.return_value = mock.Mock(is_success=True) + self.addCleanup(deploy_action.stop) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' 'take_action') diff --git a/tripleoclient/v1/overcloud_execute.py b/tripleoclient/v1/overcloud_execute.py index f44e48035..b55c839d9 100644 --- a/tripleoclient/v1/overcloud_execute.py +++ b/tripleoclient/v1/overcloud_execute.py @@ -18,7 +18,10 @@ import logging import os.path import re +from tripleo_common.actions import deployment as deployment_actions + from tripleoclient import command +from tripleoclient import exceptions class RemoteExecute(command.Command): @@ -39,45 +42,36 @@ class RemoteExecute(command.Command): def take_action(self, parsed_args): - self.log.debug("take_action(%s)" % parsed_args) + self.log.debug("take_action({})".format(parsed_args)) config = parsed_args.file_in.read() parsed_args.file_in.close() - workflow_client = self.app.client_manager.workflow_engine tripleoclients = self.app.client_manager.tripleoclient - messaging_websocket = tripleoclients.messaging_websocket() # no special characters here - config_name = re.sub('[^\w]*', '', - os.path.basename(parsed_args.file_in.name)) + config_name = re.sub( + r'[^\w]*', '', os.path.basename(parsed_args.file_in.name) + ) if not parsed_args.server_name: raise Exception('Please specify the -s (--server_name) option.') - workflow_input = { - 'server_name': parsed_args.server_name, - 'config_name': config_name, - 'group': parsed_args.group, - 'config': config - } - - workflow_client.executions.create( - 'tripleo.deployment.v1.deploy_on_servers', - workflow_input=workflow_input + context = tripleoclients.create_mistral_context() + init_deploy = deployment_actions.OrchestrationDeployAction( + server_id=self.app.client_manager.compute.servers.list( + search_opts={ + 'name': parsed_args.server_name + } + ), + config=config, + name=config_name, + group=parsed_args.group ) - - while True: - body = messaging_websocket.recv()['body'] - if 'tripleo.deployment.v1.deploy_on_server' == body['type']: - payload = body['payload'] - status = 'SUCCESS' - if payload['status_code'] != 0: - status = 'FAILED' - print('%s :: -- %s --' % (payload['server_name'], status)) - if payload['stdout']: - print('stdout\n: %s\n' % payload['stdout']) - if payload['stderr']: - print('stderr\n: %s\n' % payload['stderr']) - if 'tripleo.deployment.v1.deploy_on_servers' == body['type']: - break - - messaging_websocket.cleanup() + init_deploy_return = init_deploy.run(context=context) + if init_deploy_return.is_success(): + print(init_deploy_return) + else: + raise exceptions.DeploymentError( + 'Execution failed: {}'.format( + init_deploy_return + ) + ) diff --git a/tripleoclient/v1/overcloud_ffwd_upgrade.py b/tripleoclient/v1/overcloud_ffwd_upgrade.py index be3a9cef6..9e9e90ea3 100644 --- a/tripleoclient/v1/overcloud_ffwd_upgrade.py +++ b/tripleoclient/v1/overcloud_ffwd_upgrade.py @@ -18,8 +18,11 @@ from oslo_log import log as logging from osc_lib.i18n import _ from osc_lib import utils +from tripleo_common.actions import deployment as deployment_actions + from tripleoclient import command from tripleoclient import constants +from tripleoclient import exceptions from tripleoclient import utils as oooutils from tripleoclient.v1.overcloud_deploy import DeployOvercloud from tripleoclient.workflows import deployment @@ -62,10 +65,23 @@ class FFWDUpgradePrepare(DeployOvercloud): stack_name = stack.stack_name # ffwd-upgrade "init" run command on overcloud nodes - package_update.run_on_nodes( - clients, server_name='all', - config_name='ffwd-upgrade-prepare', - config=constants.FFWD_UPGRADE_PREPARE_SCRIPT, group='script') + context = clients.tripleoclient.create_mistral_context() + jobs = dict() + for server in clients.compute.servers.list(): + init_deploy = deployment_actions.OrchestrationDeployAction( + server_id=server.id, + config=constants.FFWD_UPGRADE_PREPARE_SCRIPT, + name='ffwd-upgrade-prepare' + ) + init_deploy_return = init_deploy.run(context=context) + jobs[server.name] = init_deploy_return.is_success() + + if jobs and any([not i for i in jobs.values() if not i]): + raise exceptions.DeploymentError( + 'The following nodes failed: {}'.format( + [k for k, v in jobs.items() if not v] + ) + ) # In case of update and upgrade we need to force the # update_plan_only. The heat stack update is done by the diff --git a/tripleoclient/workflows/package_update.py b/tripleoclient/workflows/package_update.py index 5587842b8..09be2ca3e 100644 --- a/tripleoclient/workflows/package_update.py +++ b/tripleoclient/workflows/package_update.py @@ -11,7 +11,6 @@ # under the License. from __future__ import print_function -import pprint import time from heatclient.common import event_utils @@ -20,7 +19,6 @@ from tripleo_common.actions import package_update from tripleoclient import exceptions from tripleoclient import utils -from tripleoclient.workflows import base _WORKFLOW_TIMEOUT = 120 * 60 # 2h @@ -107,24 +105,3 @@ def update(clients, container): ' `openstack --os-cloud undercloud stack failures list {}`' ' to investigate these failures further.'.format(container) ) - - -def run_on_nodes(clients, **workflow_input): - workflow_client = clients.workflow_engine - tripleoclients = clients.tripleoclient - - with tripleoclients.messaging_websocket() as ws: - execution = base.start_workflow( - workflow_client, - 'tripleo.deployment.v1.deploy_on_servers', - workflow_input=workflow_input - ) - - for payload in base.wait_for_messages(workflow_client, ws, execution, - _WORKFLOW_TIMEOUT): - assert payload['status'] == "SUCCESS", pprint.pformat(payload) - - if payload['status'] == "SUCCESS": - print('Success') - else: - raise RuntimeError('run on nodes failed: {}'.format(payload))