Fix deploy templates arg validation
With the addition of the vip file validation, we broke the check for the templates arg resulting in a stack trace if templates is not provided rather then a user friendly error message. This change moves the vip file validation to it's own check later in the process once the working directory has been created. The working directory is not created until after the validation of params. Change-Id: I67b7dc71542533607e3280b4fac3acfb95203b41 Closes-Bug: #1955573
This commit is contained in:
parent
294e42f599
commit
6e0f514c8f
|
@ -287,6 +287,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_vip_file')
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_args')
|
||||
@mock.patch('heatclient.common.template_utils.get_template_contents',
|
||||
autospec=True)
|
||||
|
@ -296,6 +297,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
@mock.patch('tripleoclient.utils.makedirs')
|
||||
def test_tht_deploy(self, mock_md, mock_tmpdir, mock_cd, mock_chmod,
|
||||
mock_get_template_contents, mock_validate_args,
|
||||
mock_validate_vip_file,
|
||||
mock_breakpoints_cleanup, mock_postconfig,
|
||||
mock_invoke_plan_env_wf,
|
||||
mock_get_undercloud_host_entry,
|
||||
|
@ -367,8 +369,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
utils_overcloud_fixture.mock_deploy_tht.assert_called_with(
|
||||
output_dir=self.cmd.working_dir)
|
||||
|
||||
mock_validate_args.assert_called_once_with(parsed_args,
|
||||
self.cmd.working_dir)
|
||||
mock_validate_args.assert_called_once_with(parsed_args)
|
||||
mock_validate_vip_file.assert_not_called()
|
||||
self.assertFalse(mock_invoke_plan_env_wf.called)
|
||||
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
|
@ -398,6 +400,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env',
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_vip_file')
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_args')
|
||||
@mock.patch('tripleoclient.utils.create_parameters_env', autospec=True)
|
||||
@mock.patch('heatclient.common.template_utils.get_template_contents',
|
||||
|
@ -408,6 +411,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
self, mock_tmpdir, mock_rm,
|
||||
mock_get_template_contents,
|
||||
mock_create_parameters_env, mock_validate_args,
|
||||
mock_validate_vip_file,
|
||||
mock_breakpoints_cleanup,
|
||||
mock_postconfig, mock_stack_network_check,
|
||||
mock_ceph_fsid, mock_swift_rgw, mock_ceph_ansible,
|
||||
|
@ -710,10 +714,9 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
working_dir = self.tmp_dir.join('working_dir')
|
||||
self.assertRaises(oscexc.CommandError,
|
||||
overcloud_deploy._validate_args,
|
||||
parsed_args, working_dir)
|
||||
parsed_args)
|
||||
|
||||
@mock.patch('os.path.isfile', autospec=True)
|
||||
def test_validate_args_missing_rendered_files(self, mock_isfile):
|
||||
|
@ -728,9 +731,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
|
||||
mock_isfile.side_effect = [False, True]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
working_dir = self.tmp_dir.join('working_dir')
|
||||
|
||||
overcloud_deploy._validate_args(parsed_args, working_dir)
|
||||
overcloud_deploy._validate_args(parsed_args)
|
||||
calls = [mock.call(env_path),
|
||||
mock.call(env_path.replace(".yaml", ".j2.yaml"))]
|
||||
mock_isfile.assert_has_calls(calls)
|
||||
|
@ -943,6 +945,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
|
||||
'_deploy_postconfig', autospec=True)
|
||||
@mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env')
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_vip_file')
|
||||
@mock.patch('tripleoclient.v1.overcloud_deploy._validate_args')
|
||||
@mock.patch('tripleoclient.utils.create_parameters_env', autospec=True)
|
||||
@mock.patch('tripleoclient.utils.create_tempest_deployer_input',
|
||||
|
@ -956,6 +959,7 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
mock_create_tempest_deployer_input,
|
||||
mock_create_parameters_env,
|
||||
mock_validate_args,
|
||||
mock_validate_vip_file,
|
||||
mock_breakpoints_cleanup,
|
||||
mock_deploy_post_config,
|
||||
mock_stack_network_check,
|
||||
|
@ -1054,8 +1058,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
mock_create_tempest_deployer_input.assert_called_with(
|
||||
output_dir=self.cmd.working_dir)
|
||||
|
||||
mock_validate_args.assert_called_once_with(parsed_args,
|
||||
self.cmd.working_dir)
|
||||
mock_validate_args.assert_called_once_with(parsed_args)
|
||||
mock_validate_vip_file.assert_not_called()
|
||||
mock_copy.assert_called_once()
|
||||
|
||||
@mock.patch('tripleoclient.utils.get_rc_params', autospec=True)
|
||||
|
|
|
@ -69,7 +69,7 @@ def _update_args_from_answers_file(parsed_args):
|
|||
parsed_args.environment_files = answers['environments']
|
||||
|
||||
|
||||
def _validate_args(parsed_args, working_dir):
|
||||
def _validate_args(parsed_args):
|
||||
if parsed_args.templates is None and parsed_args.answers_file is None:
|
||||
raise oscexc.CommandError(
|
||||
"You must specify either --templates or --answers-file")
|
||||
|
@ -124,15 +124,15 @@ def _validate_args(parsed_args, working_dir):
|
|||
"mean {}?".format(' -e '.join(jinja2_envs),
|
||||
' -e '.join(rewritten_paths)))
|
||||
|
||||
if parsed_args.vip_file:
|
||||
# Check vip_file only used with network data v2
|
||||
networks_file_path = utils.get_networks_file_path(working_dir,
|
||||
parsed_args.stack)
|
||||
if not utils.is_network_data_v2(networks_file_path):
|
||||
raise oscexc.CommandError(
|
||||
'The --vip-file option can only be used in combination with a '
|
||||
'network data v2 format networks file. The provided file {} '
|
||||
'is network data v1 format'.format(networks_file_path))
|
||||
|
||||
def _validate_vip_file(stack, working_dir):
|
||||
# Check vip_file only used with network data v2
|
||||
networks_file_path = utils.get_networks_file_path(working_dir, stack)
|
||||
if not utils.is_network_data_v2(networks_file_path):
|
||||
raise oscexc.CommandError(
|
||||
'The --vip-file option can only be used in combination with a '
|
||||
'network data v2 format networks file. The provided file {} '
|
||||
'is network data v1 format'.format(networks_file_path))
|
||||
|
||||
|
||||
class DeployOvercloud(command.Command):
|
||||
|
@ -1081,19 +1081,22 @@ class DeployOvercloud(command.Command):
|
|||
|
||||
_update_args_from_answers_file(parsed_args)
|
||||
|
||||
_validate_args(parsed_args)
|
||||
|
||||
# Make a copy of the files provided on command line in the working dir
|
||||
# If the command is re-run without providing the argument the "backup"
|
||||
# from the previous run in the working dir is used.
|
||||
utils.update_working_dir_defaults(self.working_dir, parsed_args)
|
||||
|
||||
if parsed_args.vip_file:
|
||||
_validate_vip_file(parsed_args.stack, self.working_dir)
|
||||
|
||||
# Throw warning if deprecated service is enabled and
|
||||
# ask user if deployment should still be continued.
|
||||
if parsed_args.environment_files:
|
||||
utils.check_deprecated_service_is_enabled(
|
||||
parsed_args.environment_files)
|
||||
|
||||
_validate_args(parsed_args, self.working_dir)
|
||||
|
||||
if parsed_args.dry_run:
|
||||
self.log.info("Validation Finished")
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue