Skip to content

Commit 89e5d67

Browse files
committed
Fix "server create"command with --boot-from-volume
This patch modifes the "server create --boot-from-volume" command without image option print "'NoneType' object has no attribute 'id'" story: 2010892 task: 48669 Change-Id: I566f81c285d4ebc1e23ea0762d67492fb6b3bcbe
1 parent 29f2444 commit 89e5d67

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,12 @@ def _match_image(image_api, wanted_properties):
15801580
]
15811581
elif parsed_args.boot_from_volume:
15821582
# Tell nova to create a root volume from the image provided.
1583+
if not image:
1584+
msg = _(
1585+
"An image (--image or --image-property) is required "
1586+
"to support --boot-from-volume option"
1587+
)
1588+
raise exceptions.CommandError(msg)
15831589
block_device_mapping_v2 = [
15841590
{
15851591
'uuid': image.id,

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,6 +3436,34 @@ def test_server_create_volume_boot_from_volume_conflict(self):
34363436
'--volume is not allowed with --boot-from-volume', str(ex)
34373437
)
34383438

3439+
def test_server_create_boot_from_volume_no_image(self):
3440+
# Test --boot-from-volume option without --image or
3441+
# --image-property.
3442+
arglist = [
3443+
'--flavor',
3444+
self.flavor.id,
3445+
'--boot-from-volume',
3446+
'1',
3447+
self.new_server.name,
3448+
]
3449+
verifylist = [
3450+
('flavor', self.flavor.id),
3451+
('boot_from_volume', 1),
3452+
('config_drive', False),
3453+
('server_name', self.new_server.name),
3454+
]
3455+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3456+
3457+
ex = self.assertRaises(
3458+
exceptions.CommandError, self.cmd.take_action, parsed_args
3459+
)
3460+
# Assert it is the error we expect.
3461+
self.assertIn(
3462+
'An image (--image or --image-property) is required '
3463+
'to support --boot-from-volume option',
3464+
str(ex),
3465+
)
3466+
34393467
def test_server_create_image_property(self):
34403468
arglist = [
34413469
'--image-property',

0 commit comments

Comments
 (0)