summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-04 13:05:30 +0000
committerGerrit Code Review <review@openstack.org>2016-06-04 13:05:30 +0000
commit55a7ba890d9c3a53b7728efe41053b79ba1e60d3 (patch)
tree2c093d1e78fee714a3cf3e57f9ccbf91ad3cec04 /openstackclient
parent416792f079e7d15d8747736ee792d1f5c30aa389 (diff)
parent6f2c1734e3d66e261f231711455821321c1fc254 (diff)
downloadpython-openstackclient-55a7ba890d9c3a53b7728efe41053b79ba1e60d3.tar.gz
Merge "Fix --enable options on commands"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/common/command.py10
-rw-r--r--openstackclient/network/v2/network_segment.py17
-rw-r--r--openstackclient/shell.py2
-rw-r--r--openstackclient/tests/common/test_command.py15
-rw-r--r--openstackclient/tests/fakes.py2
-rw-r--r--openstackclient/tests/network/v2/test_network_segment.py6
6 files changed, 34 insertions, 18 deletions
diff --git a/openstackclient/common/command.py b/openstackclient/common/command.py
index fee4559e..144a0db1 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 d8a91fd2..818ffc02 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 9968d73f..9179ad01 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 7467d9eb..722a4c06 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 7fb1daa9..ad4705a4 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 2822581c..0a99eced 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)