Merge "Use same code path for UpdatePrepare"

This commit is contained in:
Zuul 2021-01-14 03:11:41 +00:00 committed by Gerrit Code Review
commit 34dccbccc2
3 changed files with 13 additions and 103 deletions

View File

@ -44,25 +44,19 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_get_undercloud_host_entry', autospec=True,
return_value='192.168.0.1 uc.ctlplane.localhost uc.ctlplane')
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@mock.patch('tripleoclient.v1.overcloud_update.UpdatePrepare.log',
autospec=True)
@mock.patch('tripleoclient.workflows.package_update.update',
autospec=True)
@mock.patch('os.path.abspath')
@mock.patch('yaml.safe_load')
@mock.patch('shutil.copytree', autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_tripleo_heat_templates_tmpdir', autospec=True)
'take_action', autospec=True)
def test_update_out(self, mock_deploy, mock_open, mock_copy, mock_yaml,
mock_abspath, mock_update, mock_logger,
mock_get_stack, mock_get_undercloud_host_entry,
mock_confirm, mock_usercheck, mock_get_ctlplane_attrs):
mock_stack = mock.Mock(parameters={'DeployIdentifier': ''})
mock_stack.stack_name = 'overcloud'
mock_get_stack.return_value = mock_stack
mock_abspath, mock_logger,
mock_get_undercloud_host_entry,
mock_confirm, mock_usercheck,
mock_get_ctlplane_attrs):
mock_yaml.return_value = {'fake_container': 'fake_value'}
argslist = ['--stack', 'overcloud', '--templates']
@ -79,31 +73,21 @@ class TestOvercloudUpdatePrepare(fakes.TestOvercloudUpdatePrepare):
mock_isfile.return_value = True
self.cmd.take_action(parsed_args)
mock_usercheck.assert_called_once()
mock_update.assert_called_once_with(
self.app.client_manager,
container='overcloud',
)
mock_deploy.assert_called_once()
@mock.patch('tripleoclient.utils.ensure_run_as_normal_user')
@mock.patch('tripleoclient.utils.prompt_user_for_confirmation',
return_value=True)
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@mock.patch('tripleoclient.workflows.package_update.update',
autospec=True)
@mock.patch('six.moves.builtins.open')
@mock.patch('os.path.abspath')
@mock.patch('yaml.safe_load')
@mock.patch('shutil.copytree', autospec=True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_tripleo_heat_templates', autospec=True)
'take_action', autospec=True)
def test_update_failed(self, mock_deploy, mock_copy, mock_yaml,
mock_abspath, mock_open, mock_update,
mock_get_stack, mock_confirm, mock_usercheck):
mock_stack = mock.Mock(parameters={'DeployIdentifier': ''})
mock_stack.stack_name = 'overcloud'
mock_get_stack.return_value = mock_stack
mock_update.side_effect = exceptions.DeploymentError()
mock_abspath, mock_open,
mock_confirm, mock_usercheck):
mock_deploy.side_effect = exceptions.DeploymentError()
mock_yaml.return_value = {'fake_container': 'fake_value'}
argslist = ['--stack', 'overcloud', '--templates', ]
verifylist = [

View File

@ -25,7 +25,6 @@ from tripleoclient import constants
from tripleoclient import utils as oooutils
from tripleoclient.v1.overcloud_deploy import DeployOvercloud
from tripleoclient.workflows import deployment
from tripleoclient.workflows import package_update
CONF = cfg.CONF
@ -62,17 +61,10 @@ class UpdatePrepare(DeployOvercloud):
constants.UPDATE_PROMPT, self.log)):
raise OvercloudUpdateNotConfirmed(constants.UPDATE_NO)
clients = self.app.client_manager
stack = oooutils.get_stack(clients.orchestration,
parsed_args.stack)
stack_name = stack.stack_name
# In case of update and upgrade we need to force the
# update_plan_only. The heat stack update is done by the
# packag_update mistral action
parsed_args.update_plan_only = True
# config_download to false. The heat stack update will be performed
# by DeployOvercloud class but skipping the config download part.
parsed_args.config_download = False
# Add the update-prepare.yaml environment to set noops etc
templates_dir = (parsed_args.templates or
@ -88,7 +80,6 @@ class UpdatePrepare(DeployOvercloud):
parsed_args.environment_files)
super(UpdatePrepare, self).take_action(parsed_args)
package_update.update(clients, container=stack_name)
self.log.info("Update init on stack {0} complete.".format(
parsed_args.stack))

View File

@ -1,65 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heatclient.common import event_utils
from tripleo_common.utils import plan
from tripleo_common.utils import stack
from tripleoclient import exceptions
from tripleoclient import utils
_STACK_TIMEOUT = 120 # 2h
def update(clients, container):
"""Update the heat stack outputs for purposes of update/upgrade.
This workflow assumes that previously the
plan_management.update_deployment_plan workflow has already been
run to process the templates and environments (the same way as
'deploy' command processes them).
:param clients: Application client object.
:type clients: Object
:param container: Container name to pull from.
:type container: String.
"""
tripleoclients = clients.tripleoclient
orchestration_client = clients.orchestration
object_client = tripleoclients.object_store
plan.update_plan_environment_with_image_parameters(
object_client, container)
events = event_utils.get_events(orchestration_client,
stack_id=container,
event_args={'sort_dir': 'desc',
'limit': 1})
marker = events[0].id if events else None
stack.stack_update(object_client, orchestration_client,
_STACK_TIMEOUT, container)
create_result = utils.wait_for_stack_ready(
clients.orchestration,
container,
marker,
'UPDATE',
)
if not create_result:
raise exceptions.DeploymentError(
'Heat Stack update failed, run the following command'
' `openstack --os-cloud undercloud stack failures list {}`'
' to investigate these failures further.'.format(container)
)