summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Kulik <johannes.kulik@sap.com>2020-05-11 15:57:32 +0200
committerJohannes Kulik <johannes.kulik@sap.com>2020-07-14 10:03:41 +0200
commitdc4eb020ad3f9ebd90d030bd20853019918c51b9 (patch)
treeea97fd4c741b505cf5e5f9b767f3fe4e96e9e631
parent32c8d43a20cb6a29f03324fbc2e6cad3bfb5a294 (diff)
downloadoslo-vmware-dc4eb020ad3f9ebd90d030bd20853019918c51b9.tar.gz
Add backend-independent access to cookiejar3.6.0
Having the cookiejar available as attribute on the client instead of some child objects exposes an interface which depending code can rely on. This will help with upcoming efforts to switch the SOAP library backing oslo.vmware. This is part of phase 1 of https://specs.openstack.org/openstack/oslo-specs/specs/victoria/oslo-vmware-soap-library-switch.html Change-Id: I72082f10a184a2451dfda3d002a9288fefcef961
-rw-r--r--oslo_vmware/rw_handles.py4
-rw-r--r--oslo_vmware/service.py31
-rw-r--r--oslo_vmware/tests/test_rw_handles.py4
-rw-r--r--oslo_vmware/tests/test_service.py6
-rw-r--r--oslo_vmware/tests/test_vim.py2
-rw-r--r--releasenotes/notes/bp-oslo-vmware-soap-library-switch-cookiejar-access-d7efcc23d0eaee98.yaml8
6 files changed, 41 insertions, 14 deletions
diff --git a/oslo_vmware/rw_handles.py b/oslo_vmware/rw_handles.py
index e0dfc7c..e3769ec 100644
--- a/oslo_vmware/rw_handles.py
+++ b/oslo_vmware/rw_handles.py
@@ -492,7 +492,7 @@ class VmdkWriteHandle(VmdkHandle):
url, thumbprint = self._find_vmdk_url(lease_info, host, port)
self._vm_ref = lease_info.entity
- cookies = session.vim.client.options.transport.cookiejar
+ cookies = session.vim.client.cookiejar
# Create HTTP connection to write to VMDK URL
if http_method == 'PUT':
overwrite = 't'
@@ -600,7 +600,7 @@ class VmdkReadHandle(VmdkHandle):
# find URL of the VMDK file to be read and open connection
url, thumbprint = self._find_vmdk_url(lease_info, host, port)
- cookies = session.vim.client.options.transport.cookiejar
+ cookies = session.vim.client.cookiejar
self._conn = self._create_read_connection(url,
cookies=cookies,
ssl_thumbprint=thumbprint)
diff --git a/oslo_vmware/service.py b/oslo_vmware/service.py
index 09702f4..89ed221 100644
--- a/oslo_vmware/service.py
+++ b/oslo_vmware/service.py
@@ -209,6 +209,25 @@ class MemoryCache(cache.ObjectCache):
_CACHE = MemoryCache()
+class CompatibilitySudsClient(client.Client):
+ """suds client with added cookiejar attribute
+
+ The cookiejar properties allow reading/setting the cookiejar used by the
+ underlying transport.
+ """
+ def __init__(self, *args, **kwargs):
+ super(CompatibilitySudsClient, self).__init__(*args, **kwargs)
+
+ @property
+ def cookiejar(self):
+ return self.options.transport.cookiejar
+
+ @cookiejar.setter
+ def cookiejar(self, cookies):
+ self.options.transport.session.cookies = cookies
+ self.options.transport.cookiejar = cookies
+
+
class Service(object):
"""Base class containing common functionality for invoking vSphere
services
@@ -226,11 +245,11 @@ class Service(object):
insecure=insecure,
pool_maxsize=pool_maxsize,
connection_timeout=connection_timeout)
- self.client = client.Client(self.wsdl_url,
- transport=transport,
- location=self.soap_url,
- plugins=[ServiceMessagePlugin()],
- cache=_CACHE)
+ self.client = CompatibilitySudsClient(self.wsdl_url,
+ transport=transport,
+ location=self.soap_url,
+ plugins=[ServiceMessagePlugin()],
+ cache=_CACHE)
self._service_content = None
self._vc_session_cookie = None
@@ -312,7 +331,7 @@ class Service(object):
def get_http_cookie(self):
"""Return the vCenter session cookie."""
- cookies = self.client.options.transport.cookiejar
+ cookies = self.client.cookiejar
for cookie in cookies:
if cookie.name.lower() == 'vmware_soap_session':
return cookie.value
diff --git a/oslo_vmware/tests/test_rw_handles.py b/oslo_vmware/tests/test_rw_handles.py
index d6ef43d..6f7d4c1 100644
--- a/oslo_vmware/tests/test_rw_handles.py
+++ b/oslo_vmware/tests/test_rw_handles.py
@@ -217,7 +217,7 @@ class VmdkWriteHandleTest(base.TestCase):
vim_cookie = mock.Mock()
vim_cookie.name = 'name'
vim_cookie.value = 'value'
- session.vim.client.options.transport.cookiejar = [vim_cookie]
+ session.vim.client.cookiejar = [vim_cookie]
return session
def test_init_failure(self):
@@ -344,7 +344,7 @@ class VmdkReadHandleTest(base.TestCase):
vim_cookie = mock.Mock()
vim_cookie.name = 'name'
vim_cookie.value = 'value'
- session.vim.client.options.transport.cookiejar = [vim_cookie]
+ session.vim.client.cookiejar = [vim_cookie]
return session
def test_init_failure(self):
diff --git a/oslo_vmware/tests/test_service.py b/oslo_vmware/tests/test_service.py
index 8fc9945..b03c3ff 100644
--- a/oslo_vmware/tests/test_service.py
+++ b/oslo_vmware/tests/test_service.py
@@ -60,7 +60,7 @@ class ServiceTest(base.TestCase):
def setUp(self):
super(ServiceTest, self).setUp()
- patcher = mock.patch('suds.client.Client')
+ patcher = mock.patch('oslo_vmware.service.CompatibilitySudsClient')
self.addCleanup(patcher.stop)
self.SudsClientMock = patcher.start()
@@ -377,7 +377,7 @@ class ServiceTest(base.TestCase):
cookie = mock.Mock()
cookie.name = 'vmware_soap_session'
cookie.value = cookie_value
- svc_obj.client.options.transport.cookiejar = [cookie]
+ svc_obj.client.cookiejar = [cookie]
self.assertEqual(cookie_value, svc_obj.get_http_cookie())
def test_get_session_cookie_with_no_cookie(self):
@@ -385,7 +385,7 @@ class ServiceTest(base.TestCase):
cookie = mock.Mock()
cookie.name = 'cookie'
cookie.value = 'xyz'
- svc_obj.client.options.transport.cookiejar = [cookie]
+ svc_obj.client.cookiejar = [cookie]
self.assertIsNone(svc_obj.get_http_cookie())
def test_set_soap_headers(self):
diff --git a/oslo_vmware/tests/test_vim.py b/oslo_vmware/tests/test_vim.py
index 0887a05..ca0fb9e 100644
--- a/oslo_vmware/tests/test_vim.py
+++ b/oslo_vmware/tests/test_vim.py
@@ -31,7 +31,7 @@ class VimTest(base.TestCase):
def setUp(self):
super(VimTest, self).setUp()
- patcher = mock.patch('suds.client.Client')
+ patcher = mock.patch('oslo_vmware.service.CompatibilitySudsClient')
self.addCleanup(patcher.stop)
self.SudsClientMock = patcher.start()
self.useFixture(i18n_fixture.ToggleLazy(True))
diff --git a/releasenotes/notes/bp-oslo-vmware-soap-library-switch-cookiejar-access-d7efcc23d0eaee98.yaml b/releasenotes/notes/bp-oslo-vmware-soap-library-switch-cookiejar-access-d7efcc23d0eaee98.yaml
new file mode 100644
index 0000000..3927e83
--- /dev/null
+++ b/releasenotes/notes/bp-oslo-vmware-soap-library-switch-cookiejar-access-d7efcc23d0eaee98.yaml
@@ -0,0 +1,8 @@
+---
+upgrade:
+ - Code accessing the ``cookiejar`` must use ``session.client.cookiejar``
+ instead of the previous ``session.client.options.transport.cookiejar``,
+ because with `this spec
+ <https://specs.openstack.org/openstack/oslo-specs/specs/victoria/oslo-vmware-soap-library-switch.html>`_
+ we switch the backing SOAP library and different libraries have different
+ locations for their transport and cookiejar objects.