Skip to content

Commit 55a7ba8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix --enable options on commands"
2 parents 416792f + 6f2c173 commit 55a7ba8

12 files changed

Lines changed: 54 additions & 35 deletions

File tree

doc/source/command-beta.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ example list
3333
List examples
3434

3535
.. caution:: This is a beta command and subject to change.
36-
Use global option ``--enable-beta-commands`` to
36+
Use global option ``--os-beta-command`` to
3737
enable this command.
3838

3939
.. program:: example list
@@ -52,21 +52,17 @@ The command help must label the command as a beta.
5252
"""Display example details
5353
5454
(Caution: This is a beta command and subject to change.
55-
Use global option --enable-beta-commands to enable
55+
Use global option --os-beta-command to enable
5656
this command)
5757
"""
5858
5959
Implementation
6060
--------------
6161

6262
The command must raise a ``CommandError`` exception if beta commands
63-
are not enabled via ``--enable-beta-commands`` global option.
63+
are not enabled via ``--os-beta-command`` global option.
6464

6565
.. code-block:: python
6666
6767
def take_action(self, parsed_args):
68-
if not self.app.options.enable_beta_commands:
69-
msg = _('Caution: This is a beta command and subject to '
70-
'change. Use global option --enable-beta-commands '
71-
'to enable this command.')
72-
raise exceptions.CommandError(msg)
68+
self.validate_os_beta_command_enabled()

doc/source/command-objects/network-segment.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ network segment list
1515
List network segments
1616

1717
.. caution:: This is a beta command and subject to change.
18-
Use global option ``--enable-beta-commands`` to
18+
Use global option ``--os-beta-command`` to
1919
enable this command.
2020

2121
.. program:: network segment list
@@ -39,7 +39,7 @@ network segment show
3939
Display network segment details
4040

4141
.. caution:: This is a beta command and subject to change.
42-
Use global option ``--enable-beta-commands`` to
42+
Use global option ``--os-beta-command`` to
4343
enable this command.
4444

4545
.. program:: network segment show

doc/source/man/openstack.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ OPTIONS
132132
This key should be the value of one of the HMAC keys defined in the
133133
configuration files of OpenStack services to be traced.
134134

135+
:option:`--os-beta-command`
136+
Enable beta commands which are subject to change
137+
135138
:option:`--log-file` <LOGFILE>
136139
Specify a file to log output. Disabled by default.
137140

@@ -144,9 +147,6 @@ OPTIONS
144147
:option:`--debug`
145148
Show tracebacks on errors and set verbosity to debug
146149

147-
:option:`--enable-beta-commands`
148-
Enable beta commands which are subject to change
149-
150150
COMMANDS
151151
========
152152

functional/tests/network/v2/test_network_segment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def setUpClass(cls):
3434

3535
# Get the segment for the network.
3636
opts = cls.get_show_opts(['ID', 'Network'])
37-
raw_output = cls.openstack('--enable-beta-commands '
37+
raw_output = cls.openstack('--os-beta-command '
3838
'network segment list '
3939
' --network ' + cls.NETWORK_NAME +
4040
' ' + opts)
@@ -48,13 +48,13 @@ def tearDownClass(cls):
4848

4949
def test_network_segment_list(self):
5050
opts = self.get_list_opts(['ID'])
51-
raw_output = self.openstack('--enable-beta-commands '
51+
raw_output = self.openstack('--os-beta-command '
5252
'network segment list' + opts)
5353
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
5454

5555
def test_network_segment_show(self):
5656
opts = self.get_show_opts(['network_id'])
57-
raw_output = self.openstack('--enable-beta-commands '
57+
raw_output = self.openstack('--os-beta-command '
5858
'network segment show ' +
5959
self.NETWORK_SEGMENT_ID + opts)
6060
self.assertEqual(self.NETWORK_ID + "\n", raw_output)

openstackclient/common/command.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from cliff import show
2121
import six
2222

23+
from openstackclient.common import exceptions
24+
from openstackclient.i18n import _
25+
2326

2427
class CommandMeta(abc.ABCMeta):
2528

@@ -37,6 +40,13 @@ def run(self, parsed_args):
3740
self.log.debug('run(%s)', parsed_args)
3841
return super(Command, self).run(parsed_args)
3942

43+
def validate_os_beta_command_enabled(self):
44+
if not self.app.options.os_beta_command:
45+
msg = _('Caution: This is a beta command and subject to '
46+
'change. Use global option --os-beta-command '
47+
'to enable this command.')
48+
raise exceptions.CommandError(msg)
49+
4050

4151
class Lister(Command, lister.Lister):
4252
pass

openstackclient/network/v2/network_segment.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# TODO(rtheis): Add description and name properties when support is available.
1717

1818
from openstackclient.common import command
19-
from openstackclient.common import exceptions
2019
from openstackclient.common import utils
2120
from openstackclient.i18n import _
2221

@@ -25,7 +24,7 @@ class ListNetworkSegment(command.Lister):
2524
"""List network segments
2625
2726
(Caution: This is a beta command and subject to change.
28-
Use global option --enable-beta-commands to enable
27+
Use global option --os-beta-command to enable
2928
this command)
3029
"""
3130

@@ -46,11 +45,7 @@ def get_parser(self, prog_name):
4645
return parser
4746

4847
def take_action(self, parsed_args):
49-
if not self.app.options.enable_beta_commands:
50-
msg = _('Caution: This is a beta command and subject to '
51-
'change. Use global option --enable-beta-commands '
52-
'to enable this command.')
53-
raise exceptions.CommandError(msg)
48+
self.validate_os_beta_command_enabled()
5449

5550
network_client = self.app.client_manager.network
5651

@@ -94,7 +89,7 @@ class ShowNetworkSegment(command.ShowOne):
9489
"""Display network segment details
9590
9691
(Caution: This is a beta command and subject to change.
97-
Use global option --enable-beta-commands to enable
92+
Use global option --os-beta-command to enable
9893
this command)
9994
"""
10095

@@ -108,11 +103,7 @@ def get_parser(self, prog_name):
108103
return parser
109104

110105
def take_action(self, parsed_args):
111-
if not self.app.options.enable_beta_commands:
112-
msg = _('Caution: This is a beta command and subject to '
113-
'change. Use global option --enable-beta-commands '
114-
'to enable this command.')
115-
raise exceptions.CommandError(msg)
106+
self.validate_os_beta_command_enabled()
116107

117108
client = self.app.client_manager.network
118109
obj = client.find_segment(

openstackclient/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def build_option_parser(self, description, version):
251251
help="Print API call timing info",
252252
)
253253
parser.add_argument(
254-
'--enable-beta-commands',
254+
'--os-beta-command',
255255
action='store_true',
256256
help="Enable beta commands which are subject to change",
257257
)

openstackclient/tests/common/test_command.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import mock
1616

1717
from openstackclient.common import command
18+
from openstackclient.common import exceptions
19+
from openstackclient.tests import fakes as test_fakes
1820
from openstackclient.tests import utils as test_utils
1921

2022

@@ -31,3 +33,16 @@ def test_command_has_logger(self):
3133
self.assertTrue(hasattr(cmd, 'log'))
3234
self.assertEqual('openstackclient.tests.common.test_command.'
3335
'FakeCommand', cmd.log.name)
36+
37+
def test_validate_os_beta_command_enabled(self):
38+
cmd = FakeCommand(mock.Mock(), mock.Mock())
39+
cmd.app = mock.Mock()
40+
cmd.app.options = test_fakes.FakeOptions()
41+
42+
# No exception is raised when enabled.
43+
cmd.app.options.os_beta_command = True
44+
cmd.validate_os_beta_command_enabled()
45+
46+
cmd.app.options.os_beta_command = False
47+
self.assertRaises(exceptions.CommandError,
48+
cmd.validate_os_beta_command_enabled)

openstackclient/tests/fakes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, _stdout, _log):
9999

100100
class FakeOptions(object):
101101
def __init__(self, **kwargs):
102-
self.enable_beta_commands = False
102+
self.os_beta_command = False
103103

104104

105105
class FakeClient(object):

openstackclient/tests/network/v2/test_network_segment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self):
2525
super(TestNetworkSegment, self).setUp()
2626

2727
# Enable beta commands.
28-
self.app.options.enable_beta_commands = True
28+
self.app.options.os_beta_command = True
2929

3030
# Get a shortcut to the network client
3131
self.network = self.app.client_manager.network
@@ -89,7 +89,7 @@ def test_list_no_option(self):
8989
self.assertEqual(self.data, list(data))
9090

9191
def test_list_no_beta_commands(self):
92-
self.app.options.enable_beta_commands = False
92+
self.app.options.os_beta_command = False
9393
parsed_args = self.check_parser(self.cmd, [], [])
9494
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
9595
parsed_args)
@@ -174,7 +174,7 @@ def test_show_no_beta_commands(self):
174174
verifylist = [
175175
('network_segment', self._network_segment.id),
176176
]
177-
self.app.options.enable_beta_commands = False
177+
self.app.options.os_beta_command = False
178178
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
179179
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
180180
parsed_args)

0 commit comments

Comments
 (0)