From 5da35d416243402585dd78d5a1dee8e56456db32 Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Oct 11 2017 15:24:16 +0000 Subject: Ticket 48771 - lib389 - get ns-slapd version Bug description: Some tests should be executed only with 389-ds-base that implements required features/has fixes. This can be done with py.test skipif fixture. But we don't have a way to get the version of ns-slapd that is currently used. Fix description: Add functions get_ds_version() and ds_is_older(). get_ds_version() returns a string like "1.3.4.8 B2016.043.2254" ds_is_older(version) returns boolean value if the current version is older than provided string. https://fedorahosted.org/389/ticket/48771 Author: vashirov Reviewed by: wibrown, mreynolds (Thanks!) --- diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index 17aff84..458be61 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -29,6 +29,7 @@ import logging import shutil import ldap import socket +import subprocess from socket import getfqdn from ldapurl import LDAPUrl @@ -708,3 +709,20 @@ def formatInfData(args): content += "\nldapifilepath=%s\n" % args['ldapifilepath'] return content + + +def get_ds_version(): + """Return version of ns-slapd binary, for example + 1.3.4.8 B2016.043.2254""" + nsslapd = get_sbin_dir() + "/ns-slapd" + output = subprocess.Popen([nsslapd, "-v"], + stdout=subprocess.PIPE).communicate()[0] + fullver = output.splitlines()[1] + ver = fullver.split('/')[1] + return ver + + +def ds_is_older(ver): + """Return True if current version of ns-slapd is older than provided + version""" + return get_ds_version() < ver