[Asterisk-code-review] test config: Add test for OpenSSL version (testsuite[master])

Jenkins2 asteriskteam at digium.com
Tue Dec 19 16:06:21 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7610 )

Change subject: test_config:  Add test for OpenSSL version
......................................................................

test_config:  Add test for OpenSSL version

You can now test for openssl version as you do for sipp.

properties:
    dependencies:
        - asterisk : 'chan_pjsip'
        - openssl  :
            version: '1.0.1'

Change-Id: Ib2a3d726a6c9bd83b2658886eb26d5ef7809fa7e
---
A lib/python/asterisk/opensslversion.py
M lib/python/asterisk/test_config.py
M sample-yaml/test-config.yaml.sample
3 files changed, 83 insertions(+), 0 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Verified
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/lib/python/asterisk/opensslversion.py b/lib/python/asterisk/opensslversion.py
new file mode 100644
index 0000000..a7377ea
--- /dev/null
+++ b/lib/python/asterisk/opensslversion.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+"""OpenSSL Version String Handling
+
+Copyright (C) 2017, Digium, Inc.
+George Joseph <gjoseph at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import sys
+import unittest
+import re
+sys.path.append("lib/python")
+
+import test_suite_utils
+
+class OpenSSLVersion:
+    """An OpenSSL Version.
+
+    """
+    def __init__(self, version=None, feature=None):
+        """Construct a OpenSSL Version parser.
+
+        Keyword Arguments:
+        version The OpenSSL version string to parse.
+                If not supplied, the installed version is used.
+        """
+
+        self.version = -1
+
+        if version is None:
+            try:
+                from OpenSSL import SSL
+                from OpenSSL.SSL import OPENSSL_VERSION_NUMBER as ivers
+            except ImportError:
+                return
+
+            self.version = ivers
+        else:
+            self.version = self.__parse_version(version)
+
+    def __int__(self):
+        """Return the version as an integer value"""
+        return self.version
+
+    def __cmp__(self, other):
+        """Compare two SIPpVersion instances against each other"""
+        return cmp(self.version, other.version)
+
+    def __ne__(self, other):
+        return self.version != other.version
+
+    def __eq__(self, other):
+        return self.version == other.version
+
+    def __parse_version(self, version_str):
+        """Parse the version string"""
+        vv = 0
+        if version_str is not None:
+            parts = re.split("(\d+)[.](\d+)[.](\d+)([a-z]+)?(?:-(.+))?", version_str)
+            if parts[1]:
+                vv += int(parts[1]) << 28
+            if parts[2]:
+                vv += int(parts[2]) << 20
+            if parts[3]:
+                vv += int(parts[3]) << 12
+            if parts[4]:
+                vv += (ord(parts[4]) - ord('a')) << 4
+        return vv
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index 7775a62..260d292 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -24,6 +24,7 @@
 from asterisk import Asterisk
 from buildoptions import AsteriskBuildOptions
 from sippversion import SIPpVersion
+from opensslversion import OpenSSLVersion
 
 
 class TestConditionConfig(object):
@@ -114,6 +115,14 @@
                 self.met = True
             except ImportError:
                 pass
+        elif "openssl" in dep:
+            self.name = "OpenSSL"
+            self.version = None
+            if 'version' in dep['openssl']:
+                self.version = dep['openssl']['version']
+            ossl_installed = OpenSSLVersion()
+            ossl_required = OpenSSLVersion(self.version)
+            self.met = ossl_installed >= ossl_required
         elif "sipp" in dep:
             self.name = "SIPp"
             version = None
diff --git a/sample-yaml/test-config.yaml.sample b/sample-yaml/test-config.yaml.sample
index a8d0f69..8d78b80 100644
--- a/sample-yaml/test-config.yaml.sample
+++ b/sample-yaml/test-config.yaml.sample
@@ -63,6 +63,10 @@
         - sipp:
             version: 'v3.3'
 
+        # Specifies attributes of OpenSSL that must be present for this test to execute
+        - openssl:
+            version: '1.0.1'
+
         # If present, import the yappcap library as a dependency for test execution
         - 'pcap'
 

-- 
To view, visit https://gerrit.asterisk.org/7610
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2a3d726a6c9bd83b2658886eb26d5ef7809fa7e
Gerrit-Change-Number: 7610
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171219/9a36472a/attachment.html>


More information about the asterisk-code-review mailing list