Skip to content

Commit 6a914d0

Browse files
qiangtangDean Troyer
authored andcommitted
Support mark volume as bootable in volume set
Add --bootable | --non-bootable option in volume set to mark or unmark volume as bootable. Change-Id: Ifa6c2dd1642202f55b6d50e3b8614d3513d488f6 Closes-Bug:#1535704
1 parent d2273ec commit 6a914d0

8 files changed

Lines changed: 126 additions & 1 deletion

File tree

doc/source/command-objects/volume.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Set volume properties
193193
[--property <key=value> [...] ]
194194
[--image-property <key=value> [...] ]
195195
[--state <state>]
196+
[--bootable | --non-bootable]
196197
<volume>
197198
198199
.. option:: --name <name>
@@ -211,6 +212,14 @@ Set volume properties
211212
212213
Set a property on this volume (repeat option to set multiple properties)
213214
215+
.. option:: --bootable
216+
217+
Mark volume as bootable
218+
219+
.. option:: --non-bootable
220+
221+
Mark volume as non-bootable
222+
214223
.. option:: --image-property <key=value>
215224
216225
Set an image property on this volume

openstackclient/tests/functional/volume/v1/test_volume.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ def test_volume_set_size(self):
7575
opts = self.get_opts(["display_name", "size"])
7676
raw_output = self.openstack('volume show ' + self.NAME + opts)
7777
self.assertEqual(self.NAME + "\n2\n", raw_output)
78+
79+
def test_volume_set_bootable(self):
80+
self.openstack('volume set --bootable ' + self.NAME)
81+
opts = self.get_opts(["bootable"])
82+
raw_output = self.openstack('volume show ' + self.NAME + opts)
83+
self.assertEqual("true\n", raw_output)
84+
85+
self.openstack('volume set --non-bootable ' + self.NAME)
86+
opts = self.get_opts(["bootable"])
87+
raw_output = self.openstack('volume show ' + self.NAME + opts)
88+
self.assertEqual("false\n", raw_output)

openstackclient/tests/functional/volume/v2/test_volume.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ def test_volume_set_size(self):
9191
raw_output = self.openstack('volume show ' + self.NAME + opts)
9292
self.assertEqual(self.NAME + "\n2\n", raw_output)
9393

94+
def test_volume_set_bootable(self):
95+
self.openstack('volume set --bootable ' + self.NAME)
96+
opts = self.get_opts(["bootable"])
97+
raw_output = self.openstack('volume show ' + self.NAME + opts)
98+
self.assertEqual("true\n", raw_output)
99+
100+
self.openstack('volume set --non-bootable ' + self.NAME)
101+
opts = self.get_opts(["bootable"])
102+
raw_output = self.openstack('volume show ' + self.NAME + opts)
103+
self.assertEqual("false\n", raw_output)
104+
94105
def test_volume_snapshot(self):
95106
opts = self.get_opts(self.FIELDS)
96107

openstackclient/tests/unit/volume/v1/test_volume.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,8 @@ def test_volume_set_property(self):
844844
('size', None),
845845
('property', {'myprop': 'myvalue'}),
846846
('volume', volume_fakes.volume_name),
847+
('bootable', False),
848+
('non_bootable', False)
847849
]
848850
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
849851

@@ -858,3 +860,28 @@ def test_volume_set_property(self):
858860
metadata
859861
)
860862
self.assertIsNone(result)
863+
864+
def test_volume_set_bootable(self):
865+
arglist = [
866+
['--bootable', volume_fakes.volume_id],
867+
['--non-bootable', volume_fakes.volume_id]
868+
]
869+
verifylist = [
870+
[
871+
('bootable', True),
872+
('non_bootable', False),
873+
('volume', volume_fakes.volume_id)
874+
],
875+
[
876+
('bootable', False),
877+
('non_bootable', True),
878+
('volume', volume_fakes.volume_id)
879+
]
880+
]
881+
for index in range(len(arglist)):
882+
parsed_args = self.check_parser(
883+
self.cmd, arglist[index], verifylist[index])
884+
885+
self.cmd.take_action(parsed_args)
886+
self.volumes_mock.set_bootable.assert_called_with(
887+
volume_fakes.volume_id, verifylist[index][0][1])

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ def test_volume_set_image_property(self):
905905
verifylist = [
906906
('image_property', {'Alpha': 'a', 'Beta': 'b'}),
907907
('volume', self.new_volume.id),
908+
('bootable', False),
909+
('non_bootable', False)
908910
]
909911
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
910912

@@ -952,6 +954,31 @@ def test_volume_set_state_failed(self):
952954
self.volumes_mock.reset_state.assert_called_with(
953955
self.new_volume.id, 'error')
954956

957+
def test_volume_set_bootable(self):
958+
arglist = [
959+
['--bootable', self.new_volume.id],
960+
['--non-bootable', self.new_volume.id]
961+
]
962+
verifylist = [
963+
[
964+
('bootable', True),
965+
('non_bootable', False),
966+
('volume', self.new_volume.id)
967+
],
968+
[
969+
('bootable', False),
970+
('non_bootable', True),
971+
('volume', self.new_volume.id)
972+
]
973+
]
974+
for index in range(len(arglist)):
975+
parsed_args = self.check_parser(
976+
self.cmd, arglist[index], verifylist[index])
977+
978+
self.cmd.take_action(parsed_args)
979+
self.volumes_mock.set_bootable.assert_called_with(
980+
self.new_volume.id, verifylist[index][0][1])
981+
955982

956983
class TestVolumeShow(TestVolume):
957984

openstackclient/volume/v1/volume.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ def get_parser(self, prog_name):
363363
help=_('Set a property on this volume '
364364
'(repeat option to set multiple properties)'),
365365
)
366+
bootable_group = parser.add_mutually_exclusive_group()
367+
bootable_group.add_argument(
368+
"--bootable",
369+
action="store_true",
370+
help=_("Mark volume as bootable")
371+
)
372+
bootable_group.add_argument(
373+
"--non-bootable",
374+
action="store_true",
375+
help=_("Mark volume as non-bootable")
376+
)
366377
return parser
367378

368379
def take_action(self, parsed_args):
@@ -382,7 +393,12 @@ def take_action(self, parsed_args):
382393

383394
if parsed_args.property:
384395
volume_client.volumes.set_metadata(volume.id, parsed_args.property)
385-
396+
if parsed_args.bootable or parsed_args.non_bootable:
397+
try:
398+
volume_client.volumes.set_bootable(
399+
volume.id, parsed_args.bootable)
400+
except Exception as e:
401+
LOG.error(_("Failed to set volume bootable property: %s"), e)
386402
kwargs = {}
387403
if parsed_args.name:
388404
kwargs['display_name'] = parsed_args.name

openstackclient/volume/v2/volume.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,17 @@ def get_parser(self, prog_name):
404404
'"deleting", "in-use", "attaching", "detaching", '
405405
'"error_deleting" or "maintenance")'),
406406
)
407+
bootable_group = parser.add_mutually_exclusive_group()
408+
bootable_group.add_argument(
409+
"--bootable",
410+
action="store_true",
411+
help=_("Mark volume as bootable")
412+
)
413+
bootable_group.add_argument(
414+
"--non-bootable",
415+
action="store_true",
416+
help=_("Mark volume as non-bootable")
417+
)
407418
return parser
408419

409420
def take_action(self, parsed_args):
@@ -446,6 +457,13 @@ def take_action(self, parsed_args):
446457
except Exception as e:
447458
LOG.error(_("Failed to set volume state: %s"), e)
448459
result += 1
460+
if parsed_args.bootable or parsed_args.non_bootable:
461+
try:
462+
volume_client.volumes.set_bootable(
463+
volume.id, parsed_args.bootable)
464+
except Exception as e:
465+
LOG.error(_("Failed to set volume bootable property: %s"), e)
466+
result += 1
449467

450468
kwargs = {}
451469
if parsed_args.name:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Add ``--bootable`` and ``--non-bootable`` options to ``os volume set``
5+
command to mark volume as bootable or non-bootable.
6+
[Bug `1535704 <https://bugs.launchpad.net/bugs/1535704>`_]

0 commit comments

Comments
 (0)