Add support for calling validations from deployment

The deploy plan and overcloud deploy commands can now enable the usage
of the additional validations that are called via workflows. The
'overcloud deploy' command and the 'plan deploy' command adds a new
'--run-validations' switch.

Change-Id: Ic8f79ca3f0ffdd1d5136f1ef24913281359a7808
Partial-Bug: #1638697
Depends-On: I439361ae20c4e302b83870cdc06a5baa90ea683c
This commit is contained in:
Brad P. Crochet 2017-01-10 13:02:43 -05:00
parent 076df58f30
commit f2422607a9
6 changed files with 45 additions and 17 deletions

View File

@ -0,0 +1,4 @@
---
features:
- Adds the ability for external TripleO validations to
be called during a deployment workflow.

View File

@ -466,7 +466,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
def _fake_heat_deploy(self, stack, stack_name, template_path,
parameters, environments, timeout, tht_root,
env, update_plan_only):
env, update_plan_only, run_validations):
assertEqual(
{'parameter_defaults': {},
'resource_registry': {'Test': u'OS::Heat::None'}}, env)
@ -522,7 +522,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
def _fake_heat_deploy(self, stack, stack_name, template_path,
parameters, environments, timeout, tht_root,
env, update_plan_only):
env, update_plan_only, run_validations):
assertEqual(
{'parameter_defaults': {},
'resource_registry': {'Test': u'OS::Heat::None'}}, env)
@ -762,13 +762,13 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self, mock_heat_deploy_func):
result = self.cmd._try_overcloud_deploy_with_compat_yaml(
'/fake/path', {}, 'overcloud', {}, ['~/overcloud-env.json'], 1,
{}, False)
{}, False, True)
# If it returns None it succeeded
self.assertIsNone(result)
mock_heat_deploy_func.assert_called_once_with(
self.cmd, {}, 'overcloud',
'/fake/path/' + constants.OVERCLOUD_YAML_NAME, {},
['~/overcloud-env.json'], 1, '/fake/path', {}, False)
['~/overcloud-env.json'], 1, '/fake/path', {}, False, True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_heat_deploy', autospec=True)
@ -778,7 +778,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.assertRaises(ValueError,
self.cmd._try_overcloud_deploy_with_compat_yaml,
'/fake/path', mock.ANY, mock.ANY, mock.ANY,
mock.ANY, mock.ANY, mock.ANY, mock.ANY)
mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_heat_deploy', autospec=True)
@ -789,7 +789,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
try:
self.cmd._try_overcloud_deploy_with_compat_yaml(
'/fake/path', mock.ANY, mock.ANY, mock.ANY,
mock.ANY, mock.ANY, mock.ANY, mock.ANY)
mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY)
except ValueError as value_error:
self.assertIn('/fake/path', str(value_error))
@ -1257,7 +1257,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_get_template_contents.return_value = [{}, {}]
self.cmd._heat_deploy(mock_stack, 'mock_stack', '/tmp', {},
{}, 1, '/tmp', {}, True)
{}, 1, '/tmp', {}, True, False)
self.assertFalse(mock_deploy_and_wait.called)

View File

@ -259,9 +259,10 @@ class TestOvercloudDeployPlan(utils.TestCommand):
def test_overcloud_deploy_plan(self, mock_for_stack_ready):
# Setup
arglist = ['overcast']
arglist = ['--run-validations', 'overcast']
verifylist = [
('name', 'overcast')
('name', 'overcast'),
('run_validations', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -282,6 +283,7 @@ class TestOvercloudDeployPlan(utils.TestCommand):
'tripleo.deployment.v1.deploy_plan',
workflow_input={
'container': 'overcast',
'run_validations': True,
'queue_name': 'UUID4'
}
)

View File

@ -200,7 +200,8 @@ class DeployOvercloud(command.Command):
return env_files, localenv
def _heat_deploy(self, stack, stack_name, template_path, parameters,
env_files, timeout, tht_root, env, update_plan_only):
env_files, timeout, tht_root, env, update_plan_only,
run_validations):
"""Verify the Baremetal nodes are available and do a stack update"""
clients = self.app.client_manager
@ -248,7 +249,9 @@ class DeployOvercloud(command.Command):
if not update_plan_only:
deployment.deploy_and_wait(self.log, clients, stack, stack_name,
self.app_args.verbose_level, timeout)
self.app_args.verbose_level,
timeout=timeout,
run_validations=run_validations)
def _load_environment_directories(self, directories):
if os.environ.get('TRIPLEO_ENVIRONMENT_DIRECTORY'):
@ -451,17 +454,20 @@ class DeployOvercloud(command.Command):
self._try_overcloud_deploy_with_compat_yaml(
tht_root, stack, parsed_args.stack, parameters, env_files,
parsed_args.timeout, env, parsed_args.update_plan_only)
parsed_args.timeout, env, parsed_args.update_plan_only,
parsed_args.run_validations)
def _try_overcloud_deploy_with_compat_yaml(self, tht_root, stack,
stack_name, parameters,
env_files, timeout,
env, update_plan_only):
env, update_plan_only,
run_validations):
overcloud_yaml = os.path.join(tht_root, constants.OVERCLOUD_YAML_NAME)
try:
self._heat_deploy(stack, stack_name, overcloud_yaml,
parameters, env_files, timeout,
tht_root, env, update_plan_only)
tht_root, env, update_plan_only,
run_validations)
except ClientException as e:
messages = 'Failed to deploy: %s' % str(e)
raise ValueError(messages)
@ -979,13 +985,22 @@ class DeployOvercloud(command.Command):
'--disable-validations',
action='store_true',
default=False,
help=_('Disable the predeployment validations entirely.'))
help=_('Disable the pre-deployment validations entirely. These '
'validations are the built-in pre-deployment validations. '
'To enable external validations from tripleo-validations, '
'use the --run-validations flag.'))
parser.add_argument(
'--dry-run',
action='store_true',
default=False,
help=_('Only run validations, but do not apply any changes.')
)
parser.add_argument(
'--run-validations',
action='store_true',
default=False,
help=_('Run external validations from the tripleo-validations '
'project.'))
parser.add_argument(
'--skip-postconfig',
action='store_true',

View File

@ -118,6 +118,11 @@ class DeployPlan(command.Command):
parser.add_argument('--timeout', '-t', metavar='<TIMEOUT>',
type=int,
help=_('Deployment timeout in minutes.'))
parser.add_argument('--run-validations', action='store_true',
default=False,
help=_('Run the pre-deployment validations. These '
'external validations are from the TripleO '
'Validations project.'))
return parser
def take_action(self, parsed_args):
@ -130,4 +135,5 @@ class DeployPlan(command.Command):
print("Starting to deploy plan: {}".format(parsed_args.name))
deployment.deploy_and_wait(self.log, clients, stack, parsed_args.name,
self.app_args.verbose_level,
timeout=parsed_args.timeout)
timeout=parsed_args.timeout,
run_validations=parsed_args.run_validations)

View File

@ -44,11 +44,12 @@ def deploy(clients, **workflow_input):
def deploy_and_wait(log, clients, stack, plan_name, verbose_level,
timeout=None):
timeout=None, run_validations=False):
"""Start the deploy and wait for it to finish"""
workflow_input = {
"container": plan_name,
"run_validations": run_validations,
"queue_name": str(uuid.uuid4()),
}