Prompt before running undercloud/all-in-one upgrades

Running upgrades is critical and we want our operators to make backups
before running the process.
This patch adds a prompt that will confirm that the operator is ready to
upgrade the undercloud or all-in-one setup.

It can be ignored when uding -y or --yes arguments like:
  $ openstack tripleo upgrade -y (...)

Change-Id: Iab7ebbe6283039a447d88f9d801486511f5b7b05
This commit is contained in:
Emilien Macchi 2018-05-17 15:41:46 -07:00
parent e8a12eac8f
commit 14c6b8da41
3 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
Prompt the operator before running the upgrades and suggest to perform a backup
before. Can be ignored with -y/--yes.

View File

@ -16,6 +16,7 @@
import mock
from osc_lib.tests import utils
import six
# Load the plugin init module for the plugin list and show commands
from tripleoclient.v1 import tripleo_upgrade
@ -60,3 +61,48 @@ class TestUpgrade(utils.TestCommand):
parsed_args.standlone = True
parsed_args.upgrade = True
mock_deploy.assert_called_with(self.cmd, parsed_args)
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action',
autospec=True)
@mock.patch('sys.stdin', spec=six.StringIO)
def test_take_action_prompt(self, mock_stdin, mock_deploy):
mock_stdin.isatty.return_value = True
mock_stdin.readline.return_value = 'y'
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'], [])
self.cmd.take_action(parsed_args)
parsed_args.standlone = True
parsed_args.upgrade = True
mock_deploy.assert_called_with(self.cmd, parsed_args)
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy',
autospec=True)
@mock.patch('sys.stdin', spec=six.StringIO)
def test_take_action_prompt_no(self, mock_stdin, mock_deploy):
mock_stdin.isatty.return_value = True
mock_stdin.readline.return_value = 'n'
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'], [])
self.cmd.take_action(parsed_args)
parsed_args.standlone = True
parsed_args.upgrade = True
mock_stdin.readline.assert_called_with()
mock_deploy.assert_not_called()

View File

@ -554,6 +554,8 @@ class Deploy(command.Command):
"with no undercloud."))
parser.add_argument('--upgrade', default=False, action='store_true',
help=_("Upgrade an existing deployment."))
parser.add_argument('-y', '--yes', default=False, action='store_true',
help=_("Skip yes/no prompt (assume yes)."))
parser.add_argument('--stack',
help=_("Stack name to create"),
default='undercloud')
@ -781,6 +783,27 @@ class Deploy(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
try:
if parsed_args.upgrade and (
not parsed_args.yes and sys.stdin.isatty()):
prompt_response = six.moves.input(
('It is strongly recommended to perform a backup '
'before the upgrade. Are you sure you want to '
'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
if parsed_args.standalone:
if self._standalone_deploy(parsed_args) != 0:
msg = _('Deployment failed.')