Bug fix on None type for return

Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/418b4e02
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/418b4e02
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/418b4e02

Branch: refs/heads/trunk
Commit: 418b4e02a05d2e857748aa30708a319b6d84fd8d
Parents: 79e2581
Author: Jeffrey Dunham <jeffrey.a.dun...@gmail.com>
Authored: Tue May 3 19:26:51 2016 -0400
Committer: Mark S. Maglana <mmagl...@gmail.com>
Committed: Fri Sep 16 11:21:47 2016 -0700

----------------------------------------------------------------------
 libcloud/backup/drivers/dimensiondata.py        |  2 ++
 .../dimensiondata/server_server_NOBACKUP.xml    | 29 ++++++++++++++++
 libcloud/test/backup/test_dimensiondata.py      | 36 +++++++++++++-------
 3 files changed, 55 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/418b4e02/libcloud/backup/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/backup/drivers/dimensiondata.py 
b/libcloud/backup/drivers/dimensiondata.py
index 414d1c8..9204957 100644
--- a/libcloud/backup/drivers/dimensiondata.py
+++ b/libcloud/backup/drivers/dimensiondata.py
@@ -517,6 +517,8 @@ class DimensionDataBackupDriver(BackupDriver):
         """
         if not isinstance(target, BackupTarget):
             target = self.ex_get_target_by_id(target)
+            if target is None:
+                return
         response = self.connection.request_with_orgId_api_1(
             'server/%s/backup' % (target.address),
             method='GET').object

http://git-wip-us.apache.org/repos/asf/libcloud/blob/418b4e02/libcloud/test/backup/fixtures/dimensiondata/server_server_NOBACKUP.xml
----------------------------------------------------------------------
diff --git 
a/libcloud/test/backup/fixtures/dimensiondata/server_server_NOBACKUP.xml 
b/libcloud/test/backup/fixtures/dimensiondata/server_server_NOBACKUP.xml
new file mode 100644
index 0000000..6f76aba
--- /dev/null
+++ b/libcloud/test/backup/fixtures/dimensiondata/server_server_NOBACKUP.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<servers xmlns="urn:didata.com:api:cloud:types" pageNumber="1" pageCount="1" 
totalCount="1" pageSize="250">
+    <server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+        <name>Production Web Server MCP 2</name>
+        <description>Server to host our main web application.</description>
+        <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" 
family="WINDOWS" />
+        <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>4</memoryGb>
+        <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" 
speed="STANDARD" state="NORMAL" />
+        <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+            <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" 
privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" 
vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" 
state="NORMAL" />
+        </networkInfo>
+        <backup assetId="91002e08-8dc1-47a1-ad33-04f501c06f87" 
servicePlan="Advanced" state="NORMAL" />
+        <monitoring monitoringId="11039" servicePlan="ESSENTIALS" 
state="NORMAL" />
+        <softwareLabel>MSSQL2008R2S</softwareLabel>
+        <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+        <createTime>2015-12-02T10:31:33.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>PENDING_CHANGE</state>
+        <progress>
+            <action>SHUTDOWN_SERVER</action>
+            <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+            <userName>devuser1</userName>
+        </progress>
+        <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" 
apiVersion="9354" />
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>
+</servers>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/418b4e02/libcloud/test/backup/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/test_dimensiondata.py 
b/libcloud/test/backup/test_dimensiondata.py
index 589a577..a17065d 100644
--- a/libcloud/test/backup/test_dimensiondata.py
+++ b/libcloud/test/backup/test_dimensiondata.py
@@ -130,12 +130,18 @@ class DimensionDataTests(unittest.TestCase, 
TestCaseMixin):
         self.assertEqual(client.type.type, 'FA.Linux')
         self.assertEqual(client.running_job.progress, 5)
         self.assertTrue(isinstance(client.running_job, BackupTargetJob))
-        self.assertEqual(len(client.alert.notify_list), 2)
-        self.assertTrue(isinstance(client.alert.notify_list, list))
-
-    def test_ex_cancel_target_job(self):
-        target = self.driver.list_targets()[0]
-        response = self.driver.ex_get_backup_details_for_target(target)
+        self.assertEqual(len(client.alert.notify_list), 2)
+        self.assertTrue(isinstance(client.alert.notify_list, list))
+
+    def test_ex_get_backup_details_for_target_NOBACKUP(self):
+        target = self.driver.list_targets()[0].address
+        DimensionDataMockHttp.type = 'NOBACKUP'
+        response = self.driver.ex_get_backup_details_for_target(target)
+        self.assertTrue(response is None)
+
+    def test_ex_cancel_target_job(self):
+        target = self.driver.list_targets()[0]
+        response = self.driver.ex_get_backup_details_for_target(target)
         client = response.clients[0]
         self.assertTrue(isinstance(client.running_job, BackupTargetJob))
         success = client.running_job.cancel()
@@ -423,12 +429,18 @@ class DimensionDataMockHttp(MockHttp):
                 '_backup_INFO.xml')
             return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-        else:
-            raise ValueError("Unknown Method {0}".format(method))
-
-    def 
_oec_0_9_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_e75ead52_692f_4314_8725_c8a4f4d13a87_backup_EXISTS(
-            self, method, url, body, headers):
-        # only POSTs are implemented
+        else:
+            raise ValueError("Unknown Method {0}".format(method))
+
+    def 
_caas_2_2_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87_NOBACKUP(
+            self, method, url, body, headers):
+        assert(method == 'GET')
+        body = self.fixtures.load('server_server_NOBACKUP.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):
+        # only POSTs are implemented
         # If we get any other method something has gone wrong
         assert(method == 'POST')
         body = self.fixtures.load(

Reply via email to