Add a check for --config-drive option on nova boot

A value of the '--config-drive' option must be a boolean value
on the 'nova boot' command because nova accepts a boolean value
only for the 'config_drive' parameter.
So add a check for the '--config-drive' option on the 'nova boot'
command.

Fix a description for 'config_drive' parameter
in the 'create' method of the novaclient.v2.ServerManager class.

Change-Id: Ic6e65139302fbb662fb6ba60e73633dad8ffb72e
Closes-Bug: #1825061
This commit is contained in:
Takashi NATSUME 2019-07-17 11:40:24 +09:00
parent 730bc2c47e
commit d1c5dc61d6
5 changed files with 39 additions and 24 deletions

View File

@ -1089,7 +1089,8 @@ quality of service support, microversion ``2.72`` is required.
versions '2.42' - '2.latest') versions '2.42' - '2.latest')
``--config-drive <value>`` ``--config-drive <value>``
Enable config drive. Enable config drive. The value must be a
boolean value.
``--poll`` ``--poll``
Report the new server boot progress until it Report the new server boot progress until it

View File

@ -240,22 +240,6 @@ class ShellTest(utils.TestCase):
}}, }},
) )
def test_boot_config_drive(self):
self.run_command(
'boot --flavor 1 --image %s --config-drive 1 some-server' %
FAKE_UUID_1)
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': '1',
'name': 'some-server',
'imageRef': FAKE_UUID_1,
'min_count': 1,
'max_count': 1,
'config_drive': True
}},
)
def test_boot_access_ip(self): def test_boot_access_ip(self):
self.run_command( self.run_command(
'boot --flavor 1 --image %s --access-ip-v4 10.10.10.10 ' 'boot --flavor 1 --image %s --access-ip-v4 10.10.10.10 '
@ -273,9 +257,9 @@ class ShellTest(utils.TestCase):
}}, }},
) )
def test_boot_config_drive_custom(self): def test_boot_config_drive(self):
self.run_command( self.run_command(
'boot --flavor 1 --image %s --config-drive /dev/hda some-server' % 'boot --flavor 1 --image %s --config-drive 1 some-server' %
FAKE_UUID_1) FAKE_UUID_1)
self.assert_called_anytime( self.assert_called_anytime(
'POST', '/servers', 'POST', '/servers',
@ -285,10 +269,33 @@ class ShellTest(utils.TestCase):
'imageRef': FAKE_UUID_1, 'imageRef': FAKE_UUID_1,
'min_count': 1, 'min_count': 1,
'max_count': 1, 'max_count': 1,
'config_drive': '/dev/hda' 'config_drive': True
}}, }},
) )
def test_boot_config_drive_false(self):
self.run_command(
'boot --flavor 1 --image %s --config-drive false some-server' %
FAKE_UUID_1)
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': '1',
'name': 'some-server',
'imageRef': FAKE_UUID_1,
'min_count': 1,
'max_count': 1,
}},
)
def test_boot_config_drive_invalid_value(self):
ex = self.assertRaises(
exceptions.CommandError, self.run_command,
'boot --flavor 1 --image %s --config-drive /dev/hda some-server' %
FAKE_UUID_1)
self.assertIn("The value of the '--config-drive' option must be "
"a boolean value.", six.text_type(ex))
def test_boot_invalid_user_data(self): def test_boot_invalid_user_data(self):
invalid_file = os.path.join(os.path.dirname(__file__), invalid_file = os.path.join(os.path.dirname(__file__),
'no_such_file') 'no_such_file')

View File

@ -1375,8 +1375,8 @@ class ServerManager(base.BootingManagerWithFind):
any networking for the server. any networking for the server.
:param scheduler_hints: (optional extension) arbitrary key-value pairs :param scheduler_hints: (optional extension) arbitrary key-value pairs
specified by the client to help boot an instance specified by the client to help boot an instance
:param config_drive: (optional extension) value for config drive :param config_drive: (optional extension) a boolean value to enable
either boolean, or volume-id config drive
:param disk_config: (optional extension) control how the disk is :param disk_config: (optional extension) control how the disk is
partitioned when the server is created. possible partitioned when the server is created. possible
values are 'AUTO' or 'MANUAL'. values are 'AUTO' or 'MANUAL'.

View File

@ -506,7 +506,9 @@ def _boot(cs, args):
elif str(args.config_drive).lower() in ("false", "0", "", "none"): elif str(args.config_drive).lower() in ("false", "0", "", "none"):
config_drive = None config_drive = None
else: else:
config_drive = args.config_drive raise exceptions.CommandError(
_("The value of the '--config-drive' option must be "
"a boolean value."))
boot_kwargs = dict( boot_kwargs = dict(
meta=meta, meta=meta,
@ -906,7 +908,7 @@ def _boot(cs, args):
metavar="<value>", metavar="<value>",
dest='config_drive', dest='config_drive',
default=False, default=False,
help=_("Enable config drive.")) help=_("Enable config drive. The value must be a boolean value."))
@utils.arg( @utils.arg(
'--poll', '--poll',
dest='poll', dest='poll',

View File

@ -0,0 +1,5 @@
---
fixes:
- |
A check for a value of the '--config-drive' option has been added on the
``nova boot`` command. A boolean value is only allowed in the option now.