libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [5/8] libcloud git commit: Fixed exception handling for powering off node
Date Mon, 24 Oct 2016 11:05:03 GMT
Fixed exception handling for powering off node


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

Branch: refs/heads/trunk
Commit: d17901893f875d7c6c9aefbaea9f354e54bfd050
Parents: 50e9a57
Author: Samuel Chong <samuelchong1@gmail.com>
Authored: Mon Oct 17 14:08:10 2016 +1100
Committer: Samuel Chong <samuelchong1@gmail.com>
Committed: Mon Oct 17 14:08:10 2016 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py       | 13 ++-----
 .../fixtures/dimensiondata/server_GetServer.xml | 39 ++++++++++++++++++++
 libcloud/test/compute/test_dimensiondata.py     |  8 +++-
 3 files changed, 49 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d1790189/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index bc8d565..0546ec3 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -640,8 +640,6 @@ class DimensionDataNodeDriver(NodeDriver):
         request_elm = ET.Element('powerOffServer',
                                  {'xmlns': TYPES_URN, 'id': node.id})
 
-        response_code = None
-
         try:
             body = self.connection.request_with_orgId_api_2(
                 'server/powerOffServer',
@@ -649,14 +647,9 @@ class DimensionDataNodeDriver(NodeDriver):
                 data=ET.tostring(request_elm)).object
             response_code = findtext(body, 'responseCode', TYPES_URN)
         except (DimensionDataAPIException, NameError, BaseHTTPError):
-            r = self.ex_wait_for_state(
-                state='stopped',
-                func=self.ex_get_node_by_id,
-                id=node.id,
-                timeout=1)
-            if r is not None:
-                response_code = r.state.upper()
-            pass
+            r = self.ex_get_node_by_id(node.id)
+            response_code = r.state.upper()
+
         return response_code in ['IN_PROGRESS', 'OK', 'STOPPED', 'STOPPING']
 
     def ex_reset(self, node):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d1790189/libcloud/test/compute/fixtures/dimensiondata/server_GetServer.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/server_GetServer.xml b/libcloud/test/compute/fixtures/dimensiondata/server_GetServer.xml
new file mode 100644
index 0000000..fc71562
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/server_GetServer.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server id="5a32d6e4-9707-4813-a269-56ab4d989f4d" datacenterId="NA9">
+    <name>Production Web Server</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="5579f3a7-4c32-4cf5-8a7e-b45c36a35c10"
+            servicePlan="Enterprise" state="NORMAL"/>
+    <monitoring monitoringId="11049" 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>stopped</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"/> <!-- DRS: drsEligible or consistencyGroup or
neither -->
+    <drsEligible/>
+    **OR**
+    <consistencyGroup id="1f4ef-1238933-2344adce-1098" name="ProductionCG" status="DRS_MODE"
serverRole="TARGET"/>
+</server>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d1790189/libcloud/test/compute/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata.py b/libcloud/test/compute/test_dimensiondata.py
index 80dfa4a..7ea0d1e 100644
--- a/libcloud/test/compute/test_dimensiondata.py
+++ b/libcloud/test/compute/test_dimensiondata.py
@@ -515,8 +515,9 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
 
     def test_ex_power_off_INPROGRESS(self):
         DimensionDataMockHttp.type = 'INPROGRESS'
-        node = Node(id='11', name=None, state=None,
+        node = Node(id='11', name=None, state='STOPPING',
                     public_ips=None, private_ips=None, driver=self.driver)
+
         with self.assertRaises(DimensionDataAPIException):
             self.driver.ex_power_off(node)
 
@@ -2183,6 +2184,11 @@ class DimensionDataMockHttp(StorageMockHttp, MockHttp):
             'server_powerOffServer_INPROGRESS.xml')
         return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.OK])
 
+    def _caas_2_3_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_11_INPROGRESS(
+            self, method, url, body, headers):
+        body = self.fixtures.load('server_GetServer.xml')
+        return (httplib.BAD_REQUEST, body, {}, httplib.responses[httplib.OK])
+
     def _caas_2_3_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_network_networkDomain(self, method,
url, body, headers):
         body = self.fixtures.load(
             'network_networkDomain.xml')


Mime
View raw message