From 6a986e735a99be6365808167a012c38fc6823fb0 Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Fri, 18 Mar 2016 13:14:39 +0100 Subject: [PATCH] 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: ? --- lib389/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib389/utils.py b/lib389/utils.py index 1ede4e3..81fe5e4 100644 --- a/lib389/utils.py +++ b/lib389/utils.py @@ -29,8 +29,10 @@ import logging import shutil import ldap import socket +import subprocess from socket import getfqdn from ldapurl import LDAPUrl +from distutils.version import LooseVersion from lib389._constants import * from lib389.properties import * @@ -708,3 +710,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 LooseVersion(get_ds_version()) < LooseVersion(ver) -- 2.7.0