]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix PEP476 & format message of Oracle ZFSSA drivers
authorDiem Tran <diem.tran@oracle.com>
Wed, 1 Jul 2015 21:12:48 +0000 (21:12 +0000)
committerdiem_tran <diem.tran@oracle.com>
Tue, 4 Aug 2015 16:11:20 +0000 (12:11 -0400)
* Handles the PEP 476 by opting out certificate verification.
* Fix debug format messages in restclient.py

Change-Id: Iaf9e546f0aed6b57fe9c2bf43aa2ce003a05ddf8
Closes-Bug: #1460156

cinder/volume/drivers/zfssa/restclient.py

index 67addcf84a75570967b2484b6b4a952b563704d9..00fc085876e2c257af94cc497f61752d16ebe45f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
 #    not use this file except in compliance with the License. You may obtain
@@ -16,6 +16,7 @@ ZFS Storage Appliance REST API Client Programmatic Interface
 """
 
 import json
+import ssl
 import time
 
 from oslo_log import log
@@ -269,14 +270,27 @@ class RestClientURL(object):
         retry = 0
         response = None
 
-        LOG.debug('Request: %s %s', (request, zfssaurl))
+        LOG.debug('Request: %(request)s %(url)s',
+                  {'request': request, 'url': zfssaurl})
         LOG.debug('Out headers: %s', out_hdrs)
         if body and body != '':
             LOG.debug('Body: %s', body)
 
+        context = None
+        if hasattr(ssl, '_create_unverified_context'):
+            context = ssl._create_unverified_context()
+        else:
+            context = None
+
         while retry < maxreqretries:
             try:
-                response = urllib.request.urlopen(req, timeout=self.timeout)
+                if context:
+                    response = urllib.request.urlopen(req,
+                                                      timeout=self.timeout,
+                                                      context=context)
+                else:
+                    response = urllib.request.urlopen(req,
+                                                      timeout=self.timeout)
             except urllib.error.HTTPError as err:
                 if err.code == http_client.NOT_FOUND:
                     LOG.debug('REST Not Found: %s', err.code)
@@ -314,8 +328,9 @@ class RestClientURL(object):
 
             break
 
-        if response and response.getcode() == http_client.SERVICE_UNAVAILABLE and \
-           retry >= maxreqretries:
+        if (response and
+            (response.getcode() == http_client.SERVICE_UNAVAILABLE and
+                retry >= maxreqretries)):
             raise RestClientError(response.getcode(), name="ERR_HTTPError",
                                   message="REST Not Available: Disabled")