Merge "Fix --enable options on commands"
This commit is contained in:
commit
55a7ba890d
@ -33,7 +33,7 @@ example list
|
|||||||
List examples
|
List examples
|
||||||
|
|
||||||
.. caution:: This is a beta command and subject to change.
|
.. 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.
|
enable this command.
|
||||||
|
|
||||||
.. program:: example list
|
.. program:: example list
|
||||||
@ -52,7 +52,7 @@ The command help must label the command as a beta.
|
|||||||
"""Display example details
|
"""Display example details
|
||||||
|
|
||||||
(Caution: This is a beta command and subject to change.
|
(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)
|
this command)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -60,13 +60,9 @@ Implementation
|
|||||||
--------------
|
--------------
|
||||||
|
|
||||||
The command must raise a ``CommandError`` exception if beta commands
|
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
|
.. code-block:: python
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
if not self.app.options.enable_beta_commands:
|
self.validate_os_beta_command_enabled()
|
||||||
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)
|
|
||||||
|
@ -15,7 +15,7 @@ network segment list
|
|||||||
List network segments
|
List network segments
|
||||||
|
|
||||||
.. caution:: This is a beta command and subject to change.
|
.. 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.
|
enable this command.
|
||||||
|
|
||||||
.. program:: network segment list
|
.. program:: network segment list
|
||||||
@ -39,7 +39,7 @@ network segment show
|
|||||||
Display network segment details
|
Display network segment details
|
||||||
|
|
||||||
.. caution:: This is a beta command and subject to change.
|
.. 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.
|
enable this command.
|
||||||
|
|
||||||
.. program:: network segment show
|
.. program:: network segment show
|
||||||
|
@ -132,6 +132,9 @@ OPTIONS
|
|||||||
This key should be the value of one of the HMAC keys defined in the
|
This key should be the value of one of the HMAC keys defined in the
|
||||||
configuration files of OpenStack services to be traced.
|
configuration files of OpenStack services to be traced.
|
||||||
|
|
||||||
|
:option:`--os-beta-command`
|
||||||
|
Enable beta commands which are subject to change
|
||||||
|
|
||||||
:option:`--log-file` <LOGFILE>
|
:option:`--log-file` <LOGFILE>
|
||||||
Specify a file to log output. Disabled by default.
|
Specify a file to log output. Disabled by default.
|
||||||
|
|
||||||
@ -144,9 +147,6 @@ OPTIONS
|
|||||||
:option:`--debug`
|
:option:`--debug`
|
||||||
Show tracebacks on errors and set verbosity to debug
|
Show tracebacks on errors and set verbosity to debug
|
||||||
|
|
||||||
:option:`--enable-beta-commands`
|
|
||||||
Enable beta commands which are subject to change
|
|
||||||
|
|
||||||
COMMANDS
|
COMMANDS
|
||||||
========
|
========
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class NetworkSegmentTests(test.TestCase):
|
|||||||
|
|
||||||
# Get the segment for the network.
|
# Get the segment for the network.
|
||||||
opts = cls.get_show_opts(['ID', '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 segment list '
|
||||||
' --network ' + cls.NETWORK_NAME +
|
' --network ' + cls.NETWORK_NAME +
|
||||||
' ' + opts)
|
' ' + opts)
|
||||||
@ -48,13 +48,13 @@ class NetworkSegmentTests(test.TestCase):
|
|||||||
|
|
||||||
def test_network_segment_list(self):
|
def test_network_segment_list(self):
|
||||||
opts = self.get_list_opts(['ID'])
|
opts = self.get_list_opts(['ID'])
|
||||||
raw_output = self.openstack('--enable-beta-commands '
|
raw_output = self.openstack('--os-beta-command '
|
||||||
'network segment list' + opts)
|
'network segment list' + opts)
|
||||||
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
|
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
|
||||||
|
|
||||||
def test_network_segment_show(self):
|
def test_network_segment_show(self):
|
||||||
opts = self.get_show_opts(['network_id'])
|
opts = self.get_show_opts(['network_id'])
|
||||||
raw_output = self.openstack('--enable-beta-commands '
|
raw_output = self.openstack('--os-beta-command '
|
||||||
'network segment show ' +
|
'network segment show ' +
|
||||||
self.NETWORK_SEGMENT_ID + opts)
|
self.NETWORK_SEGMENT_ID + opts)
|
||||||
self.assertEqual(self.NETWORK_ID + "\n", raw_output)
|
self.assertEqual(self.NETWORK_ID + "\n", raw_output)
|
||||||
|
@ -20,6 +20,9 @@ from cliff import lister
|
|||||||
from cliff import show
|
from cliff import show
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from openstackclient.common import exceptions
|
||||||
|
from openstackclient.i18n import _
|
||||||
|
|
||||||
|
|
||||||
class CommandMeta(abc.ABCMeta):
|
class CommandMeta(abc.ABCMeta):
|
||||||
|
|
||||||
@ -37,6 +40,13 @@ class Command(command.Command):
|
|||||||
self.log.debug('run(%s)', parsed_args)
|
self.log.debug('run(%s)', parsed_args)
|
||||||
return super(Command, self).run(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):
|
class Lister(Command, lister.Lister):
|
||||||
pass
|
pass
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
# TODO(rtheis): Add description and name properties when support is available.
|
# TODO(rtheis): Add description and name properties when support is available.
|
||||||
|
|
||||||
from openstackclient.common import command
|
from openstackclient.common import command
|
||||||
from openstackclient.common import exceptions
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ class ListNetworkSegment(command.Lister):
|
|||||||
"""List network segments
|
"""List network segments
|
||||||
|
|
||||||
(Caution: This is a beta command and subject to change.
|
(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)
|
this command)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -46,11 +45,7 @@ class ListNetworkSegment(command.Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
if not self.app.options.enable_beta_commands:
|
self.validate_os_beta_command_enabled()
|
||||||
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)
|
|
||||||
|
|
||||||
network_client = self.app.client_manager.network
|
network_client = self.app.client_manager.network
|
||||||
|
|
||||||
@ -94,7 +89,7 @@ class ShowNetworkSegment(command.ShowOne):
|
|||||||
"""Display network segment details
|
"""Display network segment details
|
||||||
|
|
||||||
(Caution: This is a beta command and subject to change.
|
(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)
|
this command)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -108,11 +103,7 @@ class ShowNetworkSegment(command.ShowOne):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
if not self.app.options.enable_beta_commands:
|
self.validate_os_beta_command_enabled()
|
||||||
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)
|
|
||||||
|
|
||||||
client = self.app.client_manager.network
|
client = self.app.client_manager.network
|
||||||
obj = client.find_segment(
|
obj = client.find_segment(
|
||||||
|
@ -251,7 +251,7 @@ class OpenStackShell(app.App):
|
|||||||
help="Print API call timing info",
|
help="Print API call timing info",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--enable-beta-commands',
|
'--os-beta-command',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Enable beta commands which are subject to change",
|
help="Enable beta commands which are subject to change",
|
||||||
)
|
)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from openstackclient.common import command
|
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
|
from openstackclient.tests import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
@ -31,3 +33,16 @@ class TestCommand(test_utils.TestCase):
|
|||||||
self.assertTrue(hasattr(cmd, 'log'))
|
self.assertTrue(hasattr(cmd, 'log'))
|
||||||
self.assertEqual('openstackclient.tests.common.test_command.'
|
self.assertEqual('openstackclient.tests.common.test_command.'
|
||||||
'FakeCommand', cmd.log.name)
|
'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)
|
||||||
|
@ -99,7 +99,7 @@ class FakeApp(object):
|
|||||||
|
|
||||||
class FakeOptions(object):
|
class FakeOptions(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.enable_beta_commands = False
|
self.os_beta_command = False
|
||||||
|
|
||||||
|
|
||||||
class FakeClient(object):
|
class FakeClient(object):
|
||||||
|
@ -25,7 +25,7 @@ class TestNetworkSegment(network_fakes.TestNetworkV2):
|
|||||||
super(TestNetworkSegment, self).setUp()
|
super(TestNetworkSegment, self).setUp()
|
||||||
|
|
||||||
# Enable beta commands.
|
# Enable beta commands.
|
||||||
self.app.options.enable_beta_commands = True
|
self.app.options.os_beta_command = True
|
||||||
|
|
||||||
# Get a shortcut to the network client
|
# Get a shortcut to the network client
|
||||||
self.network = self.app.client_manager.network
|
self.network = self.app.client_manager.network
|
||||||
@ -89,7 +89,7 @@ class TestListNetworkSegment(TestNetworkSegment):
|
|||||||
self.assertEqual(self.data, list(data))
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
def test_list_no_beta_commands(self):
|
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, [], [])
|
parsed_args = self.check_parser(self.cmd, [], [])
|
||||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
parsed_args)
|
parsed_args)
|
||||||
@ -174,7 +174,7 @@ class TestShowNetworkSegment(TestNetworkSegment):
|
|||||||
verifylist = [
|
verifylist = [
|
||||||
('network_segment', self._network_segment.id),
|
('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)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
parsed_args)
|
parsed_args)
|
||||||
|
@ -3,5 +3,5 @@ features:
|
|||||||
- Add support for the ``network segment`` command object via the
|
- Add support for the ``network segment`` command object via the
|
||||||
``network segment list`` and ``network segment show`` commands.
|
``network segment list`` and ``network segment show`` commands.
|
||||||
These are beta commands and subject to change. Use global option
|
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>`_]
|
[Blueprint `routed-networks <https://blueprints.launchpad.net/neutron/+spec/routed-networks>`_]
|
||||||
|
7
releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml
Normal file
7
releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml
Normal 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>`_]
|
Loading…
Reference in New Issue
Block a user