You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/02/07 09:53:29 UTC
[4/5] libcloud git commit: DimensionData: Adding a new exception
code/message, testing backup exceptions
DimensionData: Adding a new exception code/message, testing backup exceptions
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a956d827
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a956d827
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a956d827
Branch: refs/heads/trunk
Commit: a956d8274ac388ec0001cc5552f934c87e89d3ce
Parents: 234ada0
Author: Jeffrey Dunham <je...@gmail.com>
Authored: Sat Feb 6 16:58:47 2016 -0500
Committer: anthony-shaw <an...@gmail.com>
Committed: Sun Feb 7 19:51:26 2016 +1100
----------------------------------------------------------------------
libcloud/common/dimensiondata.py | 26 +++++++++++++++-----
...92f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml | 7 ++++++
libcloud/test/backup/test_dimensiondata.py | 21 ++++++++++++++++
3 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a956d827/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index fc5c9be..ee75afd 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -81,6 +81,18 @@ API_ENDPOINTS = {
# Default API end-point for the base connection class.
DEFAULT_REGION = 'dd-na'
+BAD_CODE_XML_ELEMENTS = (
+ ('responseCode', SERVER_NS),
+ ('reponseCode', TYPES_URN),
+ ('result', GENERAL_NS)
+)
+
+BAD_MESSAGE_XML_ELEMENTS = (
+ ('message', SERVER_NS),
+ ('message', TYPES_URN),
+ ('resultDetail', GENERAL_NS)
+)
+
class NetworkDomainServicePlan(object):
ESSENTIALS = "ESSENTIALS"
@@ -97,12 +109,14 @@ class DimensionDataResponse(XmlResponse):
body = self.parse_body()
if self.status == httplib.BAD_REQUEST:
- code = findtext(body, 'responseCode', SERVER_NS)
- if code is None:
- code = findtext(body, 'responseCode', TYPES_URN)
- message = findtext(body, 'message', SERVER_NS)
- if message is None:
- message = findtext(body, 'message', TYPES_URN)
+ for response_code in BAD_CODE_XML_ELEMENTS:
+ code = findtext(body, response_code[0], response_code[1])
+ if code is not None:
+ break
+ for message in BAD_MESSAGE_XML_ELEMENTS:
+ message = findtext(body, message[0], message[1])
+ if message is not None:
+ break
raise DimensionDataAPIException(code=code,
msg=message,
driver=self.connection.driver)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a956d827/libcloud/test/backup/fixtures/dimensiondata/oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/fixtures/dimensiondata/oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml b/libcloud/test/backup/fixtures/dimensiondata/oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml
new file mode 100644
index 0000000..5ffa67e
--- /dev/null
+++ b/libcloud/test/backup/fixtures/dimensiondata/oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<ns0:Status xmlns:ns0="http://oec.api.opsource.net/schemas/general">
+ <ns0:operation>Enable Backup for Server</ns0:operation>
+ <ns0:result>ERROR</ns0:result>
+ <ns0:resultDetail>Cloud backup for this server is already enabled or being enabled (state: NORMAL).</ns0:resultDetail>
+ <ns0:resultCode>REASON_550</ns0:resultCode>
+</ns0:Status>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a956d827/libcloud/test/backup/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/test_dimensiondata.py b/libcloud/test/backup/test_dimensiondata.py
index 5121d8b..11d2b73 100644
--- a/libcloud/test/backup/test_dimensiondata.py
+++ b/libcloud/test/backup/test_dimensiondata.py
@@ -16,6 +16,7 @@
import sys
from libcloud.utils.py3 import httplib
+from libcloud.common.dimensiondata import DimensionDataAPIException
from libcloud.common.types import InvalidCredsError
from libcloud.backup.drivers.dimensiondata import DimensionDataBackupDriver as DimensionData
@@ -58,6 +59,16 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
self.assertEqual(target.address, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
self.assertEqual(target.extra['servicePlan'], 'Enterprise')
+ def test_create_target_EXISTS(self):
+ DimensionDataMockHttp.type = 'EXISTS'
+ with self.assertRaises(DimensionDataAPIException) as context:
+ self.driver.create_target(
+ 'name',
+ 'e75ead52-692f-4314-8725-c8a4f4d13a87',
+ extra={'servicePlan': 'Enterprise'})
+ self.assertEqual(context.exception.code, 'ERROR')
+ self.assertEqual(context.exception.msg, 'Cloud backup for this server is already enabled or being enabled (state: NORMAL).')
+
def test_update_target(self):
target = self.driver.list_targets()[0]
extra = {'servicePlan': 'Enterprise'}
@@ -109,6 +120,10 @@ class DimensionDataMockHttp(MockHttp):
body = self.fixtures.load('oec_0_9_myaccount.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _oec_0_9_myaccount_EXISTS(self, method, url, body, headers):
+ body = self.fixtures.load('oec_0_9_myaccount.xml')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
def _oec_0_9_myaccount_INPROGRESS(self, method, url, body, headers):
body = self.fixtures.load('oec_0_9_myaccount.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -141,6 +156,12 @@ class DimensionDataMockHttp(MockHttp):
'oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS(
+ self, method, url, body, headers):
+ body = self.fixtures.load(
+ 'oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS.xml')
+ return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.OK])
+
def _oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_modify(
self, method, url, body, headers):
body = self.fixtures.load(