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 2017/04/13 09:33:31 UTC

[25/46] libcloud git commit: make ET a switch between lxml and xml.etree, try and fix the crazy cloudstack tests

make ET a switch between lxml and xml.etree, try and fix the crazy cloudstack tests


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

Branch: refs/heads/trunk
Commit: 0c114fbc42b89ef1c27f8213055619b76f02be31
Parents: c45fa04
Author: Anthony Shaw <an...@apache.org>
Authored: Wed Apr 12 12:19:51 2017 +1000
Committer: Anthony Shaw <an...@apache.org>
Committed: Wed Apr 12 12:19:51 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py       | 16 ++++++----------
 libcloud/test/compute/test_cloudstack.py |  6 +++---
 libcloud/test/compute/test_ktucloud.py   |  6 +++---
 libcloud/test/compute/test_openstack.py  |  2 +-
 libcloud/utils/py3.py                    |  7 ++++++-
 5 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c114fbc/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index 2766853..d2b833d 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -25,16 +25,12 @@ from libcloud.utils.py3 import urlencode
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import b
 from libcloud.utils.py3 import next
+from libcloud.utils.py3 import ET
 
 urlparse = urlparse.urlparse
 
 import time
 
-try:
-    from lxml import etree as ET
-except ImportError:
-    from xml.etree import ElementTree as ET
-
 from xml.parsers.expat import ExpatError
 
 from libcloud.common.base import XmlResponse, ConnectionUserAndKey
@@ -339,8 +335,8 @@ class VCloudConnection(ConnectionUserAndKey):
                                     headers=self._get_auth_headers())
 
             resp = self.connection.getresponse()
-            headers = dict(resp.getheaders())
-            body = ET.XML(resp.read())
+            headers = resp.headers
+            body = ET.XML(resp.text)
 
             try:
                 self.token = headers['set-cookie']
@@ -833,7 +829,7 @@ class VCloud_1_5_Connection(VCloudConnection):
                                     headers=self._get_auth_headers())
 
             resp = self.connection.getresponse()
-            headers = dict(resp.getheaders())
+            headers = resp.headers
 
             # Set authorization token
             try:
@@ -842,7 +838,7 @@ class VCloud_1_5_Connection(VCloudConnection):
                 raise InvalidCredsError()
 
             # Get the URL of the Organization
-            body = ET.XML(resp.read())
+            body = ET.XML(resp.text)
             self.org_name = body.get('org')
             org_list_url = get_url_path(
                 next((link for link in body.findall(fixxpath(body, 'Link'))
@@ -854,7 +850,7 @@ class VCloud_1_5_Connection(VCloudConnection):
                 self.connection.set_http_proxy(self.proxy_url)
             self.connection.request(method='GET', url=org_list_url,
                                     headers=self.add_default_headers({}))
-            body = ET.XML(self.connection.getresponse().read())
+            body = ET.XML(self.connection.getresponse().text)
             self.driver.org = get_url_path(
                 next((org for org in body.findall(fixxpath(body, 'Org'))
                      if org.get('name') == self.org_name)).get('href')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c114fbc/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index 753ae90..df675ae 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -1266,7 +1266,7 @@ class CloudStackTestCase(CloudStackCommonTestCase, unittest.TestCase):
             self.fail('url provided but driver raised an exception')
 
 
-class CloudStackMockHttp(MockHttp):
+class CloudStackMockHttp(MockHttp, unittest.TestCase):
     fixtures = ComputeFileFixtures('cloudstack')
     fixture_tag = 'default'
 
@@ -1305,7 +1305,7 @@ class CloudStackMockHttp(MockHttp):
         else:
             fixture = command + '_' + self.fixture_tag + '.json'
             body, obj = self._load_fixture(fixture)
-            return (httplib.OK, body, obj, httplib.responses[httplib.OK])
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _test_path_userdata(self, method, url, body, headers):
         if 'deployVirtualMachine' in url:
@@ -1315,7 +1315,7 @@ class CloudStackMockHttp(MockHttp):
     def _cmd_queryAsyncJobResult(self, jobid):
         fixture = 'queryAsyncJobResult' + '_' + str(jobid) + '.json'
         body, obj = self._load_fixture(fixture)
-        return (httplib.OK, body, obj, httplib.responses[httplib.OK])
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c114fbc/libcloud/test/compute/test_ktucloud.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ktucloud.py b/libcloud/test/compute/test_ktucloud.py
index 87c2967..f2fa2ec 100644
--- a/libcloud/test/compute/test_ktucloud.py
+++ b/libcloud/test/compute/test_ktucloud.py
@@ -90,7 +90,7 @@ class KTUCloudNodeDriverTest(unittest.TestCase, TestCaseMixin):
         self.assertTrue(check)
 
 
-class KTUCloudStackMockHttp(MockHttp):
+class KTUCloudStackMockHttp(MockHttp, unittest.TestCase):
     fixtures = ComputeFileFixtures('ktucloud')
     fixture_tag = 'default'
 
@@ -119,12 +119,12 @@ class KTUCloudStackMockHttp(MockHttp):
         else:
             fixture = command + '_' + self.fixture_tag + '.json'
             body, obj = self._load_fixture(fixture)
-            return (httplib.OK, body, obj, httplib.responses[httplib.OK])
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
     def _cmd_queryAsyncJobResult(self, jobid):
         fixture = 'queryAsyncJobResult' + '_' + str(jobid) + '.json'
         body, obj = self._load_fixture(fixture)
-        return (httplib.OK, body, obj, httplib.responses[httplib.OK])
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c114fbc/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index fab2d7e..bd84143 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -459,7 +459,7 @@ class OpenStack_1_0_FactoryMethodTests(OpenStack_1_0_Tests):
             self.fail('Exception was not thrown')
 
 
-class OpenStackMockHttp(MockHttp):
+class OpenStackMockHttp(MockHttp, unittest.TestCase):
     fixtures = ComputeFileFixtures('openstack')
     auth_fixtures = OpenStackFixtures()
     json_content_headers = {'content-type': 'application/json; charset=UTF-8'}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0c114fbc/libcloud/utils/py3.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/py3.py b/libcloud/utils/py3.py
index ef38eed..9b7a866 100644
--- a/libcloud/utils/py3.py
+++ b/libcloud/utils/py3.py
@@ -25,8 +25,13 @@ from __future__ import absolute_import
 import sys
 import types
 
+DEFAULT_LXML = False
+
 try:
-    from lxml import etree as ET
+    if DEFAULT_LXML:
+        from lxml import etree as ET
+    else:
+        from xml.etree import ElementTree as ET
 except ImportError:
     from xml.etree import ElementTree as ET