From abbb2740735d96751ef949091ff2ab1b012376f5 Mon Sep 17 00:00:00 2001 From: Shawn Hartsock Date: Tue, 29 Jul 2014 11:42:01 -0400 Subject: [PATCH 1/2] python3: fix reraise Related to six bug https://bitbucket.org/gutworth/six/issue/86/sixreraise-exception_object-none-traceback closes: https://github.com/vmware/pyvmomi/issues/92 --- pyVim/connect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyVim/connect.py b/pyVim/connect.py index 3f4f4aa..21b3b41 100644 --- a/pyVim/connect.py +++ b/pyVim/connect.py @@ -315,7 +315,8 @@ def __Login(host, port, user, pwd, service, adapter, version, path, # why the connection failed beyond the message string. (type, value, traceback) = sys.exc_info() if traceback: - reraise(vim.fault.HostConnectFault(msg=str(e)), None, traceback) + fault = vim.fault.HostConnectFault(msg=str(e)) + reraise(vim.fault.HostConnectFault, fault, traceback) else: raise vim.fault.HostConnectFault(msg=str(e)) From 124a8ac6cea149cf17bb70c88e1f8bb1828f0699 Mon Sep 17 00:00:00 2001 From: Shawn Hartsock Date: Tue, 29 Jul 2014 12:22:54 -0400 Subject: [PATCH 2/2] python3: fix cookie handler in test * tries both cases for the set-cookie header to make sure we catch cookie transitions. * tampers with basic_connection fixture to demonstrate closes: https://github.com/vmware/pyvmomi/issues/93 --- pyVmomi/SoapAdapter.py | 5 ++++- tests/fixtures/basic_connection.yaml | 10 +++++----- tests/test_connect.py | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyVmomi/SoapAdapter.py b/pyVmomi/SoapAdapter.py index 0bec26e..de50e15 100644 --- a/pyVmomi/SoapAdapter.py +++ b/pyVmomi/SoapAdapter.py @@ -1241,7 +1241,10 @@ class SoapStubAdapter(SoapStubAdapterBase): # The server is probably sick, drop all of the cached connections. self.DropConnections() raise - cookie = resp.getheader('set-cookie') + cookie = resp.getheader('Set-Cookie') + if cookie is None: + # try lower-case header for backwards compat. with old vSphere + cookie = resp.getheader('set-cookie') status = resp.status if cookie: diff --git a/tests/fixtures/basic_connection.yaml b/tests/fixtures/basic_connection.yaml index 547c05c..0314719 100644 --- a/tests/fixtures/basic_connection.yaml +++ b/tests/fixtures/basic_connection.yaml @@ -52,7 +52,7 @@ interactions: content-length: ['3332'] content-type: [text/xml; charset=utf-8] date: ['Mon, 21 Jul 2014 22:31:05 GMT'] - set-cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/; + set-cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; HttpOnly; Secure;] status: {code: 200, message: OK} - request: @@ -68,7 +68,7 @@ interactions: headers: Accept-Encoding: ['gzip, deflate'] Content-Type: [text/xml; charset=UTF-8] - Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/; + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; HttpOnly; Secure;] SOAPAction: ['"urn:vim25/4.1"'] method: POST @@ -99,7 +99,7 @@ interactions: headers: Accept-Encoding: ['gzip, deflate'] Content-Type: [text/xml; charset=UTF-8] - Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/; + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; HttpOnly; Secure;] SOAPAction: ['"urn:vim25/4.1"'] method: POST @@ -155,7 +155,7 @@ interactions: headers: Accept-Encoding: ['gzip, deflate'] Content-Type: [text/xml; charset=UTF-8] - Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/; + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; HttpOnly; Secure;] SOAPAction: ['"urn:vim25/4.1"'] method: POST @@ -212,7 +212,7 @@ interactions: headers: Accept-Encoding: ['gzip, deflate'] Content-Type: [text/xml; charset=UTF-8] - Cookie: [vmware_soap_session="52970dd3-2b0f-647b-22b3-44bda6d49983"; Path=/; + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; HttpOnly; Secure;] SOAPAction: ['"urn:vim25/4.1"'] method: POST diff --git a/tests/test_connect.py b/tests/test_connect.py index b5bb425..d44f24d 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -36,10 +36,15 @@ class ConnectionTests(unittest.TestCase): si = connect.Connect(host='vcsa', user='my_user', pwd='my_password') + cookie = si._stub.cookie session_id = si.content.sessionManager.currentSession.key + # NOTE (hartsock): The cookie value should never change during + # a connected session. That should be verifiable in these tests. + self.assertEqual(cookie, si._stub.cookie) # NOTE (hartsock): assertIsNotNone does not work in Python 2.6 self.assertTrue(session_id is not None) self.assertEqual('52773cd3-35c6-b40a-17f1-fe664a9f08f3', session_id) + self.assertTrue(session_id in cookie) @vcr.use_cassette('basic_connection_bad_password.yaml', cassette_library_dir=fixtures_path, record_mode='none')