Browse Source

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),
then download the config by invoking get_config from package_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.

Change-Id: I6148511eb6ad1e3798a7bf40c721824830c7073d
(cherry picked from commit 8df46e3798)
changes/19/731619/9
Jose Luis Franco Arza 1 month ago
committed by Jesse Pretorius (odyssey4me)
parent
commit
0ba53608b2
2 changed files with 33 additions and 69 deletions
  1. +11
    -32
      tripleoclient/tests/v1/overcloud_upgrade/test_overcloud_upgrade.py
  2. +22
    -37
      tripleoclient/v1/overcloud_upgrade.py

+ 11
- 32
tripleoclient/tests/v1/overcloud_upgrade/test_overcloud_upgrade.py View File

@@ -41,34 +41,22 @@ 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',
@mock.patch('tripleoclient.workflows.package_update.get_config',
autospec=True)
@mock.patch('tripleoclient.utils.write_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.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_write_overcloudrc,
mock_overcloudrc,
mock_get_config,
mock_enable_ssh_admin,
mock_overcloud_deploy):

@@ -90,16 +78,14 @@ 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(mock.ANY,
container="overcloud")
mock_write_overcloudrc.assert_called_once_with("overcloud",
mock.ANY)

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_get_config.assert_called_once_with(mock.ANY,
container=mock_stack.stack_name
)
mock_enable_ssh_admin.assert_called_once_with(
self.cmd.log, self.app.client_manager, mock_stack,
parsed_args.overcloud_ssh_network,
@@ -111,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.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'


+ 22
- 37
tripleoclient/v1/overcloud_upgrade.py View File

@@ -39,7 +39,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,33 +66,31 @@ 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)
package_update.get_config(clients, container=stack_name)

overcloudrcs = deployment.create_overcloudrc(
clients, container=stack_name)
oooutils.write_overcloudrc(stack_name, overcloudrcs)
# Download stack_name-config as this is skiped in
# DeployOvercloud.
package_update.get_config(clients, 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(
self.log, clients, stack, parsed_args.overcloud_ssh_network,
parsed_args.overcloud_ssh_user, self.get_key_pair(parsed_args),
parsed_args.overcloud_ssh_enable_timeout,
parsed_args.overcloud_ssh_port_timeout)

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 +105,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)
@@ -241,7 +243,7 @@ class UpgradeRun(command.Command):
"playbooks {1} ").format(limit_hosts, playbooks))


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
@@ -250,25 +252,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
template = constants.UPGRADE_CONVERGE_ENV

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__ + ".UpgradeConvergeOvercloud")

Loading…
Cancel
Save