From 89e5d67a16bd86af7bbe8480252686e2eef55095 Mon Sep 17 00:00:00 2001 From: rladntjr4 Date: Fri, 25 Aug 2023 02:30:32 +0900 Subject: [PATCH] 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 --- openstackclient/compute/v2/server.py | 6 ++++ .../tests/unit/compute/v2/test_server.py | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 61fffe2d3b..3f31bc26e4 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1580,6 +1580,12 @@ class CreateServer(command.ShowOne): ] elif parsed_args.boot_from_volume: # Tell nova to create a root volume from the image provided. + if not image: + msg = _( + "An image (--image or --image-property) is required " + "to support --boot-from-volume option" + ) + raise exceptions.CommandError(msg) block_device_mapping_v2 = [ { 'uuid': image.id, diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 5ed5eee927..42fea03de9 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -3436,6 +3436,34 @@ class TestServerCreate(TestServer): '--volume is not allowed with --boot-from-volume', str(ex) ) + def test_server_create_boot_from_volume_no_image(self): + # Test --boot-from-volume option without --image or + # --image-property. + arglist = [ + '--flavor', + self.flavor.id, + '--boot-from-volume', + '1', + self.new_server.name, + ] + verifylist = [ + ('flavor', self.flavor.id), + ('boot_from_volume', 1), + ('config_drive', False), + ('server_name', self.new_server.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + ex = self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args + ) + # Assert it is the error we expect. + self.assertIn( + 'An image (--image or --image-property) is required ' + 'to support --boot-from-volume option', + str(ex), + ) + def test_server_create_image_property(self): arglist = [ '--image-property',