Merge "Fix --enable options on commands"

This commit is contained in:
Jenkins 2016-06-04 13:05:30 +00:00 committed by Gerrit Code Review
commit 55a7ba890d
12 changed files with 54 additions and 35 deletions

View File

@ -33,7 +33,7 @@ example list
List examples
.. caution:: This is a beta command and subject to change.
Use global option ``--enable-beta-commands`` to
Use global option ``--os-beta-command`` to
enable this command.
.. program:: example list
@ -52,7 +52,7 @@ The command help must label the command as a beta.
"""Display example details
(Caution: This is a beta command and subject to change.
Use global option --enable-beta-commands to enable
Use global option --os-beta-command to enable
this command)
"""
@ -60,13 +60,9 @@ Implementation
--------------
The command must raise a ``CommandError`` exception if beta commands
are not enabled via ``--enable-beta-commands`` global option.
are not enabled via ``--os-beta-command`` global option.
.. code-block:: python
def take_action(self, parsed_args):
if not self.app.options.enable_beta_commands:
msg = _('Caution: This is a beta command and subject to '
'change. Use global option --enable-beta-commands '
'to enable this command.')
raise exceptions.CommandError(msg)
self.validate_os_beta_command_enabled()

View File

@ -15,7 +15,7 @@ network segment list
List network segments
.. caution:: This is a beta command and subject to change.
Use global option ``--enable-beta-commands`` to
Use global option ``--os-beta-command`` to
enable this command.
.. program:: network segment list
@ -39,7 +39,7 @@ network segment show
Display network segment details
.. caution:: This is a beta command and subject to change.
Use global option ``--enable-beta-commands`` to
Use global option ``--os-beta-command`` to
enable this command.
.. program:: network segment show

View File

@ -132,6 +132,9 @@ OPTIONS
This key should be the value of one of the HMAC keys defined in the
configuration files of OpenStack services to be traced.
:option:`--os-beta-command`
Enable beta commands which are subject to change
:option:`--log-file` <LOGFILE>
Specify a file to log output. Disabled by default.
@ -144,9 +147,6 @@ OPTIONS
:option:`--debug`
Show tracebacks on errors and set verbosity to debug
:option:`--enable-beta-commands`
Enable beta commands which are subject to change
COMMANDS
========

View File

@ -34,7 +34,7 @@ class NetworkSegmentTests(test.TestCase):
# Get the segment for the network.
opts = cls.get_show_opts(['ID', 'Network'])
raw_output = cls.openstack('--enable-beta-commands '
raw_output = cls.openstack('--os-beta-command '
'network segment list '
' --network ' + cls.NETWORK_NAME +
' ' + opts)
@ -48,13 +48,13 @@ class NetworkSegmentTests(test.TestCase):
def test_network_segment_list(self):
opts = self.get_list_opts(['ID'])
raw_output = self.openstack('--enable-beta-commands '
raw_output = self.openstack('--os-beta-command '
'network segment list' + opts)
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
def test_network_segment_show(self):
opts = self.get_show_opts(['network_id'])
raw_output = self.openstack('--enable-beta-commands '
raw_output = self.openstack('--os-beta-command '
'network segment show ' +
self.NETWORK_SEGMENT_ID + opts)
self.assertEqual(self.NETWORK_ID + "\n", raw_output)

View File

@ -20,6 +20,9 @@ from cliff import lister
from cliff import show
import six
from openstackclient.common import exceptions
from openstackclient.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

@ -16,7 +16,6 @@
# TODO(rtheis): Add description and name properties when support is available.
from openstackclient.common import command
from openstackclient.common import exceptions
from openstackclient.common import utils
from openstackclient.i18n import _
@ -25,7 +24,7 @@ class ListNetworkSegment(command.Lister):
"""List network segments
(Caution: This is a beta command and subject to change.
Use global option --enable-beta-commands to enable
Use global option --os-beta-command to enable
this command)
"""
@ -46,11 +45,7 @@ class ListNetworkSegment(command.Lister):
return parser
def take_action(self, parsed_args):
if not self.app.options.enable_beta_commands:
msg = _('Caution: This is a beta command and subject to '
'change. Use global option --enable-beta-commands '
'to enable this command.')
raise exceptions.CommandError(msg)
self.validate_os_beta_command_enabled()
network_client = self.app.client_manager.network
@ -94,7 +89,7 @@ class ShowNetworkSegment(command.ShowOne):
"""Display network segment details
(Caution: This is a beta command and subject to change.
Use global option --enable-beta-commands to enable
Use global option --os-beta-command to enable
this command)
"""
@ -108,11 +103,7 @@ class ShowNetworkSegment(command.ShowOne):
return parser
def take_action(self, parsed_args):
if not self.app.options.enable_beta_commands:
msg = _('Caution: This is a beta command and subject to '
'change. Use global option --enable-beta-commands '
'to enable this command.')
raise exceptions.CommandError(msg)
self.validate_os_beta_command_enabled()
client = self.app.client_manager.network
obj = client.find_segment(

View File

@ -251,7 +251,7 @@ class OpenStackShell(app.App):
help="Print API call timing info",
)
parser.add_argument(
'--enable-beta-commands',
'--os-beta-command',
action='store_true',
help="Enable beta commands which are subject to change",
)

View File

@ -15,6 +15,8 @@
import mock
from openstackclient.common import command
from openstackclient.common import exceptions
from openstackclient.tests import fakes as test_fakes
from openstackclient.tests import utils as test_utils
@ -31,3 +33,16 @@ class TestCommand(test_utils.TestCase):
self.assertTrue(hasattr(cmd, 'log'))
self.assertEqual('openstackclient.tests.common.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

@ -99,7 +99,7 @@ class FakeApp(object):
class FakeOptions(object):
def __init__(self, **kwargs):
self.enable_beta_commands = False
self.os_beta_command = False
class FakeClient(object):

View File

@ -25,7 +25,7 @@ class TestNetworkSegment(network_fakes.TestNetworkV2):
super(TestNetworkSegment, self).setUp()
# Enable beta commands.
self.app.options.enable_beta_commands = True
self.app.options.os_beta_command = True
# Get a shortcut to the network client
self.network = self.app.client_manager.network
@ -89,7 +89,7 @@ class TestListNetworkSegment(TestNetworkSegment):
self.assertEqual(self.data, list(data))
def test_list_no_beta_commands(self):
self.app.options.enable_beta_commands = False
self.app.options.os_beta_command = False
parsed_args = self.check_parser(self.cmd, [], [])
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)
@ -174,7 +174,7 @@ class TestShowNetworkSegment(TestNetworkSegment):
verifylist = [
('network_segment', self._network_segment.id),
]
self.app.options.enable_beta_commands = False
self.app.options.os_beta_command = False
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)

View File

@ -3,5 +3,5 @@ features:
- Add support for the ``network segment`` command object via the
``network segment list`` and ``network segment show`` commands.
These are beta commands and subject to change. Use global option
``--enable-beta-commands`` to enable these commands.
``--os-beta-command`` to enable these commands.
[Blueprint `routed-networks <https://blueprints.launchpad.net/neutron/+spec/routed-networks>`_]

View File

@ -0,0 +1,7 @@
---
fixes:
- Fix the ``--enable`` option on all commands by changing the
``--enable-beta-commands`` global option to ``--os-beta-command``.
There are no upgrade impacts for the global option rename since
the old name isn't used.
[Bug `1588384 <https://bugs.launchpad.net/python-openstackclient/+bug/1588384>`_]