You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2015/05/05 15:26:15 UTC
[22/50] cloudstack-ec2stack git commit: Finish basic snapshot support
Finish basic snapshot support
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/commit/b30b27e8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/tree/b30b27e8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/diff/b30b27e8
Branch: refs/heads/master
Commit: b30b27e8f68a939f4b3e8e8a49c786f6819f2af1
Parents: b6a48b9
Author: brogand1993 <da...@hotmail.com>
Authored: Sat Aug 9 13:37:30 2014 +0100
Committer: brogand1993 <da...@hotmail.com>
Committed: Sat Aug 9 13:37:30 2014 +0100
----------------------------------------------------------------------
ec2stack/providers/cloudstack/snapshots.py | 19 +++++++++++++------
ec2stack/templates/snapshots.xml | 2 +-
...invalid_create_snapshot_volume_not_found.json | 8 ++++++++
tests/data/invalid_create_tag_invalid_id.json | 17 -----------------
tests/data/invalid_create_tag_not_found.json | 17 +++++++++++++++++
...valid_delete_snapshot_snapshot_not_found.json | 8 ++++++++
.../data/invalid_delete_tag_invalid_tag_id.json | 17 -----------------
tests/data/invalid_delete_tag_tag_not_found.json | 17 +++++++++++++++++
.../invalid_describe_image_image_not_found.json | 8 ++++++++
.../invalid_describe_image_invalid_image_id.json | 8 --------
...valid_describe_volume_instance_not_found.json | 3 +++
...alid_describe_volume_invalid_instance_id.json | 3 ---
tests/tags_tests.py | 4 ++--
13 files changed, 77 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/ec2stack/providers/cloudstack/snapshots.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/snapshots.py b/ec2stack/providers/cloudstack/snapshots.py
index 69e53ea..8f3dc2d 100644
--- a/ec2stack/providers/cloudstack/snapshots.py
+++ b/ec2stack/providers/cloudstack/snapshots.py
@@ -17,6 +17,7 @@ def create_snapshot():
@return: Response.
"""
+ helpers.require_parameters(['VolumeId'])
response = _create_snapshot_request()
return _create_snapshot_response(response)
@@ -27,7 +28,7 @@ def _create_snapshot_request():
@return: Response.
"""
- args = {'command': 'createSnapshot'}
+ args = {'command': 'createSnapshot', 'volumeid': helpers.get('VolumeId')}
response = requester.make_request_async(args)
@@ -41,8 +42,11 @@ def _create_snapshot_response(response):
@param response: Response from Cloudstack.
@return: Response.
"""
-
- response = response['vmsnapshot']
+ if 'errortext' in response:
+ if 'Invalid parameter volumeid' in response['errortext']:
+ errors.invalid_volume_id()
+ else:
+ response = response['snapshot']
return {
'template_name_or_list': 'create_snapshot.xml',
'response_type': 'CreateSnapshotResponse',
@@ -58,8 +62,8 @@ def delete_snapshot():
@return: Response.
"""
helpers.require_parameters(['SnapshotId'])
- _delete_snapshot_request()
- return _delete_snapshot_response()
+ response = _delete_snapshot_request()
+ return _delete_snapshot_response(response)
def _delete_snapshot_request():
@@ -75,12 +79,15 @@ def _delete_snapshot_request():
return response
-def _delete_snapshot_response():
+def _delete_snapshot_response(response):
"""
Generates a response for delete snapshot request.
@return: Response.
"""
+ if 'errortext' in response:
+ if 'Invalid parameter id' in response['errortext']:
+ errors.invalid_snapshot_id()
return {
'template_name_or_list': 'status.xml',
'response_type': 'DeleteSnapshotResponse',
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/ec2stack/templates/snapshots.xml
----------------------------------------------------------------------
diff --git a/ec2stack/templates/snapshots.xml b/ec2stack/templates/snapshots.xml
index 1560683..d4a3cee 100644
--- a/ec2stack/templates/snapshots.xml
+++ b/ec2stack/templates/snapshots.xml
@@ -1,7 +1,7 @@
{% extends "response.xml" %}
{% block response_content %}
<snapshotSet>
- {% for snapshot in response.vmsnapshot %}
+ {% for snapshot in response.snapshot %}
<item>
<snapshotId>{{ snapshot.id }}</snapshotId>
<volumeId>{{ snapshot.volumeid }}</volumeId>
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_create_snapshot_volume_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_create_snapshot_volume_not_found.json b/tests/data/invalid_create_snapshot_volume_not_found.json
new file mode 100644
index 0000000..51440fd
--- /dev/null
+++ b/tests/data/invalid_create_snapshot_volume_not_found.json
@@ -0,0 +1,8 @@
+{
+ "createsnapshotresponse": {
+ "errorcode": 431,
+ "uuidlist": [],
+ "cserrorcode": 9999,
+ "errortext": "Unable to execute API command createsnapshot due to invalid value. Invalid parameter volumeid value=120a5425-6092-4700-baaf-600fcbaa10 due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class."
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_create_tag_invalid_id.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_create_tag_invalid_id.json b/tests/data/invalid_create_tag_invalid_id.json
deleted file mode 100644
index d0defb5..0000000
--- a/tests/data/invalid_create_tag_invalid_id.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "queryasyncjobresultresponse": {
- "jobprocstatus": 0,
- "created": "2014-06-01T13:43:16+0200",
- "cmd": "org.apache.cloudstack.api.command.user.tag.CreateTagsCmd",
- "userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30",
- "jobstatus": 2,
- "jobid": "3cca108f-53df-4a57-8975-3caf29e9d313",
- "jobresultcode": 530,
- "jobresulttype": "object",
- "jobresult": {
- "errorcode": 530,
- "errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm"
- },
- "accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8"
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_create_tag_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_create_tag_not_found.json b/tests/data/invalid_create_tag_not_found.json
new file mode 100644
index 0000000..d0defb5
--- /dev/null
+++ b/tests/data/invalid_create_tag_not_found.json
@@ -0,0 +1,17 @@
+{
+ "queryasyncjobresultresponse": {
+ "jobprocstatus": 0,
+ "created": "2014-06-01T13:43:16+0200",
+ "cmd": "org.apache.cloudstack.api.command.user.tag.CreateTagsCmd",
+ "userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30",
+ "jobstatus": 2,
+ "jobid": "3cca108f-53df-4a57-8975-3caf29e9d313",
+ "jobresultcode": 530,
+ "jobresulttype": "object",
+ "jobresult": {
+ "errorcode": 530,
+ "errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm"
+ },
+ "accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8"
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_delete_snapshot_snapshot_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_delete_snapshot_snapshot_not_found.json b/tests/data/invalid_delete_snapshot_snapshot_not_found.json
new file mode 100644
index 0000000..04ac9cf
--- /dev/null
+++ b/tests/data/invalid_delete_snapshot_snapshot_not_found.json
@@ -0,0 +1,8 @@
+{
+ "deletesnapshotresponse": {
+ "errorcode": 431,
+ "uuidlist": [],
+ "cserrorcode": 9999,
+ "errortext": "Unable to execute API command deletesnapshot due to invalid value. Invalid parameter id value=abdb81fa-f4ac-4ec6-822c-34af7cd461 due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class."
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_delete_tag_invalid_tag_id.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_delete_tag_invalid_tag_id.json b/tests/data/invalid_delete_tag_invalid_tag_id.json
deleted file mode 100644
index ba015af..0000000
--- a/tests/data/invalid_delete_tag_invalid_tag_id.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "queryasyncjobresultresponse": {
- "jobprocstatus": 0,
- "created": "2014-06-01T13:43:16+0200",
- "cmd": "org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd",
- "userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30",
- "jobstatus": 2,
- "jobid": "3cca108f-53df-4a57-8975-3caf29e9d313",
- "jobresultcode": 530,
- "jobresulttype": "object",
- "jobresult": {
- "errorcode": 530,
- "errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm"
- },
- "accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8"
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_delete_tag_tag_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_delete_tag_tag_not_found.json b/tests/data/invalid_delete_tag_tag_not_found.json
new file mode 100644
index 0000000..ba015af
--- /dev/null
+++ b/tests/data/invalid_delete_tag_tag_not_found.json
@@ -0,0 +1,17 @@
+{
+ "queryasyncjobresultresponse": {
+ "jobprocstatus": 0,
+ "created": "2014-06-01T13:43:16+0200",
+ "cmd": "org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd",
+ "userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30",
+ "jobstatus": 2,
+ "jobid": "3cca108f-53df-4a57-8975-3caf29e9d313",
+ "jobresultcode": 530,
+ "jobresulttype": "object",
+ "jobresult": {
+ "errorcode": 530,
+ "errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm"
+ },
+ "accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8"
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_describe_image_image_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_describe_image_image_not_found.json b/tests/data/invalid_describe_image_image_not_found.json
new file mode 100644
index 0000000..0ca8f90
--- /dev/null
+++ b/tests/data/invalid_describe_image_image_not_found.json
@@ -0,0 +1,8 @@
+{
+ "listtemplatesresponse": {
+ "errorcode": 431,
+ "uuidlist": [],
+ "cserrorcode": 4350,
+ "errortext": "Please specify a valid template ID."
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_describe_image_invalid_image_id.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_describe_image_invalid_image_id.json b/tests/data/invalid_describe_image_invalid_image_id.json
deleted file mode 100644
index 0ca8f90..0000000
--- a/tests/data/invalid_describe_image_invalid_image_id.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "listtemplatesresponse": {
- "errorcode": 431,
- "uuidlist": [],
- "cserrorcode": 4350,
- "errortext": "Please specify a valid template ID."
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_describe_volume_instance_not_found.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_describe_volume_instance_not_found.json b/tests/data/invalid_describe_volume_instance_not_found.json
new file mode 100644
index 0000000..11f93dc
--- /dev/null
+++ b/tests/data/invalid_describe_volume_instance_not_found.json
@@ -0,0 +1,3 @@
+{
+ "listvirtualmachinesresponse": {}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/data/invalid_describe_volume_invalid_instance_id.json
----------------------------------------------------------------------
diff --git a/tests/data/invalid_describe_volume_invalid_instance_id.json b/tests/data/invalid_describe_volume_invalid_instance_id.json
deleted file mode 100644
index 11f93dc..0000000
--- a/tests/data/invalid_describe_volume_invalid_instance_id.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "listvirtualmachinesresponse": {}
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/b30b27e8/tests/tags_tests.py
----------------------------------------------------------------------
diff --git a/tests/tags_tests.py b/tests/tags_tests.py
index 6dc1958..e8e57cc 100644
--- a/tests/tags_tests.py
+++ b/tests/tags_tests.py
@@ -73,7 +73,7 @@ class TagsTestCase(Ec2StackAppTestCase):
get = mock.Mock()
get.return_value.text = read_file(
- 'tests/data/invalid_create_tag_invalid_id.json'
+ 'tests/data/invalid_create_tag_not_found.json'
)
get.return_value.status_code = 200
@@ -145,7 +145,7 @@ class TagsTestCase(Ec2StackAppTestCase):
get = mock.Mock()
get.return_value.text = read_file(
- 'tests/data/invalid_delete_tag_invalid_tag_id.json'
+ 'tests/data/invalid_delete_tag_tag_not_found.json'
)
get.return_value.status_code = 200