Skip to content

Commit bba5c90

Browse files
author
Huanxuan Ao
committed
Fix "volume unset" command pass normally when nothing specified
When nothing specified in "volume unset" command, there will be an error message says that the "--properties" option is required, it is unusual behaviour, this patch fix it and also add unit test for it. Also, this patch add unit test for "volume show" command by the way. Change-Id: I5b5d587670acf0af4262b8521292455bf9f60fe5 Partial-bug: #1588588
1 parent 4a8b802 commit bba5c90

2 files changed

Lines changed: 99 additions & 2 deletions

File tree

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,3 +880,102 @@ def test_volume_set_bootable(self):
880880
self.cmd.take_action(parsed_args)
881881
self.volumes_mock.set_bootable.assert_called_with(
882882
self._volume.id, verifylist[index][0][1])
883+
884+
885+
class TestVolumeShow(TestVolume):
886+
887+
columns = (
888+
'attachments',
889+
'availability_zone',
890+
'bootable',
891+
'created_at',
892+
'display_description',
893+
'display_name',
894+
'id',
895+
'properties',
896+
'size',
897+
'snapshot_id',
898+
'status',
899+
'type',
900+
)
901+
902+
def setUp(self):
903+
super(TestVolumeShow, self).setUp()
904+
self._volume = volume_fakes.FakeVolume.create_one_volume()
905+
self.datalist = (
906+
self._volume.attachments,
907+
self._volume.availability_zone,
908+
self._volume.bootable,
909+
self._volume.created_at,
910+
self._volume.display_description,
911+
self._volume.display_name,
912+
self._volume.id,
913+
utils.format_dict(self._volume.metadata),
914+
self._volume.size,
915+
self._volume.snapshot_id,
916+
self._volume.status,
917+
self._volume.volume_type,
918+
)
919+
self.volumes_mock.get.return_value = self._volume
920+
# Get the command object to test
921+
self.cmd = volume.ShowVolume(self.app, None)
922+
923+
def test_volume_show(self):
924+
arglist = [
925+
self._volume.id
926+
]
927+
verifylist = [
928+
("volume", self._volume.id)
929+
]
930+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
931+
932+
columns, data = self.cmd.take_action(parsed_args)
933+
self.volumes_mock.get.assert_called_with(self._volume.id)
934+
935+
self.assertEqual(self.columns, columns)
936+
self.assertEqual(self.datalist, data)
937+
938+
939+
class TestVolumeUnset(TestVolume):
940+
941+
_volume = volume_fakes.FakeVolume.create_one_volume()
942+
943+
def setUp(self):
944+
super(TestVolumeUnset, self).setUp()
945+
946+
self.volumes_mock.get.return_value = self._volume
947+
948+
self.volumes_mock.delete_metadata.return_value = None
949+
# Get the command object to test
950+
self.cmd = volume.UnsetVolume(self.app, None)
951+
952+
def test_volume_unset_no_options(self):
953+
arglist = [
954+
self._volume.display_name,
955+
]
956+
verifylist = [
957+
('property', None),
958+
('volume', self._volume.display_name),
959+
]
960+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
961+
962+
result = self.cmd.take_action(parsed_args)
963+
self.assertIsNone(result)
964+
965+
def test_volume_unset_property(self):
966+
arglist = [
967+
'--property', 'myprop',
968+
self._volume.display_name,
969+
]
970+
verifylist = [
971+
('property', ['myprop']),
972+
('volume', self._volume.display_name),
973+
]
974+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
975+
976+
result = self.cmd.take_action(parsed_args)
977+
978+
self.volumes_mock.delete_metadata.assert_called_with(
979+
self._volume.id, ['myprop']
980+
)
981+
self.assertIsNone(result)

openstackclient/volume/v1/volume.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,8 @@ def get_parser(self, prog_name):
452452
'--property',
453453
metavar='<key>',
454454
action='append',
455-
default=[],
456455
help=_('Remove a property from volume '
457456
'(repeat option to remove multiple properties)'),
458-
required=True,
459457
)
460458
return parser
461459

0 commit comments

Comments
 (0)