From 6f2c1734e3d66e261f231711455821321c1fc254 Mon Sep 17 00:00:00 2001 From: Richard Theis Date: Thu, 2 Jun 2016 09:53:55 -0500 Subject: [PATCH] Fix --enable options on commands The --enable option on commands is ignored when the arguments are parsed. This is related to the --enable-beta-commands option. Renaming the option to --os-beta-command fixes the problem. There's no need to handle backwards compatibility for the option name change because there hasn't been an OSC release yet with beta commands. Change-Id: I0327ba8a2058858a83e9a42e231470ed733cc834 Closes-Bug: #1588384 --- doc/source/command-beta.rst | 12 ++++-------- doc/source/command-objects/network-segment.rst | 4 ++-- doc/source/man/openstack.rst | 6 +++--- .../tests/network/v2/test_network_segment.py | 6 +++--- openstackclient/common/command.py | 10 ++++++++++ openstackclient/network/v2/network_segment.py | 17 ++++------------- openstackclient/shell.py | 2 +- openstackclient/tests/common/test_command.py | 15 +++++++++++++++ openstackclient/tests/fakes.py | 2 +- .../tests/network/v2/test_network_segment.py | 6 +++--- .../bp-routed-networks-3eea4978c93aa126.yaml | 2 +- .../notes/bug-1588384-eb6976fcfb90cb4c.yaml | 7 +++++++ 12 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml diff --git a/doc/source/command-beta.rst b/doc/source/command-beta.rst index 53a442047f..f0a4f85102 100644 --- a/doc/source/command-beta.rst +++ b/doc/source/command-beta.rst @@ -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() diff --git a/doc/source/command-objects/network-segment.rst b/doc/source/command-objects/network-segment.rst index 8e177d6af5..56a11e1ed4 100644 --- a/doc/source/command-objects/network-segment.rst +++ b/doc/source/command-objects/network-segment.rst @@ -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 diff --git a/doc/source/man/openstack.rst b/doc/source/man/openstack.rst index e14f1f95cb..7af380a31c 100644 --- a/doc/source/man/openstack.rst +++ b/doc/source/man/openstack.rst @@ -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` 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 ======== diff --git a/functional/tests/network/v2/test_network_segment.py b/functional/tests/network/v2/test_network_segment.py index a998093811..b5b5dcd9fe 100644 --- a/functional/tests/network/v2/test_network_segment.py +++ b/functional/tests/network/v2/test_network_segment.py @@ -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) diff --git a/openstackclient/common/command.py b/openstackclient/common/command.py index fee4559e75..144a0db10d 100644 --- a/openstackclient/common/command.py +++ b/openstackclient/common/command.py @@ -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 diff --git a/openstackclient/network/v2/network_segment.py b/openstackclient/network/v2/network_segment.py index d8a91fd200..818ffc026f 100644 --- a/openstackclient/network/v2/network_segment.py +++ b/openstackclient/network/v2/network_segment.py @@ -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( diff --git a/openstackclient/shell.py b/openstackclient/shell.py index 9968d73fc1..9179ad019e 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -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", ) diff --git a/openstackclient/tests/common/test_command.py b/openstackclient/tests/common/test_command.py index 7467d9eba4..722a4c06ad 100644 --- a/openstackclient/tests/common/test_command.py +++ b/openstackclient/tests/common/test_command.py @@ -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) diff --git a/openstackclient/tests/fakes.py b/openstackclient/tests/fakes.py index 7fb1daa980..ad4705a4de 100644 --- a/openstackclient/tests/fakes.py +++ b/openstackclient/tests/fakes.py @@ -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): diff --git a/openstackclient/tests/network/v2/test_network_segment.py b/openstackclient/tests/network/v2/test_network_segment.py index 2822581c67..0a99eced69 100644 --- a/openstackclient/tests/network/v2/test_network_segment.py +++ b/openstackclient/tests/network/v2/test_network_segment.py @@ -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) diff --git a/releasenotes/notes/bp-routed-networks-3eea4978c93aa126.yaml b/releasenotes/notes/bp-routed-networks-3eea4978c93aa126.yaml index 82080f7e6a..30661e6d20 100644 --- a/releasenotes/notes/bp-routed-networks-3eea4978c93aa126.yaml +++ b/releasenotes/notes/bp-routed-networks-3eea4978c93aa126.yaml @@ -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 `_] diff --git a/releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml b/releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml new file mode 100644 index 0000000000..797d6732b6 --- /dev/null +++ b/releasenotes/notes/bug-1588384-eb6976fcfb90cb4c.yaml @@ -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 `_]