Merge "Fix deploy templates arg validation"

This commit is contained in:
Zuul 2022-01-06 18:20:02 +00:00 committed by Gerrit Code Review
commit 467ea5b877
2 changed files with 27 additions and 20 deletions

View File

@ -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)
@ -946,6 +948,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',
@ -959,6 +962,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,
@ -1057,8 +1061,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)

View File

@ -68,7 +68,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")
@ -123,15 +123,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):
@ -1080,19 +1080,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