Refactor upgrade prepare and converge.

As we aren't required to re-deploy any more during the converge step
the actions performed by the Upgrade Converge and Prepare are exactly
the same, the only difference is the lifecycle environment file we
use to set and unset parameters.

This patch refactors both classes, the UpgradePrepare and UpgradeConverge
clasess:

- UpgradePrepare: Stop forcing update-plan-only and then try to do most of the
actions from deployment into UpgradePrepare. This change will force config_download
to false (which will avoid running the full deployment and do only an stack update)
and lastly enable ssh into overcloud nodes, as that part is perforemd in deployment
only if config_download is set to true. Add new attributes to UpgradePrepare so we
can override them in UpgradeConverge via inheritence.

- UpgradeConverge: Inherit from UpgradePrepare instead of DeployOvercloud. Set the
right value for the class attributes and let UpgradePrepare class do all the magic.
This patch also changes the class name to be in consonancy with the rest of the
clases.

Change-Id: I6148511eb6ad1e3798a7bf40c721824830c7073d
This commit is contained in:
Jose Luis Franco Arza 2020-05-28 15:27:06 +02:00
parent 8aa4f8810f
commit 8df46e3798
3 changed files with 24 additions and 64 deletions

View File

@ -97,7 +97,7 @@ openstack.tripleoclient.v2 =
overcloud_update_converge= tripleoclient.v1.overcloud_update:UpdateConverge
overcloud_upgrade_prepare = tripleoclient.v1.overcloud_upgrade:UpgradePrepare
overcloud_upgrade_run = tripleoclient.v1.overcloud_upgrade:UpgradeRun
overcloud_upgrade_converge = tripleoclient.v1.overcloud_upgrade:UpgradeConvergeOvercloud
overcloud_upgrade_converge = tripleoclient.v1.overcloud_upgrade:UpgradeConverge
overcloud_external-update_run = tripleoclient.v1.overcloud_external_update:ExternalUpdateRun
overcloud_external-upgrade_run = tripleoclient.v1.overcloud_external_upgrade:ExternalUpgradeRun
overcloud_ffwd-upgrade_prepare = tripleoclient.v1.overcloud_ffwd_upgrade:FFWDUpgradePrepare

View File

@ -49,21 +49,11 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
autospec=True)
@mock.patch('tripleoclient.v1.overcloud_upgrade.UpgradePrepare.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', autospec=True)
def test_upgrade_out(self,
mock_deploy,
mock_open,
mock_copy,
mock_yaml,
mock_abspath,
mock_upgrade,
mock_logger,
mock_get_stack,
add_env,
@ -89,12 +79,9 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args)
mock_upgrade.assert_called_once_with(
self.app.client_manager,
container='overcloud',
)
mock_overcloudrc.assert_called_once_with(container="overcloud")
parsed_args.config_download = True
mock_overcloudrc.assert_called_once
mock_overcloud_deploy.assert_called_once_with(parsed_args)
mock_enable_ssh_admin.assert_called_once_with(
mock_stack,
@ -110,18 +97,11 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
@mock.patch('tripleoclient.utils.get_stack',
autospec=True)
@mock.patch('tripleoclient.utils.prepend_environment', 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)
def test_upgrade_failed(self, mock_deploy, mock_copy, mock_yaml,
mock_abspath, mock_open, mock_upgrade,
def test_upgrade_failed(self, mock_yaml, mock_open,
add_env, mock_get_stack, mock_overcloud_deploy):
mock_upgrade.side_effect = exceptions.DeploymentError()
mock_overcloud_deploy.side_effect = exceptions.DeploymentError()
mock_yaml.return_value = {'fake_container': 'fake_value'}
mock_stack = mock.Mock(parameters={'DeployIdentifier': ''})
mock_stack.stack_name = 'overcloud'

View File

@ -24,7 +24,6 @@ from tripleoclient import exceptions
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
logging.register_options(CONF)
@ -39,7 +38,11 @@ class UpgradePrepare(DeployOvercloud):
first step for a major upgrade of your overcloud.
"""
log = logging.getLogger(__name__ + ".MajorUpgradePrepare")
operation = 'Prepare'
template = constants.UPGRADE_PREPARE_ENV
log = logging.getLogger(__name__ + ".UpgradePrepare")
def get_parser(self, prog_name):
parser = super(UpgradePrepare, self).get_parser(prog_name)
@ -62,25 +65,19 @@ class UpgradePrepare(DeployOvercloud):
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
# Add the upgrade-prepare.yaml environment to set noops etc
# 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 template attribute environment to set noops etc
templates_dir = (parsed_args.templates or
constants.TRIPLEO_HEAT_TEMPLATES)
parsed_args.environment_files = oooutils.prepend_environment(
parsed_args.environment_files, templates_dir,
constants.UPGRADE_PREPARE_ENV)
self.template)
super(UpgradePrepare, self).take_action(parsed_args)
package_update.update(clients, container=stack_name)
oooutils.get_config(
clients, container=stack_name,
container_config='{}-config'.format(stack.stack_name))
deployment.create_overcloudrc(container=stack_name)
# refresh stack info and enable ssh admin for Ansible-via-Mistral
stack = oooutils.get_stack(clients.orchestration, parsed_args.stack)
# enable ssh admin for Ansible-via-Mistral as that's done only
# when config_download is true
deployment.get_hosts_and_enable_ssh_admin(
stack,
parsed_args.overcloud_ssh_network,
@ -90,8 +87,8 @@ class UpgradePrepare(DeployOvercloud):
verbosity=oooutils.playbook_verbosity(self=self)
)
self.log.info("Completed Overcloud Upgrade Prepare for stack "
"{0}".format(stack_name))
self.log.info("Completed Overcloud Upgrade {0} for stack "
"{1}".format(self.operation, stack_name))
class UpgradeRun(command.Command):
@ -106,7 +103,7 @@ class UpgradeRun(command.Command):
command is the second step in the major upgrade workflow.
"""
log = logging.getLogger(__name__ + ".MajorUpgradeRun")
log = logging.getLogger(__name__ + ".UpgradeRun")
def get_parser(self, prog_name):
parser = super(UpgradeRun, self).get_parser(prog_name)
@ -232,7 +229,7 @@ class UpgradeRun(command.Command):
self.log.info("Completed Overcloud Major Upgrade Run.")
class UpgradeConvergeOvercloud(DeployOvercloud):
class UpgradeConverge(UpgradePrepare):
"""Major upgrade converge - reset Heat resources in the stored plan
This is the last step for completion of a overcloud major
@ -241,25 +238,8 @@ class UpgradeConvergeOvercloud(DeployOvercloud):
have set specific values for some stack Heat resources. This
unsets those back to their default values.
"""
operation = "Converge"
log = logging.getLogger(__name__ + ".UpgradeConvergeOvercloud")
template = constants.UPGRADE_CONVERGE_ENV
def get_parser(self, prog_name):
parser = super(UpgradeConvergeOvercloud, self).get_parser(prog_name)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
stack = oooutils.get_stack(clients.orchestration,
parsed_args.stack)
# Add the converge environment into the args to unset noop etc
templates_dir = (parsed_args.templates or
constants.TRIPLEO_HEAT_TEMPLATES)
parsed_args.environment_files = oooutils.prepend_environment(
parsed_args.environment_files, templates_dir,
constants.UPGRADE_CONVERGE_ENV)
super(UpgradeConvergeOvercloud, self).take_action(parsed_args)
self.log.info("Completed Overcloud Upgrade Converge for stack {0}"
.format(stack.stack_name))
log = logging.getLogger(__name__ + ".UpgradeConverge")