Merge "Refactor upgrade prepare and converge."

changes/25/736025/5
Zuul 2 years ago committed by Gerrit Code Review
commit 11f4cf1998
  1. 32
      tripleoclient/tests/v1/overcloud_upgrade/test_overcloud_upgrade.py
  2. 55
      tripleoclient/v1/overcloud_upgrade.py

@ -42,32 +42,19 @@ class TestOvercloudUpgradePrepare(fakes.TestOvercloudUpgradePrepare):
'take_action')
@mock.patch('tripleoclient.workflows.deployment.'
'get_hosts_and_enable_ssh_admin', autospec=True)
@mock.patch('tripleoclient.workflows.deployment.create_overcloudrc',
autospec=True)
@mock.patch('tripleoclient.utils.prepend_environment', autospec=True)
@mock.patch('tripleoclient.utils.get_stack',
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,
mock_overcloudrc,
mock_enable_ssh_admin,
mock_overcloud_deploy):
@ -89,13 +76,11 @@ 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")
mock_overcloud_deploy.assert_called_once_with(parsed_args)
args, kwargs = mock_overcloud_deploy.call_args
# Check config_download arg is set to False
self.assertEqual(args[0].config_download, False)
mock_enable_ssh_admin.assert_called_once_with(
mock_stack,
parsed_args.overcloud_ssh_network,
@ -110,18 +95,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'

@ -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,22 +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)
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,
@ -87,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 {} for stack "
"{}".format(self.operation, stack_name))
class UpgradeRun(command.Command):
@ -103,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)
@ -229,7 +229,7 @@ class UpgradeRun(command.Command):
self.log.info("Completed Overcloud Major Upgrade Run.")
class UpgradeConvergeOvercloud(DeployOvercloud):
class UpgradeConvergeOvercloud(UpgradePrepare):
"""Major upgrade converge - reset Heat resources in the stored plan
This is the last step for completion of a overcloud major
@ -238,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")
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)
template = 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__ + ".UpgradeConvergeOvercloud")

Loading…
Cancel
Save