Skip to content

Commit 4d5c5d9

Browse files
ranasheel2000Steve Martinelli
authored andcommitted
Add support for setting Image-property
OSC does not support to set volume's image property. This patch will provide support for adding image property to existing volume. Closes-Bug:#1554877 Implements: bp cinder-command-support Change-Id: I4ff5532c228f010789b81c7587dd4a2838a90f20
1 parent d88284c commit 4d5c5d9

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

doc/source/command-objects/volume.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Set volume properties
164164
[--description <description>]
165165
[--size <size>]
166166
[--property <key=value> [...] ]
167+
[--image-property <key=value> [...] ]
167168
<volume>
168169
169170
.. option:: --name <name>
@@ -182,6 +183,13 @@ Set volume properties
182183
183184
Property to add or modify for this volume (repeat option to set multiple properties)
184185
186+
.. option:: --image-property <key=value>
187+
188+
To add or modify image properties for this volume.
189+
(repeat option to set multiple image properties)
190+
191+
*Volume version 2 only*
192+
185193
.. describe:: <volume>
186194
187195
Volume to modify (name or ID)

openstackclient/tests/volume/v2/test_volume.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,33 @@ def test_volume_show(self):
753753

754754
self.assertEqual(volume_fakes.VOLUME_columns, columns)
755755
self.assertEqual(volume_fakes.VOLUME_data, data)
756+
757+
758+
class TestVolumeSet(TestVolume):
759+
760+
def setUp(self):
761+
super(TestVolumeSet, self).setUp()
762+
763+
self.new_volume = volume_fakes.FakeVolume.create_one_volume()
764+
self.volumes_mock.create.return_value = self.new_volume
765+
766+
# Get the command object to test
767+
self.cmd = volume.SetVolume(self.app, None)
768+
769+
def test_volume_set_image_property(self):
770+
arglist = [
771+
'--image-property', 'Alpha=a',
772+
'--image-property', 'Beta=b',
773+
self.new_volume.id,
774+
]
775+
verifylist = [
776+
('image_property', {'Alpha': 'a', 'Beta': 'b'}),
777+
('volume', self.new_volume.id),
778+
]
779+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
780+
781+
# In base command class ShowOne in cliff, abstract method take_action()
782+
# returns nothing
783+
self.cmd.take_action(parsed_args)
784+
self.volumes_mock.set_image_metadata.assert_called_with(
785+
self.volumes_mock.get().id, parsed_args.image_property)

openstackclient/volume/v2/volume.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ def get_parser(self, prog_name):
345345
help='Property to add or modify for this volume '
346346
'(repeat option to set multiple properties)',
347347
)
348+
parser.add_argument(
349+
'--image-property',
350+
metavar='<key=value>',
351+
action=parseractions.KeyValueAction,
352+
help='To add or modify image properties for this volume '
353+
'(repeat option to set multiple image properties)',
354+
)
348355
return parser
349356

350357
def take_action(self, parsed_args):
@@ -365,6 +372,9 @@ def take_action(self, parsed_args):
365372

366373
if parsed_args.property:
367374
volume_client.volumes.set_metadata(volume.id, parsed_args.property)
375+
if parsed_args.image_property:
376+
volume_client.volumes.set_image_metadata(
377+
volume.id, parsed_args.image_property)
368378

369379
kwargs = {}
370380
if parsed_args.name:
@@ -374,7 +384,8 @@ def take_action(self, parsed_args):
374384
if kwargs:
375385
volume_client.volumes.update(volume.id, **kwargs)
376386

377-
if not kwargs and not parsed_args.property and not parsed_args.size:
387+
if (not kwargs and not parsed_args.property
388+
and not parsed_args.image_property and not parsed_args.size):
378389
self.app.log.error("No changes requested\n")
379390

380391

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
fixes:
3+
- |
4+
Added support for setting volume image property.
5+
6+
Image properties are copied from image when volume is created.
7+
But since a volume is mutable, user sometime wants to update
8+
image properties for volume.
9+
10+
So, this fix enables user to update image properties of volume
11+
using below command:
12+
``volume set --image-property <key=value> <volume>``.
13+
14+
[Bug 'https://bugs.launchpad.net/python-openstackclient/+bug/1554877'_]

0 commit comments

Comments
 (0)