Skip to content

Commit 12f1e56

Browse files
committed
Add 'openstack server create --use-config-drive'
Despite what the help text for this options says, the nova API only accepts boolean values for this value and has done so since at least the introduction of the 2.1 microversioned API. While it would be nice to convert '--config-drive' to a boolean flag, we'd need to be able to retain temporary support for people passing arguments. 'nargs=?' [1] looks promising but it has an annoying tendency to swallow a positional argument following it [2]. Since that is not an option, we have to live with a new config option, '--use-config-drive' and a '--no-config-drive' counterpart. [1] https://docs.python.org/3/library/argparse.html#nargs [2] https://bugs.python.org/issue9338 Change-Id: If9cce0ad4094cc9cef1c9136b80c3b0f35a82c7a Signed-off-by: Stephen Finucane <sfinucan@redhat.com> Story: #2005468 Task: #30547
1 parent 82ebddc commit 12f1e56

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,30 @@ def get_parser(self, prog_name):
693693
default={},
694694
help=_('Hints for the scheduler (optional extension)'),
695695
)
696-
parser.add_argument(
696+
config_drive_group = parser.add_mutually_exclusive_group()
697+
config_drive_group.add_argument(
698+
'--use-config-drive',
699+
action='store_true',
700+
dest='config_drive',
701+
help=_("Enable config drive."),
702+
)
703+
config_drive_group.add_argument(
704+
'--no-config-drive',
705+
action='store_false',
706+
dest='config_drive',
707+
help=_("Disable config drive."),
708+
)
709+
# TODO(stephenfin): Drop support in the next major version bump after
710+
# Victoria
711+
config_drive_group.add_argument(
697712
'--config-drive',
698713
metavar='<config-drive-volume>|True',
699714
default=False,
700-
help=_('Use specified volume as the config drive, '
701-
'or \'True\' to use an ephemeral drive'),
715+
help=_(
716+
"**Deprecated** Use specified volume as the config drive, "
717+
"or 'True' to use an ephemeral drive. Replaced by "
718+
"'--use-config-drive'."
719+
),
702720
)
703721
parser.add_argument(
704722
'--min',
@@ -991,16 +1009,19 @@ def _match_image(image_api, wanted_properties):
9911009
else:
9921010
hints[key] = values
9931011

994-
# What does a non-boolean value for config-drive do?
995-
# --config-drive argument is either a volume id or
996-
# 'True' (or '1') to use an ephemeral volume
997-
if str(parsed_args.config_drive).lower() in ("true", "1"):
998-
config_drive = True
999-
elif str(parsed_args.config_drive).lower() in ("false", "0",
1000-
"", "none"):
1001-
config_drive = None
1012+
if isinstance(parsed_args.config_drive, bool):
1013+
# NOTE(stephenfin): The API doesn't accept False as a value :'(
1014+
config_drive = parsed_args.config_drive or None
10021015
else:
1003-
config_drive = parsed_args.config_drive
1016+
# TODO(stephenfin): Remove when we drop support for
1017+
# '--config-drive'
1018+
if str(parsed_args.config_drive).lower() in ("true", "1"):
1019+
config_drive = True
1020+
elif str(parsed_args.config_drive).lower() in ("false", "0",
1021+
"", "none"):
1022+
config_drive = None
1023+
else:
1024+
config_drive = parsed_args.config_drive
10041025

10051026
boot_kwargs = dict(
10061027
meta=parsed_args.property,

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ def test_server_create_with_options(self):
857857
'--key-name', 'keyname',
858858
'--property', 'Beta=b',
859859
'--security-group', 'securitygroup',
860+
'--use-config-drive',
860861
'--hint', 'a=b',
861862
'--hint', 'a=c',
862863
self.new_server.name,
@@ -868,7 +869,7 @@ def test_server_create_with_options(self):
868869
('property', {'Beta': 'b'}),
869870
('security_group', ['securitygroup']),
870871
('hint', {'a': ['b', 'c']}),
871-
('config_drive', False),
872+
('config_drive', True),
872873
('server_name', self.new_server.name),
873874
]
874875
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -900,7 +901,7 @@ def test_server_create_with_options(self):
900901
block_device_mapping_v2=[],
901902
nics=[],
902903
scheduler_hints={'a': ['b', 'c']},
903-
config_drive=None,
904+
config_drive=True,
904905
)
905906
# ServerManager.create(name, image, flavor, **kwargs)
906907
self.servers_mock.create.assert_called_with(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
deprecations:
3+
- |
4+
The ``--config-drive`` option on the ``openstack server create`` command
5+
has been deprecated in favour of the ``--use-config-drive`` and
6+
``--no-config-drive`` arguments. The ``--config-drive`` option expected
7+
either a string or bool-like argument, but the nova API has only supported
8+
boolean values since API v2.1 was introduced.

0 commit comments

Comments
 (0)