Skip to content

Commit 32e1825

Browse files
Fix RemoveServerVolume
The nova API we're using to delete a server volume attachment needs to be handed a volume, not a volume attachment. Also make sure that we create an error if the volume isn't actually attached to the server. Signed-off-by: Dr. Jens Harbott <harbott@osism.tech> Co-authored-by: Stephen Finucane <sfinucan@redhat.com> Change-Id: I12abd3787ea47acb4da282d00fdc1989405a0564
1 parent 9eb4240 commit 32e1825

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,17 +3833,11 @@ def take_action(self, parsed_args):
38333833
ignore_missing=False,
38343834
)
38353835

3836-
volume_attachments = compute_client.volume_attachments(server)
3837-
for volume_attachment in volume_attachments:
3838-
if volume_attachment.volume_id == volume.id:
3839-
compute_client.delete_volume_attachment(
3840-
volume_attachment,
3841-
server,
3842-
)
3843-
break
3844-
else:
3845-
msg = _('Target volume attachment not found.')
3846-
raise exceptions.CommandError(msg)
3836+
compute_client.delete_volume_attachment(
3837+
volume,
3838+
server,
3839+
ignore_missing=False,
3840+
)
38473841

38483842

38493843
class RescueServer(command.Command):

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,6 @@ def setUp(self):
10161016
self.cmd = server.RemoveServerVolume(self.app, None)
10171017

10181018
def test_server_remove_volume(self):
1019-
self.sdk_client.volume_attachments.return_value = [
1020-
self.volume_attachment
1021-
]
1022-
10231019
arglist = [
10241020
self.servers[0].id,
10251021
self.volumes[0].id,
@@ -1036,8 +1032,10 @@ def test_server_remove_volume(self):
10361032

10371033
self.assertIsNone(result)
10381034
self.sdk_client.delete_volume_attachment.assert_called_once_with(
1039-
self.volume_attachment,
1040-
self.servers[0])
1035+
self.volumes[0],
1036+
self.servers[0],
1037+
ignore_missing=False,
1038+
)
10411039

10421040

10431041
class TestServerAddNetwork(TestServer):

0 commit comments

Comments
 (0)