Merge "Add support for volume unmanage"
This commit is contained in:
commit
19c053efb8
@ -427,3 +427,104 @@ class TestVolumeCreate(BaseVolumeTest):
|
|||||||
'--host and --cluster options are only supported ',
|
'--host and --cluster options are only supported ',
|
||||||
str(exc),
|
str(exc),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestVolumeDelete(BaseVolumeTest):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self.volumes_mock = self.volume_client.volumes
|
||||||
|
self.volumes_mock.reset_mock()
|
||||||
|
self.volume_sdk_client.unmanage_volume.return_value = None
|
||||||
|
|
||||||
|
# Get the command object to mock
|
||||||
|
self.cmd = volume.DeleteVolume(self.app, None)
|
||||||
|
|
||||||
|
def test_volume_delete_remote(self):
|
||||||
|
vol = sdk_fakes.generate_fake_resource(_volume.Volume, **{'size': 1})
|
||||||
|
self.volumes_mock.get.return_value = vol
|
||||||
|
|
||||||
|
arglist = ['--remote', vol.id]
|
||||||
|
verifylist = [
|
||||||
|
("remote", True),
|
||||||
|
("force", False),
|
||||||
|
("purge", False),
|
||||||
|
("volumes", [vol.id]),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.volume_sdk_client.unmanage_volume.assert_called_once_with(vol.id)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_volume_delete_multi_volumes_remote(self):
|
||||||
|
volumes = sdk_fakes.generate_fake_resources(
|
||||||
|
_volume.Volume, count=3, attrs={'size': 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
arglist = ['--remote']
|
||||||
|
arglist += [v.id for v in volumes]
|
||||||
|
verifylist = [
|
||||||
|
('remote', True),
|
||||||
|
('force', False),
|
||||||
|
('purge', False),
|
||||||
|
('volumes', arglist[1:]),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
calls = [mock.call(v.id) for v in volumes]
|
||||||
|
self.volume_sdk_client.unmanage_volume.assert_has_calls(calls)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_volume_delete_remote_with_purge(self):
|
||||||
|
vol = sdk_fakes.generate_fake_resource(_volume.Volume, **{'size': 1})
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--remote',
|
||||||
|
'--purge',
|
||||||
|
vol.id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('remote', True),
|
||||||
|
('force', False),
|
||||||
|
('purge', True),
|
||||||
|
('volumes', [vol.id]),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
exc = self.assertRaises(
|
||||||
|
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"The --force and --purge options are not supported with the "
|
||||||
|
"--remote parameter.",
|
||||||
|
str(exc),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_volume_delete_remote_with_force(self):
|
||||||
|
vol = sdk_fakes.generate_fake_resource(_volume.Volume, **{'size': 1})
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--remote',
|
||||||
|
'--force',
|
||||||
|
vol.id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('remote', True),
|
||||||
|
('force', True),
|
||||||
|
('purge', False),
|
||||||
|
('volumes', [vol.id]),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
exc = self.assertRaises(
|
||||||
|
exceptions.CommandError, self.cmd.take_action, parsed_args
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
"The --force and --purge options are not supported with the "
|
||||||
|
"--remote parameter.",
|
||||||
|
str(exc),
|
||||||
|
)
|
||||||
|
@ -244,16 +244,31 @@ class DeleteVolume(volume_v2.DeleteVolume):
|
|||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super().get_parser(prog_name)
|
parser = super().get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--remote',
|
||||||
|
action='store_true',
|
||||||
|
help=_("Specify this parameter to unmanage a volume."),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
volume_client_sdk = self.app.client_manager.sdk_connection.volume
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
|
if parsed_args.remote and (parsed_args.force or parsed_args.purge):
|
||||||
|
msg = _(
|
||||||
|
"The --force and --purge options are not "
|
||||||
|
"supported with the --remote parameter."
|
||||||
|
)
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
for i in parsed_args.volumes:
|
for i in parsed_args.volumes:
|
||||||
try:
|
try:
|
||||||
volume_obj = utils.find_resource(volume_client.volumes, i)
|
volume_obj = utils.find_resource(volume_client.volumes, i)
|
||||||
if parsed_args.force:
|
if parsed_args.remote:
|
||||||
|
volume_client_sdk.unmanage_volume(volume_obj.id)
|
||||||
|
elif parsed_args.force:
|
||||||
volume_client.volumes.force_delete(volume_obj.id)
|
volume_client.volumes.force_delete(volume_obj.id)
|
||||||
else:
|
else:
|
||||||
volume_client.volumes.delete(
|
volume_client.volumes.delete(
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add support for unmanaging volumes with
|
||||||
|
``openstack volume delete --remote <volume>`` command.
|
Loading…
x
Reference in New Issue
Block a user