From 79a9210c52bca5fd633ac4cfa429e640a78c7c2c Mon Sep 17 00:00:00 2001 From: Desire Barine Date: Sat, 10 Jun 2023 21:08:43 +0000 Subject: [PATCH] Automate generation of volume transfer api-ref samples This patch adds the following tests: 1) Volume transfer for microversions 3.55 and above Partially-Implements: blueprint generating-sample-files Signed-off-by: Desire Barine Change-Id: Ifdd99433563ab72d8d43a374af0377213834d46e --- .../volume-transfers-create-request.json | 6 ++ .../volume-transfers-create-response.json | 20 ++++++ .../v3.55/volume-transfers-show-response.json | 19 +++++ .../volume-transfers-create-request.json | 7 ++ .../volume-transfers-create-response.json | 23 ++++++ .../v3.57/volume-transfers-show-response.json | 22 ++++++ .../volume-transfers-accept-request.json | 5 ++ .../volume-transfers-accept-response.json | 17 +++++ api-ref/source/v3/vol-transfer-v3.inc | 12 ++-- .../volume-transfers-create-request.json.tpl | 6 ++ .../volume-transfers-create-response.json.tpl | 20 ++++++ .../volume-transfers-show-response.json.tpl | 19 +++++ .../volume-transfers-create-request.json.tpl | 7 ++ .../volume-transfers-create-response.json.tpl | 23 ++++++ .../volume-transfers-show-response.json.tpl | 22 ++++++ .../volume-transfers-accept-request.json.tpl | 5 ++ .../volume-transfers-accept-response.json.tpl | 17 +++++ .../api_sample_tests/test_volume_transfers.py | 70 +++++++++++++++++++ 18 files changed, 315 insertions(+), 5 deletions(-) create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-request.json create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-response.json create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-show-response.json create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-request.json create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-response.json create mode 100644 api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-show-response.json create mode 100644 api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-request.json create mode 100644 api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-response.json create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-request.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-response.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-show-response.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-request.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-response.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-show-response.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-request.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-response.json.tpl create mode 100644 cinder/tests/functional/api_sample_tests/test_volume_transfers.py diff --git a/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-request.json b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-request.json new file mode 100644 index 00000000000..cf3d5067e10 --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-request.json @@ -0,0 +1,6 @@ +{ + "transfer": { + "volume_id": "1bb4acc9-9fa4-4b4d-8992-3259b69c8372", + "name": "first volume" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-response.json b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-response.json new file mode 100644 index 00000000000..f1e7d17adc6 --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-create-response.json @@ -0,0 +1,20 @@ +{ + "transfer": { + "auth_key": "19244092a5352ebb", + "created_at": "2023-06-12T21:21:38.394873", + "id": "33907fea-976f-4d67-8867-b5382f84eb8c", + "links": [ + { + "href": "http://127.0.0.1:45183/v3/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/33907fea-976f-4d67-8867-b5382f84eb8c", + "rel": "self" + }, + { + "href": "http://127.0.0.1:45183/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/33907fea-976f-4d67-8867-b5382f84eb8c", + "rel": "bookmark" + } + ], + "name": "first volume", + "no_snapshots": false, + "volume_id": "31024287-e368-4b2c-85a4-880b3b6fc8b0" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-show-response.json b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-show-response.json new file mode 100644 index 00000000000..cff68b0587e --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.55/volume-transfers-show-response.json @@ -0,0 +1,19 @@ +{ + "transfer": { + "created_at": "2023-06-22T08:28:14.618343", + "id": "16b47e50-ab70-4781-bc01-cdcc01ca264a", + "links": [ + { + "href": "http://127.0.0.1:38399/v3/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/16b47e50-ab70-4781-bc01-cdcc01ca264a", + "rel": "self" + }, + { + "href": "http://127.0.0.1:38399/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/16b47e50-ab70-4781-bc01-cdcc01ca264a", + "rel": "bookmark" + } + ], + "name": "first volume", + "no_snapshots": false, + "volume_id": "a67e4027-4a83-4b80-a2d5-5b49650ac28c" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-request.json b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-request.json new file mode 100644 index 00000000000..1b2824f6b0a --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-request.json @@ -0,0 +1,7 @@ +{ + "transfer": { + "volume_id": "80d68197-b67e-4c8e-bbb9-030b2581f921", + "name": "first volume", + "no_snapshots": false + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-response.json b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-response.json new file mode 100644 index 00000000000..fad2797e4ef --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-create-response.json @@ -0,0 +1,23 @@ +{ + "transfer": { + "accepted": false, + "auth_key": "e2cb02466324813c", + "created_at": "2023-06-12T21:21:38.392033", + "destination_project_id": null, + "id": "94bae1a0-83fb-496c-9cd2-800d8237ab0d", + "links": [ + { + "href": "http://127.0.0.1:45193/v3/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/94bae1a0-83fb-496c-9cd2-800d8237ab0d", + "rel": "self" + }, + { + "href": "http://127.0.0.1:45193/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/94bae1a0-83fb-496c-9cd2-800d8237ab0d", + "rel": "bookmark" + } + ], + "name": "first volume", + "no_snapshots": false, + "source_project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3", + "volume_id": "202eead8-3c82-41e1-914f-83638a063be9" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-show-response.json b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-show-response.json new file mode 100644 index 00000000000..7797c069562 --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/v3.57/volume-transfers-show-response.json @@ -0,0 +1,22 @@ +{ + "transfer": { + "accepted": false, + "created_at": "2023-06-22T08:28:17.647081", + "destination_project_id": null, + "id": "3d79fbda-8d9c-4da3-a016-e5612fcb7f65", + "links": [ + { + "href": "http://127.0.0.1:34593/v3/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/3d79fbda-8d9c-4da3-a016-e5612fcb7f65", + "rel": "self" + }, + { + "href": "http://127.0.0.1:34593/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/3d79fbda-8d9c-4da3-a016-e5612fcb7f65", + "rel": "bookmark" + } + ], + "name": "first volume", + "no_snapshots": false, + "source_project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3", + "volume_id": "7e31e409-2a7a-4ea6-aa0b-bc7be056fc57" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-request.json b/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-request.json new file mode 100644 index 00000000000..7af7ec1e783 --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-request.json @@ -0,0 +1,5 @@ +{ + "accept": { + "auth_key": "f318375a4400391e" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-response.json b/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-response.json new file mode 100644 index 00000000000..8d9c3df22cb --- /dev/null +++ b/api-ref/source/v3/samples/volume_transfers/volume-transfers-accept-response.json @@ -0,0 +1,17 @@ +{ + "transfer": { + "id": "9e395d6d-5138-423c-a63c-7b62c6265fa1", + "links": [ + { + "href": "http://127.0.0.1:39369/v3/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/9e395d6d-5138-423c-a63c-7b62c6265fa1", + "rel": "self" + }, + { + "href": "http://127.0.0.1:39369/89afd400-b646-4bbc-b12b-c0a4d63e5bd3/os-volume-transfer/9e395d6d-5138-423c-a63c-7b62c6265fa1", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "8d19f929-f1da-4a76-acad-9ed17da0981e" + } +} \ No newline at end of file diff --git a/api-ref/source/v3/vol-transfer-v3.inc b/api-ref/source/v3/vol-transfer-v3.inc index 4328bd6035d..89c353c6fa5 100644 --- a/api-ref/source/v3/vol-transfer-v3.inc +++ b/api-ref/source/v3/vol-transfer-v3.inc @@ -38,7 +38,7 @@ Request Request Example --------------- -.. literalinclude:: ./samples/volume_transfer/volume-transfer-accept-request.json +.. literalinclude:: ./samples/volume_transfers/volume-transfers-accept-request.json :language: javascript Response Parameters @@ -55,7 +55,7 @@ Response Parameters Response Example ---------------- -.. literalinclude:: ./samples/volume_transfer/volume-transfer-accept-response.json +.. literalinclude:: ./samples/volume_transfers/volume-transfers-accept-response.json :language: javascript @@ -99,7 +99,7 @@ Request Request Example --------------- -.. literalinclude:: ./samples/volume_transfer/volume-transfer-create-request.json +.. literalinclude:: ./samples/volume_transfers/v3.57/volume-transfers-create-request.json :language: javascript @@ -117,11 +117,12 @@ Response Parameters - destination_project_id: destination_project_id - source_project_id: source_project_id - accepted: accepted + - no_snapshots: no_snapshots Response Example ---------------- -.. literalinclude:: ./samples/volume_transfer/volume-transfer-create-response.json +.. literalinclude:: ./samples/volume_transfers/v3.57/volume-transfers-create-response.json :language: javascript @@ -209,12 +210,13 @@ Response Parameters - destination_project_id: destination_project_id - source_project_id: source_project_id - accepted: accepted + - no_snapshots: no_snapshots Response Example ---------------- -.. literalinclude:: ./samples/volume_transfer/volume-transfer-show-response.json +.. literalinclude:: ./samples/volume_transfers/v3.57/volume-transfers-show-response.json :language: javascript diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-request.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-request.json.tpl new file mode 100644 index 00000000000..4afca5acd39 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-request.json.tpl @@ -0,0 +1,6 @@ +{ + "transfer": { + "volume_id": "%(volume_id)s", + "name": "first volume" + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-response.json.tpl new file mode 100644 index 00000000000..fb372ddcb50 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-create-response.json.tpl @@ -0,0 +1,20 @@ +{ + "transfer": { + "auth_key": "%(auth_key)s", + "created_at": "%(strtime)s", + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/v3/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "%(uuid)s", + "no_snapshots": false + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-show-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-show-response.json.tpl new file mode 100644 index 00000000000..2b58106326e --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.55/volume-transfers-show-response.json.tpl @@ -0,0 +1,19 @@ +{ + "transfer": { + "created_at": "%(strtime)s", + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/v3/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "%(uuid)s", + "no_snapshots": false + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-request.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-request.json.tpl new file mode 100644 index 00000000000..870fecb3462 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-request.json.tpl @@ -0,0 +1,7 @@ +{ + "transfer": { + "volume_id": "%(volume_id)s", + "name": "first volume", + "no_snapshots": false + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-response.json.tpl new file mode 100644 index 00000000000..bb6132af2df --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-create-response.json.tpl @@ -0,0 +1,23 @@ +{ + "transfer": { + "auth_key": "%(auth_key)s", + "created_at": "%(strtime)s", + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/v3/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "%(uuid)s", + "no_snapshots": false, + "destination_project_id": null, + "source_project_id": "%(uuid)s", + "accepted": false + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-show-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-show-response.json.tpl new file mode 100644 index 00000000000..eca94d4f2f2 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/v3.57/volume-transfers-show-response.json.tpl @@ -0,0 +1,22 @@ +{ + "transfer": { + "created_at": "%(strtime)s", + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/v3/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "%(uuid)s", + "destination_project_id": null, + "source_project_id": "%(uuid)s", + "accepted": false, + "no_snapshots": false + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-request.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-request.json.tpl new file mode 100644 index 00000000000..75a5a9bc1ed --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-request.json.tpl @@ -0,0 +1,5 @@ +{ + "accept": { + "auth_key": "%(auth_key)s" + } +} diff --git a/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-response.json.tpl b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-response.json.tpl new file mode 100644 index 00000000000..0c68ba66201 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/samples/volume_transfers/volume-transfers-accept-response.json.tpl @@ -0,0 +1,17 @@ +{ + "transfer": { + "id": "%(uuid)s", + "links": [ + { + "href": "%(host)s/v3/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/%(uuid)s/os-volume-transfer/%(uuid)s", + "rel": "bookmark" + } + ], + "name": "first volume", + "volume_id": "%(uuid)s" + } +} diff --git a/cinder/tests/functional/api_sample_tests/test_volume_transfers.py b/cinder/tests/functional/api_sample_tests/test_volume_transfers.py new file mode 100644 index 00000000000..de35d4c0c19 --- /dev/null +++ b/cinder/tests/functional/api_sample_tests/test_volume_transfers.py @@ -0,0 +1,70 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_serialization import jsonutils + +from cinder.api import microversions as mv +from cinder.tests.functional.api_sample_tests import test_volumes +from cinder.tests.functional import api_samples_test_base as test_base + + +@test_base.VolumesSampleBase.use_versions( + mv.TRANSFER_WITH_SNAPSHOTS, + mv.TRANSFER_WITH_HISTORY) +class VolumeTransfersSampleJsonTest(test_volumes.test_base.VolumesSampleBase): + sample_dir = "volume_transfers" + + def setUp(self): + super(VolumeTransfersSampleJsonTest, self).setUp() + res = self._create_volume() + res = jsonutils.loads(res.content)['volume'] + self._poll_volume_while(res['id'], ['creating']) + self.subs = { + "volume_id": res['id'] + } + + def _create_transfers(self, subs=None): + response = self._do_post('volume-transfers', + 'volume-transfers-create-request', + self.subs) + return response + + def test_create_transfers(self): + response = self._create_transfers(self.subs) + self._verify_response('volume-transfers-create-response', + {}, response, 202) + + def test_accept_transfer(self): + response = self._create_transfers(self.subs) + res = jsonutils.loads(response.content)['transfer'] + subs = { + 'auth_key': res['auth_key'] + } + with self.common_api_sample(): + response = self._do_post('volume-transfers/%s/accept' % res['id'], + 'volume-transfers-accept-request', + subs) + self._verify_response('volume-transfers-accept-response', + {}, response, 202) + + def test_show_transfer(self): + response = self._create_transfers(self.subs) + res = jsonutils.loads(response.content)['transfer'] + show_response = self._do_get('volume-transfers/%s' % res['id']) + self._verify_response('volume-transfers-show-response', {}, + show_response, 200) + + def test_delete_transfer(self): + response = self._create_transfers(self.subs) + res = jsonutils.loads(response.content)['transfer'] + delete_res = self._do_delete('volume-transfers/%s' % res['id']) + self.assertEqual(202, delete_res.status_code)