From 19e5029d14677c639175ca0806aa718c1f8c9cc1 Mon Sep 17 00:00:00 2001 From: Shawn Hartsock Date: Wed, 23 Jul 2014 17:24:45 -0400 Subject: [PATCH] smart connect test and fixture A smart connect test and fixture to validate that the SmartConnect class is behaving properly. partial: https://github.com/vmware/pyvmomi/issues/42 --- tests/fixtures/smart_connection.yaml | 265 +++++++++++++++++++++++++++ tests/test_connect.py | 12 ++ 2 files changed, 277 insertions(+) create mode 100644 tests/fixtures/smart_connection.yaml diff --git a/tests/fixtures/smart_connection.yaml b/tests/fixtures/smart_connection.yaml new file mode 100644 index 000000000..173416cd5 --- /dev/null +++ b/tests/fixtures/smart_connection.yaml @@ -0,0 +1,265 @@ +interactions: +- request: + body: null + headers: + Connection: [close] + Host: ['vcsa:443'] + User-Agent: [Python-urllib/2.7] + method: GET + uri: https://vcsa:443//sdk/vimServiceVersions.xml + response: + body: {string: !!python/unicode "\n\n\n \n urn:vim25\n 5.5\n + \ \n 5.1\n 5.0\n + \ 4.1\n 4.0\n 2.5u2\n + \ 2.5\n \n \n \n + \ urn:vim2\n 2.0\n \n\n"} + headers: + connection: [close] + content-length: ['530'] + content-type: [text/xml] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ServiceInstance">ServiceInstance + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [''] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3611'] + content-type: [text/xml; charset=utf-8] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + set-cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; + HttpOnly; Secure;] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="SessionManager">SessionManagermy_usermy_password + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\n52773cd3-35c6-b40a-17f1-fe664a9f08f3rootroot + 2014-07-23T21:21:18.297208Z2014-07-23T21:21:18.297208Zenenfalse172.16.16.10\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['782'] + content-type: [text/xml; charset=utf-8] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="ServiceInstance">ServiceInstance + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\ngroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3611'] + content-type: [text/xml; charset=utf-8] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorServiceInstancefalsecontentServiceInstancefalse1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\nServiceInstancecontentgroup-d1propertyCollectorViewManagerVMware vCenter + ServerVMware vCenter Server 5.5.0 build-1750787 (Sim)VMware, + Inc.5.5.01750787 (Sim)INTL000linux-x64vpxVirtualCenter5.5EAB4D846-C243-426B-A021-0547644CE59DVMware + VirtualCenter Server5.0VpxSettingsUserDirectorySessionManagerAuthorizationManagerServiceMgrPerfMgrScheduledTaskManagerAlarmManagerEventManagerTaskManagerExtensionManagerCustomizationSpecManagerCustomFieldsManagerDiagMgrLicenseManagerSearchIndexFileManagerDatastoreNamespaceManagervirtualDiskManagerSnmpSystemProvCheckerCompatCheckerOvfManagerIpPoolManagerDVSManagerHostProfileManagerClusterProfileManagerMoComplianceManagerLocalizationManagerStorageResourceManagerguestOperationsManager\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['3751'] + content-type: [text/xml; charset=utf-8] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + status: {code: 200, message: OK} +- request: + body: ' + + + + <_this type="PropertyCollector">propertyCollectorSessionManagerfalsecurrentSessionSessionManagerfalse1 + + ' + headers: + Accept-Encoding: ['gzip, deflate'] + Content-Type: [text/xml; charset=UTF-8] + Cookie: [vmware_soap_session="52773cd3-35c6-b40a-17f1-fe664a9f08f3"; Path=/; + HttpOnly; Secure;] + SOAPAction: ['"urn:vim25/5.5"'] + method: POST + uri: https://vcsa:443/sdk + response: + body: {string: !!python/unicode "\n\n\nSessionManagercurrentSession52773cd3-35c6-b40a-17f1-fe664a9f08f3my_userMy User + 2014-07-23T21:21:18.297208Z2014-07-23T21:21:18.297208Zenenfalse172.16.16.11\n\n"} + headers: + cache-control: [no-cache] + connection: [Keep-Alive] + content-length: ['958'] + content-type: [text/xml; charset=utf-8] + date: ['Wed, 23 Jul 2014 21:21:18 GMT'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_connect.py b/tests/test_connect.py index bf6dceca9..03afc04ac 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -50,3 +50,15 @@ def should_fail(): pwd='bad_password') self.assertRaises(vim.fault.InvalidLogin, should_fail) + + @vcr.use_cassette('smart_connection.yaml', + cassette_library_dir=fixtures_path, record_mode='none') + def test_smart_connection(self): + # see: http://python3porting.com/noconv.html + si = connect.SmartConnect(host='vcsa', + user='my_user', + pwd='my_password') + session_id = si.content.sessionManager.currentSession.key + # 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)