Merge "Handle negative/wrong answer in question when upgrading undercloud."
This commit is contained in:
commit
38b7207b08
|
@ -106,3 +106,7 @@ class LogFetchError(Exception):
|
||||||
|
|
||||||
class ContainerDeleteFailed(Exception):
|
class ContainerDeleteFailed(Exception):
|
||||||
"""Container deletion failed"""
|
"""Container deletion failed"""
|
||||||
|
|
||||||
|
|
||||||
|
class UndercloudUpgradeNotConfirmed(Exception):
|
||||||
|
"""Undercloud upgrade security question not confirmed."""
|
||||||
|
|
|
@ -19,6 +19,7 @@ from osc_lib.tests import utils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
# Load the plugin init module for the plugin list and show commands
|
# Load the plugin init module for the plugin list and show commands
|
||||||
|
from tripleoclient import exceptions
|
||||||
from tripleoclient.v1 import tripleo_upgrade
|
from tripleoclient.v1 import tripleo_upgrade
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +47,13 @@ class TestUpgrade(utils.TestCommand):
|
||||||
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action',
|
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
def test_take_action(self, mock_deploy):
|
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,
|
parsed_args = self.check_parser(self.cmd,
|
||||||
['--local-ip', '127.0.0.1',
|
['--local-ip', '127.0.0.1',
|
||||||
'--templates', '/tmp/thtroot',
|
'--templates', '/tmp/thtroot',
|
||||||
|
@ -56,9 +64,11 @@ class TestUpgrade(utils.TestCommand):
|
||||||
'-e', '/tmp/thtroot42/notouch.yaml',
|
'-e', '/tmp/thtroot42/notouch.yaml',
|
||||||
'-e', '~/custom.yaml',
|
'-e', '~/custom.yaml',
|
||||||
'-e', 'something.yaml',
|
'-e', 'something.yaml',
|
||||||
'-e', '../../../outside.yaml'], [])
|
'-e', '../../../outside.yaml'],
|
||||||
|
verifylist)
|
||||||
|
|
||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
parsed_args.standlone = True
|
parsed_args.standalone = True
|
||||||
parsed_args.upgrade = True
|
parsed_args.upgrade = True
|
||||||
mock_deploy.assert_called_with(self.cmd, parsed_args)
|
mock_deploy.assert_called_with(self.cmd, parsed_args)
|
||||||
|
|
||||||
|
@ -101,8 +111,33 @@ class TestUpgrade(utils.TestCommand):
|
||||||
'-e', '~/custom.yaml',
|
'-e', '~/custom.yaml',
|
||||||
'-e', 'something.yaml',
|
'-e', 'something.yaml',
|
||||||
'-e', '../../../outside.yaml'], [])
|
'-e', '../../../outside.yaml'], [])
|
||||||
self.cmd.take_action(parsed_args)
|
|
||||||
parsed_args.standlone = True
|
parsed_args.standlone = True
|
||||||
parsed_args.upgrade = 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_stdin.readline.assert_called_with()
|
||||||
mock_deploy.assert_not_called()
|
mock_deploy.assert_not_called()
|
||||||
|
|
|
@ -1152,7 +1152,9 @@ class Deploy(command.Command):
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug("take_action(%s)" % 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:
|
try:
|
||||||
if parsed_args.upgrade and (
|
if parsed_args.upgrade and (
|
||||||
not parsed_args.yes and sys.stdin.isatty()):
|
not parsed_args.yes and sys.stdin.isatty()):
|
||||||
|
@ -1162,17 +1164,16 @@ class Deploy(command.Command):
|
||||||
'upgrade [y/N]?')
|
'upgrade [y/N]?')
|
||||||
).lower()
|
).lower()
|
||||||
if not prompt_response.startswith('y'):
|
if not prompt_response.startswith('y'):
|
||||||
self.log.info('User did not confirm upgrade so '
|
raise exceptions.UndercloudUpgradeNotConfirmed(unconf_msg)
|
||||||
'taking no action.')
|
except (KeyboardInterrupt, EOFError) as e:
|
||||||
return
|
if e.__class__ == KeyboardInterrupt:
|
||||||
except KeyboardInterrupt: # ctrl-c
|
# ctrl-c
|
||||||
self.log.info('User did not confirm upgrade '
|
raise exceptions.UndercloudUpgradeNotConfirmed("(ctrl-c) %s" %
|
||||||
'(ctrl-c) so taking no action.')
|
unconf_msg)
|
||||||
return
|
else:
|
||||||
except EOFError: # ctrl-d
|
# ctrl-d
|
||||||
self.log.info('User did not confirm upgrade '
|
raise exceptions.UndercloudUpgradeNotConfirmed("(ctrl-d) %s" %
|
||||||
'(ctrl-d) so taking no action.')
|
unconf_msg)
|
||||||
return
|
|
||||||
|
|
||||||
if parsed_args.standalone:
|
if parsed_args.standalone:
|
||||||
if self._standalone_deploy(parsed_args) != 0:
|
if self._standalone_deploy(parsed_args) != 0:
|
||||||
|
|
Loading…
Reference in New Issue