Make 'server list --config-drive' a boolean option
Instead of passing through whatever the user provides and exposing this bug in the REST API, simply make the opt a boolean one in expectation of a day where the API issues have been resolved. This also introduces machinery necessary to use more of these types of opts in the future. Change-Id: I9033540ac65ac0ee7337f16bdd002060652092ea Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
d712c0fbc7
commit
ea092b2988
|
@ -2224,7 +2224,7 @@ nova list
|
||||||
[--fields <fields>] [--minimal]
|
[--fields <fields>] [--minimal]
|
||||||
[--sort <key>[:<direction>]] [--marker <marker>]
|
[--sort <key>[:<direction>]] [--marker <marker>]
|
||||||
[--limit <limit>] [--availability-zone <availability_zone>]
|
[--limit <limit>] [--availability-zone <availability_zone>]
|
||||||
[--key-name <key_name>] [--config-drive <config_drive>]
|
[--key-name <key_name>] [--[no-]config-drive]
|
||||||
[--progress <progress>] [--vm-state <vm_state>]
|
[--progress <progress>] [--vm-state <vm_state>]
|
||||||
[--task-state <task_state>] [--power-state <power_state>]
|
[--task-state <task_state>] [--power-state <power_state>]
|
||||||
[--changes-since <changes_since>]
|
[--changes-since <changes_since>]
|
||||||
|
@ -2316,10 +2316,13 @@ present in the failure domain.
|
||||||
Display servers based on their keypair name
|
Display servers based on their keypair name
|
||||||
(Admin only until microversion 2.82).
|
(Admin only until microversion 2.82).
|
||||||
|
|
||||||
``--config-drive <config_drive>``
|
``--config-drive``
|
||||||
Display servers based on their config_drive value
|
Display servers that have a config drive attached.
|
||||||
The value must be a boolean. (Admin only until
|
(Admin only until microversion 2.82).
|
||||||
microversion 2.82).
|
|
||||||
|
``--no-config-drive``
|
||||||
|
Display servers that do not have a config drive attached.
|
||||||
|
(Admin only until microversion 2.82).
|
||||||
|
|
||||||
``--progress <progress>``
|
``--progress <progress>``
|
||||||
Display servers based on their progress value
|
Display servers based on their progress value
|
||||||
|
|
|
@ -442,6 +442,7 @@ class OpenStackComputeShell(object):
|
||||||
|
|
||||||
action_help = desc.strip()
|
action_help = desc.strip()
|
||||||
arguments = getattr(callback, 'arguments', [])
|
arguments = getattr(callback, 'arguments', [])
|
||||||
|
groups = {}
|
||||||
|
|
||||||
subparser = subparsers.add_parser(
|
subparser = subparsers.add_parser(
|
||||||
command,
|
command,
|
||||||
|
@ -456,10 +457,14 @@ class OpenStackComputeShell(object):
|
||||||
)
|
)
|
||||||
self.subcommands[command] = subparser
|
self.subcommands[command] = subparser
|
||||||
for (args, kwargs) in arguments:
|
for (args, kwargs) in arguments:
|
||||||
start_version = kwargs.get("start_version", None)
|
kwargs = kwargs.copy()
|
||||||
|
|
||||||
|
start_version = kwargs.pop("start_version", None)
|
||||||
|
end_version = kwargs.pop("end_version", None)
|
||||||
|
group = kwargs.pop("group", None)
|
||||||
|
|
||||||
if start_version:
|
if start_version:
|
||||||
start_version = api_versions.APIVersion(start_version)
|
start_version = api_versions.APIVersion(start_version)
|
||||||
end_version = kwargs.get("end_version", None)
|
|
||||||
if end_version:
|
if end_version:
|
||||||
end_version = api_versions.APIVersion(end_version)
|
end_version = api_versions.APIVersion(end_version)
|
||||||
else:
|
else:
|
||||||
|
@ -471,10 +476,16 @@ class OpenStackComputeShell(object):
|
||||||
"end": end_version.get_string()})
|
"end": end_version.get_string()})
|
||||||
if not version.matches(start_version, end_version):
|
if not version.matches(start_version, end_version):
|
||||||
continue
|
continue
|
||||||
kw = kwargs.copy()
|
|
||||||
kw.pop("start_version", None)
|
if group:
|
||||||
kw.pop("end_version", None)
|
if group not in groups:
|
||||||
subparser.add_argument(*args, **kw)
|
groups[group] = (
|
||||||
|
subparser.add_mutually_exclusive_group()
|
||||||
|
)
|
||||||
|
kwargs['dest'] = kwargs.get('dest', group)
|
||||||
|
groups[group].add_argument(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
subparser.add_argument(*args, **kwargs)
|
||||||
subparser.set_defaults(func=callback)
|
subparser.set_defaults(func=callback)
|
||||||
|
|
||||||
def setup_debugging(self, debug):
|
def setup_debugging(self, debug):
|
||||||
|
|
|
@ -1846,18 +1846,17 @@ class ShellTest(utils.TestCase):
|
||||||
self.run_command('list --key-name my_key')
|
self.run_command('list --key-name my_key')
|
||||||
self.assert_called('GET', '/servers/detail?key_name=my_key')
|
self.assert_called('GET', '/servers/detail?key_name=my_key')
|
||||||
|
|
||||||
def test_list_with_config_drive_passing_through_any_value(self):
|
def test_list_with_config_drive(self):
|
||||||
self.run_command('list --config-drive True')
|
self.run_command('list --config-drive')
|
||||||
self.assert_called('GET', '/servers/detail?config_drive=True')
|
self.assert_called('GET', '/servers/detail?config_drive=True')
|
||||||
self.run_command('list --config-drive some-random-string')
|
|
||||||
self.assert_called(
|
def test_list_with_no_config_drive(self):
|
||||||
'GET', '/servers/detail?config_drive=some-random-string')
|
self.run_command('list --no-config-drive')
|
||||||
# This form is special for the test env to pass through an empty string
|
self.assert_called('GET', '/servers/detail?config_drive=False')
|
||||||
# as a parameter. The real CLI call would look like
|
|
||||||
# list --config drive ''
|
def test_list_with_conflicting_config_drive(self):
|
||||||
self.run_command(['list', '--config-drive', ''])
|
self.assertRaises(SystemExit, self.run_command,
|
||||||
self.assert_called(
|
'list --config-drive --no-config-drive')
|
||||||
'GET', '/servers/detail?config_drive=')
|
|
||||||
|
|
||||||
def test_list_with_progress(self):
|
def test_list_with_progress(self):
|
||||||
self.run_command('list --progress 100')
|
self.run_command('list --progress 100')
|
||||||
|
|
|
@ -893,12 +893,11 @@ class ServerManager(base.BootingManagerWithFind):
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
val = val.encode('utf-8')
|
val = val.encode('utf-8')
|
||||||
qparams[opt] = val
|
qparams[opt] = val
|
||||||
# NOTE(gibi): After we fixing bug 1871409 and cleaning up the API
|
# NOTE(gibi): The False value won't actually do anything until we
|
||||||
# inconsistency around config_drive we can make the
|
# fix bug 1871409 and clean up the API inconsistency, but we do it
|
||||||
# config_drive filter a boolean filter. But until that we
|
# in preparation for that (hopefully backportable) fix
|
||||||
# simply pass through any value to the API even empty string.
|
|
||||||
if opt == 'config_drive' and val is not None:
|
if opt == 'config_drive' and val is not None:
|
||||||
qparams[opt] = val
|
qparams[opt] = str(val)
|
||||||
|
|
||||||
detail = ""
|
detail = ""
|
||||||
if detailed:
|
if detailed:
|
||||||
|
|
|
@ -1544,16 +1544,21 @@ def _print_flavor(flavor):
|
||||||
default=None,
|
default=None,
|
||||||
help=_('Display servers based on their keypair name (Admin only until '
|
help=_('Display servers based on their keypair name (Admin only until '
|
||||||
'microversion 2.82).'))
|
'microversion 2.82).'))
|
||||||
# NOTE(gibi): we can make this a real boolean filter after bug 1871409 is fixed
|
|
||||||
# and the REST API is cleaned up regarding the values of config_drive. Unit
|
|
||||||
# that we simply pass through any string from the user to the REST API.
|
|
||||||
@utils.arg(
|
@utils.arg(
|
||||||
'--config-drive',
|
'--config-drive',
|
||||||
dest='config_drive',
|
action='store_true',
|
||||||
metavar='<config_drive>',
|
group='config_drive',
|
||||||
default=None,
|
default=None,
|
||||||
help=_('Display servers based on their config_drive value (Admin only '
|
help=_('Display servers that have a config drive attached. (Admin only '
|
||||||
'until microversion 2.82). The value must be a boolean value.'))
|
'until microversion 2.82).'))
|
||||||
|
# NOTE(gibi): this won't actually do anything until bug 1871409 is fixed
|
||||||
|
# and the REST API is cleaned up regarding the values of config_drive
|
||||||
|
@utils.arg(
|
||||||
|
'--no-config-drive',
|
||||||
|
action='store_false',
|
||||||
|
group='config_drive',
|
||||||
|
help=_('Display servers that do not have a config drive attached (Admin '
|
||||||
|
'only until microversion 2.82)'))
|
||||||
@utils.arg(
|
@utils.arg(
|
||||||
'--progress',
|
'--progress',
|
||||||
dest='progress',
|
dest='progress',
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
* --availability-zone
|
* --availability-zone
|
||||||
* --config-drive
|
* --config-drive
|
||||||
|
* --no-config-drive
|
||||||
* --key-name
|
* --key-name
|
||||||
* --power-state
|
* --power-state
|
||||||
* --task-state
|
* --task-state
|
||||||
|
|
Loading…
Reference in New Issue