Use ansible playbook for plan deploy
Depends-On: https://review.opendev.org/713641 Depends-On: https://review.opendev.org/714280 Change-Id: I9b9488672293558747c6dc41eb6d41c18bdc9e05
This commit is contained in:
parent
4a55e5b9c2
commit
becee11a5a
|
@ -531,7 +531,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||||
clients.tripleoclient.object_store, mock.ANY, 'overcloud')
|
clients.tripleoclient.object_store, mock.ANY, 'overcloud')
|
||||||
|
|
||||||
workflow_client.action_executions.create.assert_called()
|
workflow_client.action_executions.create.assert_called()
|
||||||
workflow_client.executions.create.assert_called()
|
# workflow_client.executions.create.assert_called()
|
||||||
|
|
||||||
mock_open_context.assert_has_calls(
|
mock_open_context.assert_has_calls(
|
||||||
[mock.call('the-plan-environment.yaml')])
|
[mock.call('the-plan-environment.yaml')])
|
||||||
|
|
|
@ -250,56 +250,44 @@ class TestOvercloudDeployPlan(utils.TestCommand):
|
||||||
app_args.verbose_level = 1
|
app_args.verbose_level = 1
|
||||||
self.cmd = overcloud_plan.DeployPlan(self.app, app_args)
|
self.cmd = overcloud_plan.DeployPlan(self.app, app_args)
|
||||||
|
|
||||||
self.workflow = self.app.client_manager.workflow_engine = mock.Mock()
|
|
||||||
execution = mock.Mock()
|
|
||||||
execution.id = "IDID"
|
|
||||||
self.workflow.executions.create.return_value = execution
|
|
||||||
self.orch = self.app.client_manager.orchestration = 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
|
|
||||||
|
|
||||||
sleep_patch = mock.patch('time.sleep')
|
sleep_patch = mock.patch('time.sleep')
|
||||||
self.addCleanup(sleep_patch.stop)
|
self.addCleanup(sleep_patch.stop)
|
||||||
sleep_patch.start()
|
sleep_patch.start()
|
||||||
|
|
||||||
|
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
|
||||||
@mock.patch('tripleoclient.utils.wait_for_stack_ready', autospec=True)
|
@mock.patch('tripleoclient.utils.wait_for_stack_ready', autospec=True)
|
||||||
def test_overcloud_deploy_plan(self, mock_for_stack_ready):
|
def test_overcloud_deploy_plan(self, mock_for_stack_ready,
|
||||||
|
mock_run_playbook):
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
arglist = ['--run-validations', 'overcast']
|
arglist = ['--run-validations', 'overcast']
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('name', 'overcast'),
|
('name', 'overcast'),
|
||||||
('run_validations', True),
|
('run_validations', True),
|
||||||
|
('timeout', 240)
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.orch = self.app.client_manager.orchestration = mock.Mock()
|
||||||
# No existing stack, this is a new deploy.
|
# No existing stack, this is a new deploy.
|
||||||
self.orch.stacks.get.return_value = None
|
self.orch.stacks.get.return_value = None
|
||||||
|
|
||||||
self.websocket.wait_for_messages.return_value = iter([{
|
|
||||||
'execution_id': 'IDID',
|
|
||||||
'status': 'SUCCESS'
|
|
||||||
}])
|
|
||||||
|
|
||||||
mock_for_stack_ready.return_value = True
|
mock_for_stack_ready.return_value = True
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
# Verify
|
mock_run_playbook.assert_called_once_with(
|
||||||
self.workflow.executions.create.assert_called_once_with(
|
'cli-deploy-deployment-plan.yaml',
|
||||||
'tripleo.deployment.v1.deploy_plan',
|
'undercloud,',
|
||||||
workflow_input={
|
constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||||
'container': 'overcast',
|
extra_vars={
|
||||||
'run_validations': True,
|
"container": "overcast",
|
||||||
'skip_deploy_identifier': False,
|
"run_validations": True,
|
||||||
'deployment_options': {},
|
"skip_deploy_identifier": False,
|
||||||
}
|
"timeout_mins": 240
|
||||||
|
},
|
||||||
|
verbosity=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,27 +150,16 @@ class TestDeploymentWorkflows(utils.TestCommand):
|
||||||
|
|
||||||
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
@mock.patch('tripleoclient.utils.run_ansible_playbook',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
@mock.patch('tripleoclient.workflows.deployment.base')
|
|
||||||
def test_config_download_already_in_progress_for_diff_stack(
|
def test_config_download_already_in_progress_for_diff_stack(
|
||||||
self, mock_base, mock_playbook):
|
self, mock_playbook):
|
||||||
log = mock.Mock()
|
log = mock.Mock()
|
||||||
stack = mock.Mock()
|
stack = mock.Mock()
|
||||||
stack.stack_name = 'stacktest'
|
stack.stack_name = 'stacktest'
|
||||||
stack.output_show.return_value = {'output': {'output_value': []}}
|
stack.output_show.return_value = {'output': {'output_value': []}}
|
||||||
clients = mock.Mock()
|
clients = mock.Mock()
|
||||||
mock_execution = mock.Mock()
|
|
||||||
mock_execution.input = '{"plan_name": "someotherstack"}'
|
|
||||||
mock_return = mock.Mock(return_value=[mock_execution])
|
|
||||||
clients.workflow_engine.executions.find = mock_return
|
|
||||||
mock_exit = mock.Mock()
|
|
||||||
mock_exit.__exit__ = mock.Mock()
|
|
||||||
mock_exit.__enter__ = mock.Mock()
|
|
||||||
clients.tripleoclient.messaging_websocket = mock.Mock(
|
|
||||||
return_value=mock_exit)
|
|
||||||
mock_base.wait_for_messages = mock.Mock(
|
|
||||||
return_value=[dict(status='SUCCESS')])
|
|
||||||
|
|
||||||
deployment.config_download(
|
deployment.config_download(
|
||||||
log, clients, stack, 'templates', 'ssh_user',
|
log, clients, stack, 'templates', 'ssh_user',
|
||||||
'ssh_key', 'ssh_networks', 'output_dir', False,
|
'ssh_key', 'ssh_networks', 'output_dir', False,
|
||||||
'timeout')
|
'timeout')
|
||||||
|
|
||||||
|
self.assertEqual(2, mock_playbook.call_count)
|
||||||
|
|
|
@ -146,7 +146,7 @@ class DeployPlan(command.Command):
|
||||||
parser = super(DeployPlan, self).get_parser(prog_name)
|
parser = super(DeployPlan, self).get_parser(prog_name)
|
||||||
parser.add_argument('name', help=_('The name of the plan to deploy.'))
|
parser.add_argument('name', help=_('The name of the plan to deploy.'))
|
||||||
parser.add_argument('--timeout', '-t', metavar='<TIMEOUT>',
|
parser.add_argument('--timeout', '-t', metavar='<TIMEOUT>',
|
||||||
type=int,
|
type=int, default=240,
|
||||||
help=_('Deployment timeout in minutes.'))
|
help=_('Deployment timeout in minutes.'))
|
||||||
parser.add_argument('--run-validations', action='store_true',
|
parser.add_argument('--run-validations', action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
|
|
|
@ -14,7 +14,6 @@ from __future__ import print_function
|
||||||
import copy
|
import copy
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import pprint
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -31,39 +30,25 @@ from tripleoclient.constants import DEFAULT_WORK_DIR
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
|
|
||||||
from tripleoclient.workflows import base
|
|
||||||
|
|
||||||
|
|
||||||
_WORKFLOW_TIMEOUT = 360 # 6 * 60 seconds
|
_WORKFLOW_TIMEOUT = 360 # 6 * 60 seconds
|
||||||
|
|
||||||
|
|
||||||
def deploy(log, clients, **workflow_input):
|
def deploy(log, clients, **workflow_input):
|
||||||
|
utils.run_ansible_playbook(
|
||||||
|
"cli-deploy-deployment-plan.yaml",
|
||||||
|
'undercloud,',
|
||||||
|
ANSIBLE_TRIPLEO_PLAYBOOKS,
|
||||||
|
extra_vars={
|
||||||
|
"container": workflow_input['container'],
|
||||||
|
"run_validations": workflow_input['run_validations'],
|
||||||
|
"skip_deploy_identifier": workflow_input['skip_deploy_identifier'],
|
||||||
|
"timeout_mins": workflow_input['timeout'],
|
||||||
|
},
|
||||||
|
verbosity=3
|
||||||
|
)
|
||||||
|
|
||||||
workflow_client = clients.workflow_engine
|
print("Success.")
|
||||||
tripleoclients = clients.tripleoclient
|
|
||||||
wf_name = 'tripleo.deployment.v1.deploy_plan'
|
|
||||||
|
|
||||||
with tripleoclients.messaging_websocket() as ws:
|
|
||||||
execution = base.start_workflow(
|
|
||||||
workflow_client,
|
|
||||||
wf_name,
|
|
||||||
workflow_input=workflow_input
|
|
||||||
)
|
|
||||||
|
|
||||||
# The deploy workflow ends once the Heat create/update starts. This
|
|
||||||
# means that is shouldn't take very long. Wait for 10 minutes for
|
|
||||||
# messages from the workflow.
|
|
||||||
for payload in base.wait_for_messages(workflow_client, ws, execution,
|
|
||||||
600):
|
|
||||||
status = payload.get('status', 'RUNNING')
|
|
||||||
message = payload.get('message')
|
|
||||||
if message and status == "RUNNING":
|
|
||||||
print(message)
|
|
||||||
elif payload['status'] != "SUCCESS":
|
|
||||||
log.info(pprint.pformat(payload))
|
|
||||||
print(payload['message'])
|
|
||||||
raise ValueError("Unexpected status %s for %s"
|
|
||||||
% (payload['status'], wf_name))
|
|
||||||
|
|
||||||
|
|
||||||
def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
|
def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
|
||||||
|
@ -75,7 +60,7 @@ def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
|
||||||
"container": plan_name,
|
"container": plan_name,
|
||||||
"run_validations": run_validations,
|
"run_validations": run_validations,
|
||||||
"skip_deploy_identifier": skip_deploy_identifier,
|
"skip_deploy_identifier": skip_deploy_identifier,
|
||||||
"deployment_options": deployment_options,
|
"timeout": timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
|
@ -83,6 +68,7 @@ def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
|
||||||
|
|
||||||
deploy(log, clients, **workflow_input)
|
deploy(log, clients, **workflow_input)
|
||||||
|
|
||||||
|
# need to move this to the playbook I guess
|
||||||
orchestration_client = clients.orchestration
|
orchestration_client = clients.orchestration
|
||||||
|
|
||||||
if stack is None:
|
if stack is None:
|
||||||
|
|
Loading…
Reference in New Issue