summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2015-12-28 14:14:37 +0900
committerTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2016-02-05 14:23:03 +0900
commitc9c3b55333b4f3f88eac7e250f4fcd7d71374ca2 (patch)
tree086edc96f6f20c5a4dc12f68e1e79599314c3700
parentd67e16d5b7ac371b23507788ac3308acf418ca13 (diff)
downloadtempest-lib-c9c3b55333b4f3f88eac7e250f4fcd7d71374ca2.tar.gz
Add update attached volume function to servers_client
os-volume_attachments API for update: PUT /v2.1/{tenant_id}/servers/{server_id}/os-volume_attachments/{attachment_id} tenant_id: The project ID (tenant ID) that the target server belongs to server_id: The server ID to update the volume attachment attachment_id: The volume attachment ID to update Request body sample: { "volumeAttachment": { "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f805" } } volumeId: The volume ID to attach instead of the volume that has already been attached This API does not return a response body. Reference: - Request body sample https://github.com/openstack/nova/blob/master/doc/api_samples/os-volumes/update-volume-req.json - Fuctional test test_volume_attachment_update method in VolumeAttachmentsSample class https://github.com/openstack/nova/blob/master/nova/tests/functional/api_sample_tests/test_volumes.py Change-Id: Ic0258e5688be6ede3316ab4310e9ca6ac0f51659 Implements: blueprint add-nova-swap-volume-tests
-rw-r--r--tempest_lib/api_schema/response/compute/v2_1/servers.py4
-rw-r--r--tempest_lib/services/compute/servers_client.py9
-rw-r--r--tempest_lib/tests/services/compute/test_servers_client.py11
3 files changed, 24 insertions, 0 deletions
diff --git a/tempest_lib/api_schema/response/compute/v2_1/servers.py b/tempest_lib/api_schema/response/compute/v2_1/servers.py
index 4c63a34..7db05fb 100644
--- a/tempest_lib/api_schema/response/compute/v2_1/servers.py
+++ b/tempest_lib/api_schema/response/compute/v2_1/servers.py
@@ -547,3 +547,7 @@ server_actions_delete_password = {
server_actions_confirm_resize = copy.deepcopy(
server_actions_delete_password)
+
+update_attached_volume = {
+ 'status_code': [202]
+}
diff --git a/tempest_lib/services/compute/servers_client.py b/tempest_lib/services/compute/servers_client.py
index 5bbcf24..cdb992b 100644
--- a/tempest_lib/services/compute/servers_client.py
+++ b/tempest_lib/services/compute/servers_client.py
@@ -312,6 +312,15 @@ class ServersClient(rest_client.RestClient):
self.validate_response(schema.attach_volume, resp, body)
return rest_client.ResponseBody(resp, body)
+ def update_attached_volume(self, server_id, attachment_id, **kwargs):
+ """Swaps a volume attached to an instance for another volume"""
+ post_body = json.dumps({'volumeAttachment': kwargs})
+ resp, body = self.put('servers/%s/os-volume_attachments/%s' %
+ (server_id, attachment_id),
+ post_body)
+ self.validate_response(schema.update_attached_volume, resp, body)
+ return rest_client.ResponseBody(resp, body)
+
def detach_volume(self, server_id, volume_id): # noqa
"""Detaches a volume from a server instance."""
resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
diff --git a/tempest_lib/tests/services/compute/test_servers_client.py b/tempest_lib/tests/services/compute/test_servers_client.py
index 44cd7ce..d3a4e83 100644
--- a/tempest_lib/tests/services/compute/test_servers_client.py
+++ b/tempest_lib/tests/services/compute/test_servers_client.py
@@ -564,6 +564,17 @@ class TestServersClient(base.BaseComputeServiceTest):
server_id=self.server_id
)
+ def test_update_attached_volume(self):
+ self.check_service_client_function(
+ self.client.update_attached_volume,
+ 'tempest_lib.common.rest_client.RestClient.put',
+ {},
+ status=202,
+ server_id=self.server_id,
+ attachment_id='fake-attachment-id',
+ volumeId='fake-volume-id'
+ )
+
def test_detach_volume_with_str_body(self):
self._test_detach_volume_server()