summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/tests/volume/v2/test_volume.py30
-rw-r--r--openstackclient/volume/v2/volume.py13
2 files changed, 42 insertions, 1 deletions
diff --git a/openstackclient/tests/volume/v2/test_volume.py b/openstackclient/tests/volume/v2/test_volume.py
index a836f79e..29fc391e 100644
--- a/openstackclient/tests/volume/v2/test_volume.py
+++ b/openstackclient/tests/volume/v2/test_volume.py
@@ -753,3 +753,33 @@ class TestVolumeShow(TestVolume):
self.assertEqual(volume_fakes.VOLUME_columns, columns)
self.assertEqual(volume_fakes.VOLUME_data, data)
+
+
+class TestVolumeSet(TestVolume):
+
+ def setUp(self):
+ super(TestVolumeSet, self).setUp()
+
+ self.new_volume = volume_fakes.FakeVolume.create_one_volume()
+ self.volumes_mock.create.return_value = self.new_volume
+
+ # Get the command object to test
+ self.cmd = volume.SetVolume(self.app, None)
+
+ def test_volume_set_image_property(self):
+ arglist = [
+ '--image-property', 'Alpha=a',
+ '--image-property', 'Beta=b',
+ self.new_volume.id,
+ ]
+ verifylist = [
+ ('image_property', {'Alpha': 'a', 'Beta': 'b'}),
+ ('volume', self.new_volume.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns nothing
+ self.cmd.take_action(parsed_args)
+ self.volumes_mock.set_image_metadata.assert_called_with(
+ self.volumes_mock.get().id, parsed_args.image_property)
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
index 8f2122eb..9b58d73d 100644
--- a/openstackclient/volume/v2/volume.py
+++ b/openstackclient/volume/v2/volume.py
@@ -345,6 +345,13 @@ class SetVolume(command.Command):
help='Property to add or modify for this volume '
'(repeat option to set multiple properties)',
)
+ parser.add_argument(
+ '--image-property',
+ metavar='<key=value>',
+ action=parseractions.KeyValueAction,
+ help='To add or modify image properties for this volume '
+ '(repeat option to set multiple image properties)',
+ )
return parser
def take_action(self, parsed_args):
@@ -365,6 +372,9 @@ class SetVolume(command.Command):
if parsed_args.property:
volume_client.volumes.set_metadata(volume.id, parsed_args.property)
+ if parsed_args.image_property:
+ volume_client.volumes.set_image_metadata(
+ volume.id, parsed_args.image_property)
kwargs = {}
if parsed_args.name:
@@ -374,7 +384,8 @@ class SetVolume(command.Command):
if kwargs:
volume_client.volumes.update(volume.id, **kwargs)
- if not kwargs and not parsed_args.property and not parsed_args.size:
+ if (not kwargs and not parsed_args.property
+ and not parsed_args.image_property and not parsed_args.size):
self.app.log.error("No changes requested\n")