Merge "Drop StackAction related hack from tripleo deploy"
This commit is contained in:
commit
5293382a9f
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
deprecations:
|
||||
- |
|
||||
`force-stack-update` and `force_stack_create` cli arguments
|
||||
for undercloud/standalone deploy has been deprecated and
|
||||
are now irrelevant.
|
|
@ -510,63 +510,6 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
env_files)
|
||||
self.assertEqual(expected, results)
|
||||
|
||||
@mock.patch('time.time', return_value=123)
|
||||
@mock.patch('yaml.safe_load', return_value={}, autospec=True)
|
||||
@mock.patch('yaml.safe_dump', autospec=True)
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('builtins.open')
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_process_hieradata_overrides', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_update_passwords_env', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
|
||||
'_normalize_user_templates', return_value=[], autospec=True)
|
||||
@mock.patch('tripleoclient.utils.rel_or_abs_path', return_value={},
|
||||
autospec=True)
|
||||
@mock.patch('tripleoclient.utils.run_command_and_log', return_value=0,
|
||||
autospec=True)
|
||||
def test_setup_heat_environments_dropin(
|
||||
self, mock_run, mock_paths, mock_norm, mock_update_pass_env,
|
||||
mock_process_hiera, mock_open, mock_os, mock_yaml_dump,
|
||||
mock_yaml_load, mock_time):
|
||||
|
||||
parsed_args = self.check_parser(
|
||||
self.cmd, ['--local-ip', '127.0.0.1/8',
|
||||
'--templates', 'tht_from',
|
||||
'--output-dir', 'tht_to',
|
||||
'--roles-file', '/roles_file,yaml',
|
||||
'--networks-file', '/networks_file.yaml'], [])
|
||||
dropin = 'tht_from/standalone-stack-vstate-dropin.yaml'
|
||||
self.cmd.output_dir = 'tht_to'
|
||||
self.cmd.tht_render = 'tht_from'
|
||||
self.cmd.stack_action = 'UPDATE'
|
||||
environment = self.cmd._setup_heat_environments(
|
||||
parsed_args.roles_file, parsed_args.networks_file, parsed_args)
|
||||
|
||||
self.assertIn(dropin, environment)
|
||||
mock_open.assert_has_calls([mock.call(dropin, 'w')])
|
||||
|
||||
# unpack the dump yaml calls to verify if the produced stack update
|
||||
# dropin matches our expectations
|
||||
found_dropin = False
|
||||
found_identifier = False
|
||||
for call in mock_yaml_dump.call_args_list:
|
||||
args, kwargs = call
|
||||
for a in args:
|
||||
if isinstance(a, mock.MagicMock):
|
||||
continue
|
||||
if a.get('parameter_defaults', {}).get('StackAction', None):
|
||||
self.assertTrue(
|
||||
a['parameter_defaults']['StackAction'] == 'UPDATE')
|
||||
found_dropin = True
|
||||
if a.get('parameter_defaults', {}).get('DeployIdentifier',
|
||||
None):
|
||||
self.assertTrue(
|
||||
a['parameter_defaults']['DeployIdentifier'] == 123)
|
||||
found_identifier = True
|
||||
self.assertTrue(found_dropin)
|
||||
self.assertTrue(found_identifier)
|
||||
|
||||
def _setup_heat_environments(self, tmpdir, tht_from,
|
||||
mock_update_pass_env, mock_run,
|
||||
extra_cmd=None):
|
||||
|
@ -626,7 +569,6 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
os.path.join(tht_render,
|
||||
'tripleoclient-hosts-portmaps.yaml'),
|
||||
'hiera_or.yaml',
|
||||
os.path.join(tht_render, 'standalone-stack-vstate-dropin.yaml'),
|
||||
os.path.join(tht_render, 'foo.yaml'),
|
||||
os.path.join(tht_render, 'outside.yaml')]
|
||||
|
||||
|
@ -984,61 +926,6 @@ class TestDeployUndercloud(TestPluginV1):
|
|||
self.cmd.take_action, parsed_args)
|
||||
mock_copy.assert_called_once()
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=False)
|
||||
def test_set_stack_action_default_create(self, mock_isfile):
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
['--local-ip', '127.0.0.1',
|
||||
'--templates', '/tmp/thtroot',
|
||||
'--stack', 'undercloud',
|
||||
'--output-dir', '/my'], [])
|
||||
self.cmd._set_stack_action(parsed_args)
|
||||
self.assertEqual('CREATE', self.cmd.stack_action)
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
def test_set_stack_action_default_update(self, mock_isfile):
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
['--local-ip', '127.0.0.1',
|
||||
'--templates', '/tmp/thtroot',
|
||||
'--stack', 'undercloud',
|
||||
'--output-dir', '/my'], [])
|
||||
self.cmd._set_stack_action(parsed_args)
|
||||
self.assertEqual('UPDATE', self.cmd.stack_action)
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=False)
|
||||
def test_set_stack_action_force_update(self, mock_isfile):
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
['--local-ip', '127.0.0.1',
|
||||
'--templates', '/tmp/thtroot',
|
||||
'--stack', 'undercloud',
|
||||
'--output-dir', '/my',
|
||||
'--force-stack-update'], [])
|
||||
self.cmd._set_stack_action(parsed_args)
|
||||
self.assertEqual('UPDATE', self.cmd.stack_action)
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
def test_set_stack_action_force_create(self, mock_isfile):
|
||||
parsed_args = self.check_parser(self.cmd,
|
||||
['--local-ip', '127.0.0.1',
|
||||
'--templates', '/tmp/thtroot',
|
||||
'--stack', 'undercloud',
|
||||
'--output-dir', '/my',
|
||||
'--force-stack-create'], [])
|
||||
self.cmd._set_stack_action(parsed_args)
|
||||
self.assertEqual('CREATE', self.cmd.stack_action)
|
||||
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
def test_set_stack_action_mutually_exclusive(self, mock_isfile):
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
['--local-ip', '127.0.0.1',
|
||||
'--templates', '/tmp/thtroot',
|
||||
'--stack', 'undercloud',
|
||||
'--output-dir', '/my',
|
||||
'--force-stack-create',
|
||||
'--force-stack-update'], [])
|
||||
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
@mock.patch('os.chdir')
|
||||
@mock.patch('tripleoclient.utils.reset_cmdline')
|
||||
|
|
|
@ -93,8 +93,6 @@ class Deploy(command.Command):
|
|||
tht_render = None
|
||||
output_dir = None
|
||||
tmp_ansible_dir = None
|
||||
stack_update_mark = None
|
||||
stack_action = 'CREATE'
|
||||
deployment_user = None
|
||||
ansible_dir = None
|
||||
python_version = sys.version_info[0]
|
||||
|
@ -161,18 +159,6 @@ class Deploy(command.Command):
|
|||
else:
|
||||
os.chmod(file_name, mode)
|
||||
|
||||
def _set_stack_action(self, parsed_args):
|
||||
"""Set the stack action for deployment"""
|
||||
# Prepare the heat stack action we want to start deployment with
|
||||
if ((os.path.isfile(self.stack_update_mark) or
|
||||
parsed_args.force_stack_update) and
|
||||
not parsed_args.force_stack_create):
|
||||
self.stack_action = 'UPDATE'
|
||||
|
||||
self.log.warning(
|
||||
_('The heat stack {0} action is {1}').format(
|
||||
parsed_args.stack, self.stack_action))
|
||||
|
||||
def _get_roles_file_path(self, parsed_args):
|
||||
"""Return roles_file for the deployment"""
|
||||
if not parsed_args.roles_file:
|
||||
|
@ -662,12 +648,13 @@ class Deploy(command.Command):
|
|||
else:
|
||||
p_ip = ip
|
||||
|
||||
role_name = self._get_primary_role_name(
|
||||
roles_file_path, parsed_args.templates)
|
||||
tmp_env = self._generate_hosts_parameters(parsed_args, p_ip)
|
||||
tmp_env.update(self._generate_portmap_parameters(
|
||||
ip, ip_nw, c_ip, p_ip,
|
||||
stack_name=parsed_args.stack,
|
||||
role_name=self._get_primary_role_name(
|
||||
roles_file_path, parsed_args.templates)))
|
||||
role_name=role_name))
|
||||
|
||||
user_params = self._load_user_params(user_environments)
|
||||
host_routes = user_params.get('ControlPlaneStaticRoutes', [])
|
||||
|
@ -733,7 +720,6 @@ class Deploy(command.Command):
|
|||
yaml.safe_dump(
|
||||
{'parameter_defaults': {
|
||||
'RootStackName': parsed_args.stack.lower(),
|
||||
'StackAction': self.stack_action,
|
||||
'DeployIdentifier': int(time.time())}},
|
||||
dropin_file, default_flow_style=False)
|
||||
environments.append(stack_vstate_dropin)
|
||||
|
@ -1112,21 +1098,21 @@ class Deploy(command.Command):
|
|||
dest='force_stack_update',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Do a virtual update of the ephemeral "
|
||||
help=_("DEPRECATED: Do a virtual update of the ephemeral "
|
||||
"heat stack (it cannot take real updates). "
|
||||
"New or failed deployments "
|
||||
"always have the stack_action=CREATE. This "
|
||||
"option enforces stack_action=UPDATE."),
|
||||
"option enforces stack_action=UPDATE. Not Supported."),
|
||||
)
|
||||
stack_action_group.add_argument(
|
||||
'--force-stack-create',
|
||||
dest='force_stack_create',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Do a virtual create of the ephemeral "
|
||||
help=_("DEPRECATED: Do a virtual create of the ephemeral "
|
||||
"heat stack. New or failed deployments "
|
||||
"always have the stack_action=CREATE. This "
|
||||
"option enforces stack_action=CREATE."),
|
||||
"option enforces stack_action=CREATE. Not Supported"),
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -1248,16 +1234,6 @@ class Deploy(command.Command):
|
|||
|
||||
is_complete = False
|
||||
try:
|
||||
# NOTE(bogdando): Look for the unique virtual update mark matching
|
||||
# the heat stack name we are going to create below. If found the
|
||||
# mark, consider the stack action is UPDATE instead of CREATE.
|
||||
mark_uuid = '_'.join(['update_mark', parsed_args.stack])
|
||||
self.stack_update_mark = os.path.join(
|
||||
constants.STANDALONE_EPHEMERAL_STACK_VSTATE,
|
||||
mark_uuid)
|
||||
|
||||
self._set_stack_action(parsed_args)
|
||||
|
||||
# Launch heat.
|
||||
orchestration_client = self._launch_heat(parsed_args, output_dir)
|
||||
# Wait for heat to be ready.
|
||||
|
@ -1372,20 +1348,6 @@ class Deploy(command.Command):
|
|||
self.log.warning('Install artifact is located at %s' %
|
||||
tar_filename)
|
||||
if not is_complete:
|
||||
# We only get here on error.
|
||||
# Alter the stack virtual state for failed deployments
|
||||
if (self.stack_update_mark and
|
||||
not parsed_args.force_stack_update and
|
||||
os.path.isfile(self.stack_update_mark)):
|
||||
self.log.warning(
|
||||
_('The heat stack %s virtual state/action is '
|
||||
'reset to CREATE. Use "--force-stack-update" to '
|
||||
'set it forcefully to UPDATE') % parsed_args.stack)
|
||||
self.log.warning(
|
||||
_('Removing the stack virtual update mark file %s') %
|
||||
self.stack_update_mark)
|
||||
os.remove(self.stack_update_mark)
|
||||
|
||||
self.log.error(DEPLOY_FAILURE_MESSAGE.format(
|
||||
self.heat_launch.install_dir
|
||||
))
|
||||
|
@ -1402,27 +1364,6 @@ class Deploy(command.Command):
|
|||
'~/.config/openstack/clouds.yaml')
|
||||
|
||||
self.log.warning(success_messaging)
|
||||
if (self.stack_update_mark and
|
||||
(not parsed_args.output_only or
|
||||
parsed_args.force_stack_update)):
|
||||
# Persist the unique mark file for this stack
|
||||
# Do not update its atime file system attribute to keep its
|
||||
# genuine timestamp for the 1st time the stack state had
|
||||
# been (virtually) changed to match stack_action UPDATE
|
||||
self.log.warning(
|
||||
_('Writing the stack virtual update mark file %s') %
|
||||
self.stack_update_mark)
|
||||
open(self.stack_update_mark, 'w').close()
|
||||
elif parsed_args.output_only:
|
||||
self.log.warning(
|
||||
_('Not creating the stack %s virtual update mark file '
|
||||
'in the --output-only mode! Re-run with '
|
||||
'--force-stack-update, if you want to enforce it.') %
|
||||
parsed_args.stack)
|
||||
else:
|
||||
self.log.warning(
|
||||
_('Not creating the stack %s virtual update mark '
|
||||
'file') % parsed_args.stack)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
|
Loading…
Reference in New Issue