Automate generation of snapshots api-ref samples

This patch adds the tests for generating api-ref responses of
volume snapshots.

Change-Id: I1b8f265e2efd1760b34baf32d9d92cb4b2777cdd
Partially-Implements: blueprint generating-sample-files
This commit is contained in:
whoami-rajat 2019-03-12 12:07:01 +05:30
parent 15d1a00a57
commit 51a55ab03d
41 changed files with 379 additions and 139 deletions

View File

@ -1,15 +0,0 @@
{
"snapshot": {
"status": "creating",
"description": "Daily backup",
"created_at": "2013-02-25T03:56:53.081642",
"metadata": {},
"updated_at": "2013-02-25T03:58:53.081642",
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
"size": 1,
"user_id": "40c2102f4a554b848d96b14f3eec39ed",
"id": "ffa9bc5e-1172-4021-acaf-cdcd78a9584d",
"name": "snap-001"
}
}

View File

@ -1,5 +0,0 @@
{
"meta": {
"name": "test"
}
}

View File

@ -1,5 +0,0 @@
{
"meta": {
"name": "new_name"
}
}

View File

@ -1,5 +0,0 @@
{
"meta": {
"name": "new_name"
}
}

View File

@ -1,16 +0,0 @@
{
"snapshot": {
"status": "available",
"os-extended-snapshot-attributes:progress": "100%",
"description": "Daily backup",
"created_at": "2013-02-25T04:13:17.000000",
"metadata": {},
"user_id": "40c2102f4a554b848d96b14f3eec39ed",
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
"os-extended-snapshot-attributes:project_id": "0c2eba2c5af04d3f9e9d0d410b371fde",
"size": 1,
"id": "2bb856e1-b3d8-4432-a858-09e4ce939389",
"name": "snap-001",
"updated_at": "2013-03-11T07:24:57Z"
}
}

View File

@ -1,13 +0,0 @@
{
"snapshot": {
"created_at": "2013-02-20T08:11:34.000000",
"description": "This is yet, another snapshot",
"name": "snap-002",
"id": "4b502fcb-1f26-45f8-9fe5-3b9a0a52eaf2",
"size": 1,
"status": "available",
"metadata": {},
"user_id": "40c2102f4a554b848d96b14f3eec39ed",
"volume_id": "2402b902-0b7a-458c-9c07-7435a826f794"
}
}

View File

@ -1,27 +0,0 @@
{
"snapshots": [
{
"status": "available",
"metadata": {
"name": "test"
},
"os-extended-snapshot-attributes:progress": "100%",
"name": "test-volume-snapshot",
"user_id": "40c2102f4a554b848d96b14f3eec39ed",
"volume_id": "173f7b48-c4c1-4e70-9acc-086b39073506",
"os-extended-snapshot-attributes:project_id": "bab7d5c60cd041a0a36f7c4b6e1dd978",
"created_at": "2015-11-29T02:25:51.000000",
"size": 1,
"id": "b1323cda-8e4b-41c1-afc5-2fc791809c8c",
"description": "volume snapshot",
"updated_at": "2015-12-11T07:24:57Z"
}
],
"snapshots_links": [
{
"href": "https://10.43.176.164:8776/v3/d55fb90e300b436cb2714a17137be023/snapshots?limit=1&marker=2e0cd28e-d7a2-4cdb-87e6-cd37c417c06d",
"rel": "next"
}
],
"count": 10
}

View File

@ -1,28 +0,0 @@
{
"snapshots": [
{
"status": "available",
"metadata": {
"name": "test"
},
"name": "test-volume-snapshot",
"user_id": "40c2102f4a554b848d96b14f3eec39ed",
"volume_id": "173f7b48-c4c1-4e70-9acc-086b39073506",
"created_at": "2015-11-29T02:25:51.000000",
"size": 1,
"updated_at": "2015-11-20T05:36:40.000000",
"os-extended-snapshot-attributes:progress": "100%",
"os-extended-snapshot-attributes:project_id": "0892d23df5c5471da88299517a412b90",
"id": "b1323cda-8e4b-41c1-afc5-2fc791809c8c",
"description": "volume snapshot",
"updated_at": "2015-12-11T07:24:57Z"
}
],
"snapshots_links": [
{
"href": "https://10.43.176.164:8776/v3/d55fb90e300b436cb2714a17137be023/snapshots?limit=1&marker=2e0cd28e-d7a2-4cdb-87e6-cd37c417c06d",
"rel": "next"
}
],
"count": 10
}

View File

@ -4,6 +4,8 @@
"description": "Daily backup", "description": "Daily backup",
"volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635", "volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
"force": true, "force": true,
"metadata": null "metadata": {
"key": "v3"
}
} }
} }

View File

@ -0,0 +1,15 @@
{
"snapshot": {
"created_at": "2019-03-11T16:24:34.469003",
"description": "Daily backup",
"id": "b36476e5-d18b-47f9-ac69-4818cb43ee21",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "d291b81c-6e40-4525-8231-90aa1588121e"
}
}

View File

@ -1,5 +1,5 @@
{ {
"metadata": { "metadata": {
"name": "test" "key": "value"
} }
} }

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "v3"
}
}

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"metadata": {
"new_key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"metadata": {
"new_key": "new_value"
}
}

View File

@ -0,0 +1,17 @@
{
"snapshot": {
"created_at": "2019-03-12T04:42:00.809352",
"description": "Daily backup",
"id": "4a584cae-e4ce-429b-9154-d4c9eb8fda4c",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"os-extended-snapshot-attributes:progress": "0%",
"os-extended-snapshot-attributes:project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "b72c48f1-64b7-4cd8-9745-b12e0be82d37"
}
}

View File

@ -0,0 +1,6 @@
{
"snapshot": {
"name": "snap-002",
"description": "This is yet, another snapshot."
}
}

View File

@ -0,0 +1,15 @@
{
"snapshot": {
"created_at": "2019-03-12T04:53:53.426591",
"description": "This is yet, another snapshot.",
"id": "43666194-8e72-451a-b7bb-54fef763b2b8",
"metadata": {
"key": "v3"
},
"name": "snap-002",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "070c942d-9909-42e9-a467-7a781f150c58"
}
}

View File

@ -0,0 +1,19 @@
{
"snapshots": [
{
"created_at": "2019-03-11T16:24:36.464445",
"description": "Daily backup",
"id": "d0083dc5-8795-4c1a-bc9c-74f70006c205",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"os-extended-snapshot-attributes:progress": "0%",
"os-extended-snapshot-attributes:project_id": "89afd400-b646-4bbc-b12b-c0a4d63e5bd3",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "7acd675e-4e06-4653-af9f-2ecd546342d6"
}
]
}

View File

@ -0,0 +1,17 @@
{
"snapshots": [
{
"created_at": "2019-03-11T16:29:08.973832",
"description": "Daily backup",
"id": "2c228773-50eb-422d-be7e-b5c6ced0c7a9",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "428ec041-b999-40d8-8a54-9e98b19406cc"
}
]
}

View File

@ -92,7 +92,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshots-list-detailed-response.json .. literalinclude:: ./samples/snapshots/snapshots-list-detailed-response.json
:language: javascript :language: javascript
@ -128,7 +128,7 @@ Request
Request Example Request Example
--------------- ---------------
.. literalinclude:: ./samples/snapshot-create-request.json .. literalinclude:: ./samples/snapshots/snapshot-create-request.json
:language: javascript :language: javascript
Response Parameters Response Parameters
@ -151,7 +151,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-create-response.json .. literalinclude:: ./samples/snapshots/snapshot-create-response.json
:language: javascript :language: javascript
@ -211,7 +211,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshots-list-response.json .. literalinclude:: ./samples/snapshots/snapshots-list-response.json
:language: javascript :language: javascript
@ -249,7 +249,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-metadata-show-response.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-show-response.json
:language: javascript :language: javascript
@ -283,7 +283,7 @@ Request
Request Example Request Example
--------------- ---------------
.. literalinclude:: ./samples/snapshot-metadata-create-request.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-create-request.json
:language: javascript :language: javascript
Response Parameters Response Parameters
@ -296,7 +296,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-metadata-create-response.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-create-response.json
:language: javascript :language: javascript
Update a snapshot's metadata Update a snapshot's metadata
@ -326,7 +326,7 @@ Request
Request Example Request Example
--------------- ---------------
.. literalinclude:: ./samples/snapshot-metadata-update-request.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-update-request.json
:language: javascript :language: javascript
@ -340,7 +340,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-metadata-update-response.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-update-response.json
:language: javascript :language: javascript
@ -390,7 +390,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-show-response.json .. literalinclude:: ./samples/snapshots/snapshot-show-response.json
:language: javascript :language: javascript
@ -423,7 +423,7 @@ Request
Request Example Request Example
--------------- ---------------
.. literalinclude:: ./samples/snapshot-update-request.json .. literalinclude:: ./samples/snapshots/snapshot-update-request.json
:language: javascript :language: javascript
@ -447,7 +447,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-update-response.json .. literalinclude:: ./samples/snapshots/snapshot-update-response.json
:language: javascript :language: javascript
@ -520,7 +520,7 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-metadata-show-key-response.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-show-key-response.json
:language: javascript :language: javascript
@ -578,7 +578,7 @@ Request
Request Example Request Example
--------------- ---------------
.. literalinclude:: ./samples/snapshot-metadata-update-key-request.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-update-key-request.json
:language: javascript :language: javascript
Response Parameters Response Parameters
@ -591,5 +591,5 @@ Response Parameters
Response Example Response Example
---------------- ----------------
.. literalinclude:: ./samples/snapshot-metadata-update-key-response.json .. literalinclude:: ./samples/snapshots/snapshot-metadata-update-key-response.json
:language: javascript :language: javascript

View File

@ -0,0 +1,11 @@
{
"snapshot": {
"name": "snap-001",
"description": "Daily backup",
"volume_id": "%(volume_id)s",
"force": true,
"metadata": {
"key": "v3"
}
}
}

View File

@ -0,0 +1,15 @@
{
"snapshot": {
"created_at": "%(strtime)s",
"description": "Daily backup",
"id": "%(uuid)s",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "%(uuid)s"
}
}

View File

@ -0,0 +1,5 @@
{
"metadata": {
"key": "value"
}
}

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "v3"
}
}

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"meta": {
"key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"metadata": {
"new_key": "new_value"
}
}

View File

@ -0,0 +1,5 @@
{
"metadata": {
"new_key": "new_value"
}
}

View File

@ -0,0 +1,17 @@
{
"snapshot": {
"created_at": "%(strtime)s",
"description": "Daily backup",
"id": "%(uuid)s",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"os-extended-snapshot-attributes:progress": "0%",
"os-extended-snapshot-attributes:project_id": "%(uuid)s",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "%(uuid)s"
}
}

View File

@ -0,0 +1,15 @@
{
"snapshot": {
"created_at": "%(strtime)s",
"description": "This is yet, another snapshot.",
"id": "%(uuid)s",
"metadata": {
"key": "v3"
},
"name": "snap-002",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "%(uuid)s"
}
}

View File

@ -0,0 +1,19 @@
{
"snapshots": [
{
"created_at": "%(strtime)s",
"description": "Daily backup",
"id": "%(uuid)s",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"os-extended-snapshot-attributes:progress": "0%",
"os-extended-snapshot-attributes:project_id": "%(uuid)s",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "%(uuid)s"
}
]
}

View File

@ -0,0 +1,17 @@
{
"snapshots": [
{
"created_at": "%(strtime)s",
"description": "Daily backup",
"id": "%(uuid)s",
"metadata": {
"key": "v3"
},
"name": "snap-001",
"size": 10,
"status": "creating",
"updated_at": null,
"volume_id": "%(uuid)s"
}
]
}

View File

@ -0,0 +1,105 @@
# 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.tests.functional.api_sample_tests import test_volumes
class VolumeSnapshotsSampleJsonTest(test_volumes.VolumesSampleBase):
sample_dir = "snapshots"
def setUp(self):
super(VolumeSnapshotsSampleJsonTest, 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']
}
self.response = self._create_snapshot(self.subs)
def _create_snapshot(self, subs=None):
response = self._do_post('snapshots',
'snapshot-create-request',
subs)
return response
def test_snapshot_list_detail(self):
response = self._do_get('snapshots/detail')
self._verify_response('snapshots-list-detailed-response',
{}, response, 200)
def test_snapshot_create(self):
self._verify_response('snapshot-create-response',
{}, self.response, 202)
def test_snapshot_list(self):
response = self._do_get('snapshots')
self._verify_response('snapshots-list-response',
{}, response, 200)
def test_snapshot_metadata_show(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_get('snapshots/%s/metadata' % res['id'])
self._verify_response('snapshot-metadata-show-response',
{}, response, 200)
def test_snapshot_metadata_create(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_post('snapshots/%s/metadata' % res['id'],
'snapshot-metadata-create-request')
self._verify_response('snapshot-metadata-create-response',
{}, response, 200)
def test_snapshot_metadata_update(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_put('snapshots/%s/metadata' % res['id'],
'snapshot-metadata-update-request')
self._verify_response('snapshot-metadata-update-response',
{}, response, 200)
def test_snapshot_show(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_get('snapshots/%s' % res['id'])
self._verify_response('snapshot-show-response',
{}, response, 200)
def test_snapshot_update(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_put('snapshots/%s' % res['id'],
'snapshot-update-request')
self._verify_response('snapshot-update-response',
{}, response, 200)
def test_snapshot_metadata_show_specific_key(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_get('snapshots/%s/metadata/key' % res['id'])
self._verify_response('snapshot-metadata-show-key-response',
{}, response, 200)
def test_snapshot_metadata_update_specific_key(self):
res = jsonutils.loads(self.response.content)['snapshot']
response = self._do_put('snapshots/%s/metadata/key' % res['id'],
'snapshot-metadata-update-key-request')
self._verify_response('snapshot-metadata-update-key-response',
{}, response, 200)

View File

@ -244,7 +244,7 @@ class ApiSampleTestBase(functional_helpers._FunctionalTestBase):
{'expected': expected, 'result_str': result_str, {'expected': expected, 'result_str': result_str,
'result': result}) 'result': result})
try: try:
matched_value = match.group('id') matched_value = match.group()
except IndexError: except IndexError:
if match.groups(): if match.groups():
matched_value = match.groups()[0] matched_value = match.groups()[0]
@ -270,6 +270,15 @@ class ApiSampleTestBase(functional_helpers._FunctionalTestBase):
expected, result, result_str, matched_value) expected, result, result_str, matched_value)
# template string # template string
elif isinstance(expected, six.string_types) and '%' in expected: elif isinstance(expected, six.string_types) and '%' in expected:
if expected[-1] == '%':
if result != expected:
raise NoMatch(
'Values do not match:\n'
'Template: %(expected)s\n%(result_str)s: '
'%(result)s' % {'expected': expected,
'result_str': result_str,
'result': result})
else:
matched_value = self._compare_template( matched_value = self._compare_template(
expected, result, result_str, matched_value) expected, result, result_str, matched_value)
# string # string