Add API Sample tests for Snapshots extension.
Partially implements blueprint nova-api-samples Modifies fakes to produce a real timestamp Fixes bug 1126211 Change-Id: I8973d50fa67abbf6f96684ff8a0b898912f09caf
This commit is contained in:
8
doc/api_samples/os-volumes/snapshot-create-req.json
Normal file
8
doc/api_samples/os-volumes/snapshot-create-req.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"display_name": "snap-001",
|
||||
"display_description": "Daily backup",
|
||||
"volume_id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
|
||||
"force": false
|
||||
}
|
||||
}
|
7
doc/api_samples/os-volumes/snapshot-create-req.xml
Normal file
7
doc/api_samples/os-volumes/snapshot-create-req.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<snapshot>
|
||||
<display_name>snap-001</display_name>
|
||||
<display_description>Daily backup</display_description>
|
||||
<volume_id>521752a6-acf6-4b2d-bc7a-119f9148cd8c</volume_id>
|
||||
<force>false</force>
|
||||
</snapshot>
|
32
doc/api_samples/os-volumes/snapshot-create-resp.json
Normal file
32
doc/api_samples/os-volumes/snapshot-create-resp.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"createdAt": "2013-02-25T16:27:54.680544",
|
||||
"displayDescription": "Daily backup",
|
||||
"displayName": "snap-001",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": {
|
||||
"attach_status": "attached",
|
||||
"availability_zone": "fakeaz",
|
||||
"created_at": "1999-01-01T01:01:01.000000",
|
||||
"display_description": "displaydesc",
|
||||
"display_name": "displayname",
|
||||
"host": "fakehost",
|
||||
"id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c",
|
||||
"instance_uuid": "fakeuuid",
|
||||
"mountpoint": "/",
|
||||
"name": "vol name",
|
||||
"project_id": "fakeproject",
|
||||
"size": 1,
|
||||
"snapshot_id": null,
|
||||
"status": "fakestatus",
|
||||
"user_id": "fakeuser",
|
||||
"volume_metadata": [],
|
||||
"volume_type": {
|
||||
"name": "vol_type_name"
|
||||
},
|
||||
"volume_type_id": "fakevoltype"
|
||||
}
|
||||
}
|
||||
}
|
2
doc/api_samples/os-volumes/snapshot-create-resp.xml
Normal file
2
doc/api_samples/os-volumes/snapshot-create-resp.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshot status="available" displayDescription="Daily backup" displayName="snap-001" volumeId="{'instance_uuid': 'fakeuuid', 'status': 'fakestatus', 'user_id': 'fakeuser', 'name': 'vol name', 'display_name': 'displayname', 'availability_zone': 'fakeaz', 'created_at': datetime.datetime(1999, 1, 1, 1, 1, 1), 'attach_status': 'attached', 'display_description': 'displaydesc', 'host': 'fakehost', 'volume_type_id': 'fakevoltype', 'volume_metadata': [], 'volume_type': {'name': 'vol_type_name'}, 'snapshot_id': None, 'mountpoint': '/', 'project_id': 'fakeproject', 'id': u'521752a6-acf6-4b2d-bc7a-119f9148cd8c', 'size': 1}" id="100" createdAt="2013-02-25 16:27:36.840121" size="100"/>
|
31
doc/api_samples/os-volumes/snapshots-detail-resp.json
Normal file
31
doc/api_samples/os-volumes/snapshots-detail-resp.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"snapshots": [
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.671372",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.671378",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 101,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.671381",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 102,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
]
|
||||
}
|
6
doc/api_samples/os-volumes/snapshots-detail-resp.xml
Normal file
6
doc/api_samples/os-volumes/snapshots-detail-resp.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshots>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="100" createdAt="2013-02-25 16:27:36.862459" size="100"/>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="101" createdAt="2013-02-25 16:27:36.862466" size="100"/>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="102" createdAt="2013-02-25 16:27:36.862469" size="100"/>
|
||||
</snapshots>
|
31
doc/api_samples/os-volumes/snapshots-list-resp.json
Normal file
31
doc/api_samples/os-volumes/snapshots-list-resp.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"snapshots": [
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.684999",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.685005",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 101,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "2013-02-25T16:27:54.685008",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 102,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
]
|
||||
}
|
6
doc/api_samples/os-volumes/snapshots-list-resp.xml
Normal file
6
doc/api_samples/os-volumes/snapshots-list-resp.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshots>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="100" createdAt="2013-02-25 16:27:36.769149" size="100"/>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="101" createdAt="2013-02-25 16:27:36.769154" size="100"/>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="102" createdAt="2013-02-25 16:27:36.769157" size="100"/>
|
||||
</snapshots>
|
11
doc/api_samples/os-volumes/snapshots-show-resp.json
Normal file
11
doc/api_samples/os-volumes/snapshots-show-resp.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"createdAt": "2013-02-25T16:27:54.724209",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": "100",
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
}
|
2
doc/api_samples/os-volumes/snapshots-show-resp.xml
Normal file
2
doc/api_samples/os-volumes/snapshots-show-resp.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshot status="available" displayDescription="Default description" displayName="Default name" volumeId="12" id="100" createdAt="2013-02-25 16:27:36.854206" size="100"/>
|
@@ -587,7 +587,7 @@ def stub_snapshot(id, **kwargs):
|
||||
'volume_id': 12,
|
||||
'status': 'available',
|
||||
'volume_size': 100,
|
||||
'created_at': None,
|
||||
'created_at': timeutils.utcnow(),
|
||||
'display_name': 'Default name',
|
||||
'display_description': 'Default description',
|
||||
'project_id': 'fake'
|
||||
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"display_name": "%(snapshot_name)s",
|
||||
"display_description": "%(description)s",
|
||||
"volume_id": "%(volume_id)s",
|
||||
"force": false
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<snapshot>
|
||||
<display_name>%(snapshot_name)s</display_name>
|
||||
<display_description>%(description)s</display_description>
|
||||
<volume_id>%(volume_id)s</volume_id>
|
||||
<force>false</force>
|
||||
</snapshot>
|
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "%(description)s",
|
||||
"displayName": "%(snapshot_name)s",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": {
|
||||
"attach_status": "attached",
|
||||
"availability_zone": "fakeaz",
|
||||
"created_at": "%(timestamp)s",
|
||||
"display_description": "displaydesc",
|
||||
"display_name": "displayname",
|
||||
"host": "fakehost",
|
||||
"id": "%(uuid)s",
|
||||
"instance_uuid": "fakeuuid",
|
||||
"mountpoint": "/",
|
||||
"name": "vol name",
|
||||
"project_id": "fakeproject",
|
||||
"size": 1,
|
||||
"snapshot_id": null,
|
||||
"status": "fakestatus",
|
||||
"user_id": "fakeuser",
|
||||
"volume_metadata": [],
|
||||
"volume_type": {
|
||||
"name": "vol_type_name"
|
||||
},
|
||||
"volume_type_id": "fakevoltype"
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshot status="available" displayDescription="%(description)s" displayName="%(snapshot_name)s" volumeId="{'instance_uuid': 'fakeuuid', 'status': 'fakestatus', 'user_id': 'fakeuser', 'name': 'vol name', 'display_name': 'displayname', 'availability_zone': 'fakeaz', 'created_at': datetime.datetime(1999, 1, 1, 1, 1, 1), 'attach_status': 'attached', 'display_description': 'displaydesc', 'host': 'fakehost', 'volume_type_id': 'fakevoltype', 'volume_metadata': [], 'volume_type': {'name': 'vol_type_name'}, 'snapshot_id': None, 'mountpoint': '/', 'project_id': 'fakeproject', 'id': u'521752a6-acf6-4b2d-bc7a-119f9148cd8c', 'size': 1}" id="100" createdAt="%(timestamp)s" size="100"/>
|
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"snapshots": [
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 101,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "Default description",
|
||||
"displayName": "Default name",
|
||||
"id": 102,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshots>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="100" createdAt="%(timestamp)s" size="100"/>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="101" createdAt="%(timestamp)s" size="100"/>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="102" createdAt="%(timestamp)s" size="100"/>
|
||||
</snapshots>
|
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"snapshots": [
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "%(text)s",
|
||||
"displayName": "%(text)s",
|
||||
"id": 100,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "%(text)s",
|
||||
"displayName": "%(text)s",
|
||||
"id": 101,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
},
|
||||
{
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "%(text)s",
|
||||
"displayName": "%(text)s",
|
||||
"id": 102,
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshots>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="100" createdAt="%(timestamp)s" size="100"/>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="101" createdAt="%(timestamp)s" size="100"/>
|
||||
<snapshot status="available" displayDescription="%(text)s" displayName="%(text)s" volumeId="12" id="102" createdAt="%(timestamp)s" size="100"/>
|
||||
</snapshots>
|
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"snapshot": {
|
||||
"createdAt": "%(timestamp)s",
|
||||
"displayDescription": "%(description)s",
|
||||
"displayName": "%(snapshot_name)s",
|
||||
"id": "100",
|
||||
"size": 100,
|
||||
"status": "available",
|
||||
"volumeId": 12
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<snapshot status="available" displayDescription="%(description)s" displayName="%(snapshot_name)s" volumeId="12" id="100" createdAt="%(timestamp)s" size="100"/>
|
@@ -57,6 +57,7 @@ from nova.tests.image import fake
|
||||
from nova.tests.integrated import integrated_helpers
|
||||
from nova.tests import utils as test_utils
|
||||
from nova import utils
|
||||
from nova.volume import cinder
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('allow_resize_to_same_host', 'nova.compute.api')
|
||||
@@ -384,7 +385,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
|
||||
# removed) soon.
|
||||
do_not_approve_additions = []
|
||||
do_not_approve_additions.append('os-create-server-ext')
|
||||
do_not_approve_additions.append('os-volumes')
|
||||
|
||||
tests = self._get_extensions_tested()
|
||||
extensions = self._get_extensions()
|
||||
@@ -3589,3 +3589,73 @@ class AttachInterfacesSampleJsonTest(ServersSampleBase):
|
||||
|
||||
class AttachInterfacesSampleXmlTest(AttachInterfacesSampleJsonTest):
|
||||
ctype = 'xml'
|
||||
|
||||
|
||||
class SnapshotsSampleJsonTests(ApiSampleTestBase):
|
||||
extension_name = "nova.api.openstack.compute.contrib.volumes.Volumes"
|
||||
|
||||
create_subs = {
|
||||
'snapshot_name': 'snap-001',
|
||||
'description': 'Daily backup',
|
||||
'volume_id': '521752a6-acf6-4b2d-bc7a-119f9148cd8c'
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(SnapshotsSampleJsonTests, self).setUp()
|
||||
self.stubs.Set(cinder.API, "get_all_snapshots",
|
||||
fakes.stub_snapshot_get_all)
|
||||
self.stubs.Set(cinder.API, "get_snapshot", fakes.stub_snapshot_get)
|
||||
|
||||
def _create_snapshot(self):
|
||||
self.stubs.Set(cinder.API, "create_snapshot",
|
||||
fakes.stub_snapshot_create)
|
||||
self.stubs.Set(cinder.API, "get", fakes.stub_volume_get)
|
||||
|
||||
response = self._do_post("os-snapshots",
|
||||
"snapshot-create-req",
|
||||
self.create_subs)
|
||||
return response
|
||||
|
||||
def test_snapshots_create(self):
|
||||
response = self._create_snapshot()
|
||||
self.assertEqual(response.status, 200)
|
||||
self.create_subs.update(self._get_regexes())
|
||||
return self._verify_response("snapshot-create-resp",
|
||||
self.create_subs, response)
|
||||
|
||||
def test_snapshots_delete(self):
|
||||
self.stubs.Set(cinder.API, "delete_snapshot",
|
||||
fakes.stub_snapshot_delete)
|
||||
self._create_snapshot()
|
||||
response = self._do_delete('os-snapshots/100')
|
||||
self.assertEqual(response.status, 202)
|
||||
self.assertEqual(response.read(), '')
|
||||
|
||||
def test_snapshots_detail(self):
|
||||
response = self._do_get('os-snapshots/detail')
|
||||
self.assertEqual(response.status, 200)
|
||||
subs = self._get_regexes()
|
||||
return self._verify_response('snapshots-detail-resp',
|
||||
subs, response)
|
||||
|
||||
def test_snapshots_list(self):
|
||||
response = self._do_get('os-snapshots')
|
||||
self.assertEqual(response.status, 200)
|
||||
subs = self._get_regexes()
|
||||
return self._verify_response('snapshots-list-resp',
|
||||
subs, response)
|
||||
|
||||
def test_snapshots_show(self):
|
||||
response = self._do_get('os-snapshots/100')
|
||||
self.assertEqual(response.status, 200)
|
||||
subs = {
|
||||
'snapshot_name': 'Default name',
|
||||
'description': 'Default description'
|
||||
}
|
||||
subs.update(self._get_regexes())
|
||||
return self._verify_response('snapshots-show-resp',
|
||||
subs, response)
|
||||
|
||||
|
||||
class SnapshotsSampleXmlTests(SnapshotsSampleJsonTests):
|
||||
ctype = "xml"
|
||||
|
Reference in New Issue
Block a user