Merge pull request #94 from hartsock/python3

Python3: fix cookie handler in test & reraise exception handler
This commit is contained in:
Shawn Hartsock
2014-07-29 13:06:51 -04:00
4 changed files with 16 additions and 7 deletions

View File

@@ -315,7 +315,8 @@ def __Login(host, port, user, pwd, service, adapter, version, path,
# why the connection failed beyond the message string. # why the connection failed beyond the message string.
(type, value, traceback) = sys.exc_info() (type, value, traceback) = sys.exc_info()
if traceback: 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: else:
raise vim.fault.HostConnectFault(msg=str(e)) raise vim.fault.HostConnectFault(msg=str(e))

View File

@@ -1241,6 +1241,9 @@ class SoapStubAdapter(SoapStubAdapterBase):
# The server is probably sick, drop all of the cached connections. # The server is probably sick, drop all of the cached connections.
self.DropConnections() self.DropConnections()
raise raise
cookie = resp.getheader('Set-Cookie')
if cookie is None:
# try lower-case header for backwards compat. with old vSphere
cookie = resp.getheader('set-cookie') cookie = resp.getheader('set-cookie')
status = resp.status status = resp.status

View File

@@ -52,7 +52,7 @@ interactions:
content-length: ['3332'] content-length: ['3332']
content-type: [text/xml; charset=utf-8] content-type: [text/xml; charset=utf-8]
date: ['Mon, 21 Jul 2014 22:31:05 GMT'] 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;] HttpOnly; Secure;]
status: {code: 200, message: OK} status: {code: 200, message: OK}
- request: - request:
@@ -68,7 +68,7 @@ interactions:
headers: headers:
Accept-Encoding: ['gzip, deflate'] Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8] 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;] HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"'] SOAPAction: ['"urn:vim25/4.1"']
method: POST method: POST
@@ -99,7 +99,7 @@ interactions:
headers: headers:
Accept-Encoding: ['gzip, deflate'] Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8] 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;] HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"'] SOAPAction: ['"urn:vim25/4.1"']
method: POST method: POST
@@ -155,7 +155,7 @@ interactions:
headers: headers:
Accept-Encoding: ['gzip, deflate'] Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8] 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;] HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"'] SOAPAction: ['"urn:vim25/4.1"']
method: POST method: POST
@@ -212,7 +212,7 @@ interactions:
headers: headers:
Accept-Encoding: ['gzip, deflate'] Accept-Encoding: ['gzip, deflate']
Content-Type: [text/xml; charset=UTF-8] 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;] HttpOnly; Secure;]
SOAPAction: ['"urn:vim25/4.1"'] SOAPAction: ['"urn:vim25/4.1"']
method: POST method: POST

View File

@@ -36,10 +36,15 @@ class ConnectionTests(unittest.TestCase):
si = connect.Connect(host='vcsa', si = connect.Connect(host='vcsa',
user='my_user', user='my_user',
pwd='my_password') pwd='my_password')
cookie = si._stub.cookie
session_id = si.content.sessionManager.currentSession.key 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 # NOTE (hartsock): assertIsNotNone does not work in Python 2.6
self.assertTrue(session_id is not None) self.assertTrue(session_id is not None)
self.assertEqual('52773cd3-35c6-b40a-17f1-fe664a9f08f3', session_id) self.assertEqual('52773cd3-35c6-b40a-17f1-fe664a9f08f3', session_id)
self.assertTrue(session_id in cookie)
@vcr.use_cassette('basic_connection_bad_password.yaml', @vcr.use_cassette('basic_connection_bad_password.yaml',
cassette_library_dir=fixtures_path, record_mode='none') cassette_library_dir=fixtures_path, record_mode='none')