Handle negative/wrong answer in question when upgrading undercloud.

When upgrading the heat-based undercloud a security
question is asked to stop the upgrade if a undercloud
backup was not performed. This patch handles the case
when a negative or wrong answer is provided,
raising a new UndercloudUpradeNotConfirmed exception
which is then captured and displays an informative
log notifying that the upgrade didn't take place.
Also, removing the format call when the undercloud
upgrades fails [0] as the called string message
doesn't need parametrization.

[0] - 03254c84f6/tripleoclient/v1/undercloud.py (L158)

Change-Id: I80ae52e8a732b2827e8179ce024f92ed52a29394
Closes-Bug: #1783722
This commit is contained in:
Jose Luis Franco Arza 2018-07-26 16:27:54 +02:00
parent a33b1499d7
commit ed1fc90365
4 changed files with 57 additions and 21 deletions

View File

@ -106,3 +106,7 @@ class LogFetchError(Exception):
class ContainerDeleteFailed(Exception):
"""Container deletion failed"""
class UndercloudUpgradeNotConfirmed(Exception):
"""Undercloud upgrade security question not confirmed."""

View File

@ -19,6 +19,7 @@ from osc_lib.tests import utils
import six
# Load the plugin init module for the plugin list and show commands
from tripleoclient import exceptions
from tripleoclient.v1 import tripleo_upgrade
@ -46,6 +47,13 @@ class TestUpgrade(utils.TestCommand):
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action',
autospec=True)
def test_take_action(self, mock_deploy):
verifylist = [
('local_ip', '127.0.0.1'),
('templates', '/tmp/thtroot'),
('stack', 'undercloud'),
('output_dir', '/my'),
]
parsed_args = self.check_parser(self.cmd,
['--local-ip', '127.0.0.1',
'--templates', '/tmp/thtroot',
@ -56,9 +64,11 @@ class TestUpgrade(utils.TestCommand):
'-e', '/tmp/thtroot42/notouch.yaml',
'-e', '~/custom.yaml',
'-e', 'something.yaml',
'-e', '../../../outside.yaml'], [])
'-e', '../../../outside.yaml'],
verifylist)
self.cmd.take_action(parsed_args)
parsed_args.standlone = True
parsed_args.standalone = True
parsed_args.upgrade = True
mock_deploy.assert_called_with(self.cmd, parsed_args)
@ -101,8 +111,33 @@ class TestUpgrade(utils.TestCommand):
'-e', '~/custom.yaml',
'-e', 'something.yaml',
'-e', '../../../outside.yaml'], [])
self.cmd.take_action(parsed_args)
parsed_args.standlone = True
parsed_args.upgrade = True
self.assertRaises(exceptions.UndercloudUpgradeNotConfirmed,
self.cmd.take_action, parsed_args)
mock_stdin.readline.assert_called_with()
mock_deploy.assert_not_called()
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy',
autospec=True)
@mock.patch('sys.stdin', spec=six.StringIO)
def test_take_action_prompt_invalid_option(self, mock_stdin, mock_deploy):
mock_stdin.isatty.return_value = True
mock_stdin.readline.return_value = 'Dontwant'
parsed_args = self.check_parser(self.cmd,
['--local-ip', '127.0.0.1',
'--templates', '/tmp/thtroot',
'--stack', 'undercloud',
'--output-dir', '/my',
'-e', '/tmp/thtroot/puppet/foo.yaml',
'-e', '/tmp/thtroot//docker/bar.yaml',
'-e', '/tmp/thtroot42/notouch.yaml',
'-e', '~/custom.yaml',
'-e', 'something.yaml',
'-e', '../../../outside.yaml'], [])
parsed_args.standlone = True
parsed_args.upgrade = True
self.assertRaises(exceptions.UndercloudUpgradeNotConfirmed,
self.cmd.take_action, parsed_args)
mock_stdin.readline.assert_called_with()
mock_deploy.assert_not_called()

View File

@ -1183,7 +1183,9 @@ class Deploy(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
unconf_msg = _('User did not confirm upgrade, so exiting. '
'Consider using the --yes parameter if you '
'prefer to skip this warning in the future')
try:
if parsed_args.upgrade and (
not parsed_args.yes and sys.stdin.isatty()):
@ -1193,17 +1195,16 @@ class Deploy(command.Command):
'upgrade [y/N]?')
).lower()
if not prompt_response.startswith('y'):
self.log.info('User did not confirm upgrade so '
'taking no action.')
return
except KeyboardInterrupt: # ctrl-c
self.log.info('User did not confirm upgrade '
'(ctrl-c) so taking no action.')
return
except EOFError: # ctrl-d
self.log.info('User did not confirm upgrade '
'(ctrl-d) so taking no action.')
return
raise exceptions.UndercloudUpgradeNotConfirmed(unconf_msg)
except (KeyboardInterrupt, EOFError) as e:
if e.__class__ == KeyboardInterrupt:
# ctrl-c
raise exceptions.UndercloudUpgradeNotConfirmed("(ctrl-c) %s" %
unconf_msg)
else:
# ctrl-d
raise exceptions.UndercloudUpgradeNotConfirmed("(ctrl-d) %s" %
unconf_msg)
if parsed_args.standalone:
if self._standalone_deploy(parsed_args) != 0:

View File

@ -155,9 +155,7 @@ class InstallUndercloud(command.Command):
'~/stackrc'
))
except Exception as e:
self.log.error(UNDERCLOUD_FAILURE_MESSAGE.format(
self.heat_launch.install_tmp
))
self.log.error(UNDERCLOUD_FAILURE_MESSAGE)
self.log.error(e)
raise exceptions.DeploymentError(e)
@ -208,8 +206,6 @@ class UpgradeUndercloud(InstallUndercloud):
'~/stackrc'
))
except Exception as e:
self.log.error(UNDERCLOUD_FAILURE_MESSAGE.format(
self.heat_launch.install_tmp
))
self.log.error(UNDERCLOUD_FAILURE_MESSAGE)
self.log.error(e)
raise exceptions.DeploymentError(e)