Modified async code to poll for status.  Modified unit tests accordingly

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

Branch: refs/heads/trunk
Commit: 5c663200240f2c650908e1f0d05f1c4866de85c5
Parents: 34cdb3f
Author: davidcrossland <[email protected]>
Authored: Mon Jun 2 14:11:13 2014 +0100
Committer: Michael Bennett <[email protected]>
Committed: Wed Nov 19 13:02:30 2014 -0500

----------------------------------------------------------------------
 libcloud/compute/drivers/azure.py               | 36 ++++++--------------
 ...rations_acc33f6756cda6fd96826394fce4c9f3.xml |  1 +
 libcloud/test/compute/test_azure.py             | 12 ++++++-
 3 files changed, 22 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5c663200/libcloud/compute/drivers/azure.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure.py 
b/libcloud/compute/drivers/azure.py
index 8de8e06..c33d077 100644
--- a/libcloud/compute/drivers/azure.py
+++ b/libcloud/compute/drivers/azure.py
@@ -600,12 +600,10 @@ class AzureNodeDriver(NodeDriver):
                     None, # data_virtual_hard_disks
                     size)) # role_size)
 
-            self._ex_complete_async_azure_operation(response)
-
             if response.status != 202:
                 raise LibcloudError('Message: %s, Body: %s, Status code: %d' % 
(response.error, response.body, response.status), driver=self)
 
-
+            self._ex_complete_async_azure_operation(response)
 
         return Node(
             id=name,
@@ -941,7 +939,7 @@ class AzureNodeDriver(NodeDriver):
         _affinity_group = res.hosted_service_properties.affinity_group
         _cloud_service_location = res.hosted_service_properties.location
 
-        if _affinity_group is not None:
+        if _affinity_group is not None and _affinity_group is not u'':
             return self.service_location(True, _affinity_group)
         elif _cloud_service_location is not None:
             return self.service_location(False, _cloud_service_location)
@@ -967,49 +965,35 @@ class AzureNodeDriver(NodeDriver):
                 AzureXmlSerializer.create_storage_service_input_to_xml(
                     kwargs['service_name'],
                     kwargs['service_name'],
-                    kwargs['service_name'],
+                    self._encode_base64(kwargs['service_name']),
                     kwargs['location'],
                     None,  # Location
                     True,  # geo_replication_enabled
                     None)) # extended_properties
 
-            if response.status != 200:
+            if response.status != 202:
                 raise LibcloudError('Message: %s, Body: %s, Status code: %d' % 
(response.error, response.body, response.status), driver=self)
 
-            result = self._parse_response_for_async_op(response)
         else:
             response = self._perform_post(
                 self._get_storage_service_path(),
                 AzureXmlSerializer.create_storage_service_input_to_xml(
                     kwargs['service_name'],
                     kwargs['service_name'],
-                    kwargs['service_name'],
+                    self._encode_base64(kwargs['service_name']),
                     None,  # Affinity Group
                     kwargs['location'],  # Location
                     True,  # geo_replication_enabled
                     None)) # extended_properties
 
-            if response.status != 200:
+            if response.status != 202:
                 raise LibcloudError('Message: %s, Body: %s, Status code: %d' % 
(response.error, response.body, response.status), driver=self)
 
-            result = self._parse_response_for_async_op(response)
 
         # We need to wait for this to be created before we can 
-        # create the storage container and the instance. 
-
-        operation_status = self._get_operation_status(result.request_id)
+        # create the storage container and the instance.
+        self._ex_complete_async_azure_operation(response, 
"create_storage_account")
 
-        timeout = 60 * 5
-        waittime = 0
-        interval = 5  
-
-        while operation_status.status == "InProgress" and waittime < timeout:
-            operation_status = self._get_operation_status(result.request_id)
-            if operation_status.status == "Succeeded":
-                break
-
-            waittime += interval
-            time.sleep(interval)
         return
 
     def _get_operation_status(self, request_id):
@@ -1414,7 +1398,7 @@ class AzureNodeDriver(NodeDriver):
     def _ex_complete_async_azure_operation(self, response=None, 
operation_type='create_node'):
 
         request_id = self._parse_response_for_async_op(response)
-        operation_status = self._get_operation_status(request_id)
+        operation_status = self._get_operation_status(request_id.request_id)
 
         timeout = 60 * 5
         waittime = 0
@@ -1460,7 +1444,7 @@ class AzureXmlSerializer():
             'CreateStorageServiceInput',
             [('ServiceName', service_name),
              ('Description', description),
-             ('Label', label, AzureNodeDriver._encode_base64),
+             ('Label', label),
              ('AffinityGroup', affinity_group),
              ('Location', location),
              ('GeoReplicationEnabled', geo_replication_enabled, _lower)],

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5c663200/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3.xml
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3.xml
 
b/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3.xml
new file mode 100644
index 0000000..2f89d16
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure/_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3.xml
@@ -0,0 +1 @@
+<Operation xmlns="http://schemas.microsoft.com/windowsazure"; 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance";><ID>fbd6fd8f-9e3e-acad-8524-92f64e1050b6</ID><Status>Succeeded</Status></Operation>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5c663200/libcloud/test/compute/test_azure.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_azure.py 
b/libcloud/test/compute/test_azure.py
index ac833bd..c52a133 100644
--- a/libcloud/test/compute/test_azure.py
+++ b/libcloud/test/compute/test_azure.py
@@ -18,6 +18,7 @@ from libcloud.compute.providers import get_driver
 
 class AzureNodeDriverTests(unittest.TestCase) :
 
+    #required otherwise we get client side SSL verification
     libcloud.security.VERIFY_SSL_CERT = False
 
     SUBSCRIPTION_ID = '3761b98b-673d-526c-8d55-fee918758e6e'
@@ -325,6 +326,7 @@ class AzureMockHttp(MockHttp):
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc_deployments(self,
 method, url, body, headers):
+        headers["x-ms-request-id"]="acc33f6756cda6fd96826394fce4c9f3"
         if method == "GET":
                 body = 
self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc_deployments.xml')
 
@@ -337,19 +339,21 @@ class AzureMockHttp(MockHttp):
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deploymentslots_Production(self,
 method, url, body, headers):
+
         if method == "GET":
                 body = 
self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deploymentslots_Production.xml')
 
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deployments(self,
 method, url, body, headers):
+
         if method == "GET":
                 body = 
self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deployments.xml')
 
         return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc2_deployments_dcoddkinztest02_roles(self,
 method, url, body, headers):
-
+        headers["x-ms-request-id"]="acc33f6756cda6fd96826394fce4c9f3"
         return (httplib.ACCEPTED, body, headers, 
httplib.responses[httplib.ACCEPTED])
 
     def 
_3761b98b_673d_526c_8d55_fee918758e6e_services_hostedservices_testdcabc3(self, 
method, url, body, headers):
@@ -374,5 +378,11 @@ class AzureMockHttp(MockHttp):
 
         return (httplib.TEMPORARY_REDIRECT, None, headers, 
httplib.responses[httplib.TEMPORARY_REDIRECT])
 
+    def 
_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3(self,
 method, url, body, headers):
+
+        if method == "GET":
+                body = 
self.fixtures.load('_3761b98b_673d_526c_8d55_fee918758e6e_operations_acc33f6756cda6fd96826394fce4c9f3.xml')
+
+        return (httplib.OK, body, headers, httplib.responses[httplib.OK])
 if __name__ == '__main__':
     sys.exit(unittest.main())

Reply via email to