Switch command server remove volume to sdk
Change-Id: If6f6cf93b55a67e767c54de8ce21f25252cf99ca
This commit is contained in:
parent
28cd5763de
commit
fae293dd52
@ -3793,22 +3793,29 @@ class RemoveServerVolume(command.Command):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.sdk_connection.compute
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.sdk_connection.volume
|
||||||
|
|
||||||
server = utils.find_resource(
|
server = compute_client.find_server(
|
||||||
compute_client.servers,
|
|
||||||
parsed_args.server,
|
parsed_args.server,
|
||||||
|
ignore_missing=False,
|
||||||
)
|
)
|
||||||
volume = utils.find_resource(
|
volume = volume_client.find_volume(
|
||||||
volume_client.volumes,
|
|
||||||
parsed_args.volume,
|
parsed_args.volume,
|
||||||
|
ignore_missing=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
compute_client.volumes.delete_server_volume(
|
volume_attachments = compute_client.volume_attachments(server)
|
||||||
server.id,
|
for volume_attachment in volume_attachments:
|
||||||
volume.id,
|
if volume_attachment.volume_id == volume.id:
|
||||||
)
|
compute_client.delete_volume_attachment(
|
||||||
|
volume_attachment,
|
||||||
|
server,
|
||||||
|
)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
msg = _('Target volume attachment not found.')
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
class RescueServer(command.Command):
|
class RescueServer(command.Command):
|
||||||
|
@ -692,9 +692,6 @@ class TestServerVolume(TestServer):
|
|||||||
'create_volume_attachment': None,
|
'create_volume_attachment': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the command object to test
|
|
||||||
self.cmd = server.AddServerVolume(self.app, None)
|
|
||||||
|
|
||||||
self.servers = self.setup_sdk_servers_mock(count=1)
|
self.servers = self.setup_sdk_servers_mock(count=1)
|
||||||
self.volumes = self.setup_sdk_volumes_mock(count=1)
|
self.volumes = self.setup_sdk_volumes_mock(count=1)
|
||||||
|
|
||||||
@ -709,6 +706,15 @@ class TestServerVolume(TestServer):
|
|||||||
self.sdk_client.create_volume_attachment.return_value = \
|
self.sdk_client.create_volume_attachment.return_value = \
|
||||||
self.volume_attachment
|
self.volume_attachment
|
||||||
|
|
||||||
|
|
||||||
|
class TestServerAddVolume(TestServerVolume):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestServerAddVolume, self).setUp()
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = server.AddServerVolume(self.app, None)
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||||
def test_server_add_volume(self, sm_mock):
|
def test_server_add_volume(self, sm_mock):
|
||||||
|
|
||||||
@ -985,6 +991,39 @@ class TestServerVolume(TestServer):
|
|||||||
'with argument --enable-delete-on-termination', str(ex))
|
'with argument --enable-delete-on-termination', str(ex))
|
||||||
|
|
||||||
|
|
||||||
|
class TestServerRemoveVolume(TestServerVolume):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestServerRemoveVolume, self).setUp()
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = server.RemoveServerVolume(self.app, None)
|
||||||
|
|
||||||
|
def test_server_remove_volume(self):
|
||||||
|
self.sdk_client.volume_attachments.return_value = [
|
||||||
|
self.volume_attachment
|
||||||
|
]
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
self.servers[0].id,
|
||||||
|
self.volumes[0].id,
|
||||||
|
]
|
||||||
|
|
||||||
|
verifylist = [
|
||||||
|
('server', self.servers[0].id),
|
||||||
|
('volume', self.volumes[0].id),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertIsNone(result)
|
||||||
|
self.sdk_client.delete_volume_attachment.assert_called_once_with(
|
||||||
|
self.volume_attachment,
|
||||||
|
self.servers[0])
|
||||||
|
|
||||||
|
|
||||||
class TestServerAddNetwork(TestServer):
|
class TestServerAddNetwork(TestServer):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Switch command server remove volume to using sdk.
|
Loading…
x
Reference in New Issue
Block a user