Merge "Add warning + required confirm for ffwd-upgrade cli --yes to skip"

This commit is contained in:
Zuul 2018-05-03 20:48:46 +00:00 committed by Gerrit Code Review
commit c79dabc47b
3 changed files with 65 additions and 8 deletions

View File

@ -73,11 +73,13 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare):
mock_yaml.return_value = {'fake_container': 'fake_value'}
argslist = ['--stack', 'mystack', '--templates',
'--container-registry-file', 'my-fake-registry.yaml']
'--container-registry-file', 'my-fake-registry.yaml',
'--yes']
verifylist = [
('stack', 'mystack'),
('templates', constants.TRIPLEO_HEAT_TEMPLATES),
('container_registry_file', 'my-fake-registry.yaml')
('container_registry_file', 'my-fake-registry.yaml'),
('yes', True),
]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
@ -111,11 +113,13 @@ class TestFFWDUpgradePrepare(fakes.TestFFWDUpgradePrepare):
mock_abspath.return_value = '/home/fake/my-fake-registry.yaml'
mock_yaml.return_value = {'fake_container': 'fake_value'}
argslist = ['--stack', 'overcloud', '--templates',
'--container-registry-file', 'my-fake-registry.yaml']
'--container-registry-file', 'my-fake-registry.yaml',
'--yes', ]
verifylist = [
('stack', 'overcloud'),
('templates', constants.TRIPLEO_HEAT_TEMPLATES),
('container_registry_file', 'my-fake-registry.yaml')
('container_registry_file', 'my-fake-registry.yaml'),
('yes', True),
]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
@ -145,8 +149,8 @@ class TestFFWDUpgradeRun(fakes.TestFFWDUpgradeRun):
def test_ffwd_upgrade_playbook(
self, mock_open, mock_execute, mock_expanduser, upgrade_ansible):
mock_expanduser.return_value = '/home/fake/'
argslist = []
verifylist = []
argslist = ['--yes']
verifylist = [('yes', True), ]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
with mock.patch('os.path.exists') as mock_exists:
@ -170,7 +174,7 @@ class TestFFWDUpgradeRun(fakes.TestFFWDUpgradeRun):
def test_upgrade_no_nodes_or_roles(self, mock_open, mock_execute,
mock_expanduser, upgrade_ansible):
mock_expanduser.return_value = '/home/fake/'
argslist = ["--nodes", "controller-1", "--roles", "foo"]
argslist = ["--nodes", "controller-1", "--roles", "foo", "--yes"]
verifylist = []
self.assertRaises(ParserException, lambda: self.check_parser(
self.cmd, argslist, verifylist))
@ -213,10 +217,11 @@ class TestFFWDUpgradeConverge(fakes.TestFFWDUpgradeConverge):
mock_stack = mock.Mock()
mock_stack.stack_name = 'le_overcloud'
mock_get_stack.return_value = mock_stack
argslist = ['--stack', 'le_overcloud', '--templates']
argslist = ['--stack', 'le_overcloud', '--templates', '--yes']
verifylist = [
('stack', 'le_overcloud'),
('templates', constants.TRIPLEO_HEAT_TEMPLATES),
('yes', True)
]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
with mock.patch('os.path.exists') as mock_exists:

View File

@ -1068,3 +1068,31 @@ def run_command_and_log(log, cmd, cwd=None):
log.warning(line.rstrip())
proc.stdout.close()
return proc.wait()
def ffwd_upgrade_operator_confirm(parsed_args_yes, log):
print("Warning! The TripleO Fast Forward Upgrade workflow "
"is currently considered under development. In "
"particular invocations of the ffwd-upgrade cli "
"should be initially limited to development/test "
"environments. Once and if you decide to use ffwd-upgrade "
"in production, ensure you are adequately prepared "
"with valid backup of your current deployment state.")
if parsed_args_yes:
log.debug("Fast forward upgrade --yes continuing")
print("Continuing fast forward upgrade")
return
else:
# Fix Python 2.x.
try:
input = raw_input
except NameError:
pass
response = input("Proceed with the fast forward upgrade? "
"Type 'yes' to continue and anything else to "
"cancel. Consider using the --yes parameter if "
"you wish to skip this warning in future. ")
if response != 'yes':
log.debug("Fast forward upgrade cancelled on user request")
print("Cancelling fast forward upgrade")
sys.exit(1)

View File

@ -36,6 +36,12 @@ class FFWDUpgradePrepare(DeployOvercloud):
def get_parser(self, prog_name):
parser = super(FFWDUpgradePrepare, self).get_parser(prog_name)
parser.add_argument('--yes',
action='store_true',
help=_("Use --yes to skip the confirmation "
"required before any ffwd-upgrade "
"operation. Use this with caution! "),
)
parser.add_argument('--container-registry-file',
dest='container_registry_file',
default=None,
@ -53,6 +59,8 @@ class FFWDUpgradePrepare(DeployOvercloud):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
oooutils.ffwd_upgrade_operator_confirm(parsed_args.yes, self.log)
clients = self.app.client_manager
stack = oooutils.get_stack(clients.orchestration,
@ -103,6 +111,12 @@ class FFWDUpgradeRun(command.Command):
def get_parser(self, prog_name):
parser = super(FFWDUpgradeRun, self).get_parser(prog_name)
parser.add_argument('--yes',
action='store_true',
help=_("Use --yes to skip the confirmation "
"required before any ffwd-upgrade "
"operation. Use this with caution! "),
)
parser.add_argument('--static-inventory',
dest='static_inventory',
action="store",
@ -123,6 +137,8 @@ class FFWDUpgradeRun(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
oooutils.ffwd_upgrade_operator_confirm(parsed_args.yes, self.log)
clients = self.app.client_manager
# Run ansible:
inventory = oooutils.get_tripleo_ansible_inventory(
@ -150,10 +166,18 @@ class FFWDUpgradeConverge(DeployOvercloud):
def get_parser(self, prog_name):
parser = super(FFWDUpgradeConverge, self).get_parser(prog_name)
parser.add_argument('--yes',
action='store_true',
help=_("Use --yes to skip the confirmation "
"required before any ffwd-upgrade "
"operation. Use this with caution! "),
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
oooutils.ffwd_upgrade_operator_confirm(parsed_args.yes, self.log)
clients = self.app.client_manager
stack = oooutils.get_stack(clients.orchestration,