made pyopenssl optional trunk
authormitch <mitch.raful@itaas.dimensiondata.com>
Thu, 6 Dec 2018 19:06:22 +0000 (14:06 -0500)
committerAnthony Shaw <anthonyshaw@apache.org>
Thu, 13 Dec 2018 11:24:18 +0000 (19:24 +0800)
Closes #1255

libcloud/loadbalancer/drivers/nttcis.py
tox.ini

index 316f918..5d56e0c 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import OpenSSL.crypto
+try:
+    import OpenSSL
+    OpenSSL
+except ImportError:
+    raise ImportError('Missing "OpenSSL" dependency. You can install it '
+                      'using pip - pip install pyopenssl')
+from OpenSSL import crypto
 from libcloud.utils.py3 import ET
 from libcloud.common.nttcis import NttCisConnection
 from libcloud.common.nttcis import NttCisPool
@@ -833,10 +839,10 @@ class NttCisLBDriver(Driver):
         :type description: ``str``
         :return: ``bool``
         """
-        c = OpenSSL.crypto.load_certificate(
-            OpenSSL.crypto.FILETYPE_PEM, open(chain_crt_file).read())
+        c = crypto.load_certificate(
+            crypto.FILETYPE_PEM, open(chain_crt_file).read())
         cert = OpenSSL.crypto.dump_certificate(
-            OpenSSL.crypto.FILETYPE_PEM, c).decode(encoding='utf-8')
+            crypto.FILETYPE_PEM, c).decode(encoding='utf-8')
         cert_chain_elem = ET.Element("importSslCertificateChain",
                                      {"xmlns": TYPES_URN})
         ET.SubElement(cert_chain_elem, "networkDomainId") \
diff --git a/tox.ini b/tox.ini
index 293ccf9..dbcad71 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -5,8 +5,8 @@ envlist = py{2.7,pypy,pypy3,3.4,3.5,3.6,3.7},checks,lint,pylint,integration,cove
 passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
 deps =
     -r{toxinidir}/requirements-tests.txt
-    lockfile
     pyopenssl
+    lockfile
     libvirt-python==4.0.0
     py2.7: paramiko
 commands = cp libcloud/test/secrets.py-dist libcloud/test/secrets.py
@@ -30,6 +30,7 @@ commands = cp libcloud/test/secrets.py-dist libcloud/test/secrets.py
 
 [testenv:docs]
 deps = pysphere
+       pyopenssl
        backports.ssl_match_hostname
        lockfile
        rstcheck
@@ -45,6 +46,7 @@ commands = pip install sphinx~=1.6.0
 # Note: We don't build API docs on Travis since it causes build failures because
 # those API docs files are not included anywhere.
 deps = pysphere
+       pyopenssl
        backports.ssl_match_hostname
        lockfile
        rstcheck