Backport --os-beta-command

Added to OSC in https://review.openstack.org/305436
and updated in https://review.openstack.org/324609

Change-Id: I6613954ed984c4d471fdd8bab8367731215318ec
This commit is contained in:
Dean Troyer 2016-06-08 10:17:10 -05:00
parent 876d81ef21
commit 263dd52fa9
4 changed files with 37 additions and 0 deletions

View File

@ -20,6 +20,9 @@ from cliff import lister
from cliff import show
import six
from osc_lib import exceptions
from osc_lib.i18n import _
class CommandMeta(abc.ABCMeta):
@ -37,6 +40,13 @@ class Command(command.Command):
self.log.debug('run(%s)', parsed_args)
return super(Command, self).run(parsed_args)
def validate_os_beta_command_enabled(self):
if not self.app.options.os_beta_command:
msg = _('Caution: This is a beta command and subject to '
'change. Use global option --os-beta-command '
'to enable this command.')
raise exceptions.CommandError(msg)
class Lister(Command, lister.Lister):
pass

View File

@ -265,6 +265,11 @@ class OpenStackShell(app.App):
action='store_true',
help="Print API call timing info",
)
parser.add_argument(
'--os-beta-command',
action='store_true',
help="Enable beta commands which are subject to change",
)
# osprofiler HMAC key argument
if osprofiler_profiler:

View File

@ -15,6 +15,8 @@
import mock
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib.tests import fakes as test_fakes
from osc_lib.tests import utils as test_utils
@ -33,3 +35,18 @@ class TestCommand(test_utils.TestCase):
'osc_lib.tests.command.test_command.FakeCommand',
cmd.log.name,
)
def test_validate_os_beta_command_enabled(self):
cmd = FakeCommand(mock.Mock(), mock.Mock())
cmd.app = mock.Mock()
cmd.app.options = test_fakes.FakeOptions()
# No exception is raised when enabled.
cmd.app.options.os_beta_command = True
cmd.validate_os_beta_command_enabled()
cmd.app.options.os_beta_command = False
self.assertRaises(
exceptions.CommandError,
cmd.validate_os_beta_command_enabled,
)

View File

@ -110,6 +110,11 @@ class FakeApp(object):
self.log = _log
class FakeOptions(object):
def __init__(self, **kwargs):
self.os_beta_command = False
class FakeClient(object):
def __init__(self, **kwargs):